Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/84.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Html Grunt预编译内联标记_Html_Gruntjs_Markdown_Yeoman_Assemble - Fatal编程技术网

Html Grunt预编译内联标记

Html Grunt预编译内联标记,html,gruntjs,markdown,yeoman,assemble,Html,Gruntjs,Markdown,Yeoman,Assemble,我一直在寻找一种使用grunt预编译内联标记的方法。我选择markdown是因为,我处理的是大量具有简单格式的纯文本,但我不会完全反对JSON(或类似格式) 下面是一个例子:我在寻找什么: <body> <div id="content"> <div class="text"> ## Markdown Headline markdown Paragraph 1 </

我一直在寻找一种使用grunt预编译内联标记的方法。我选择markdown是因为,我处理的是大量具有简单格式的纯文本,但我不会完全反对JSON(或类似格式)

下面是一个例子:我在寻找什么:

<body>

    <div id="content">
        <div class="text">
            ## Markdown Headline
            markdown Paragraph 1
        </div>
        <div class="text">
            ## Markdown Headline
            Markdown Paragraph 2
        </div>
    </div>

</body>

##降价标题
降价第1段
##降价标题
降价第2段
更好的办法是:

<body>

    <div id="content">
        <div class="text">
            {include: /path/to/markdown_file_1.md:block_1}
        </div>
        <div class="text">
            {include: /path/to/markdown_file_1.md:block_2}
        </div>
    </div>

</body>

{include:/path/to/markdown_file_1.md:block_1}
{include:/path/to/markdown_file_1.md:block_2}
我不想从markdown创建模板,这仅仅是一种包含文本的方法,然后使用“grunt build”将文本呈现/编译成html(或者在yeoman的情况下,也可以使用“grunt server”)

这意味着上面的示例将编译为

<body>

    <div id="content">
        <div class="text">
            <h1>Markdown Headline</h1></p>
            Lorem ipsum <b>dolar</b> set <a href="http://amet.com/">amet</a>.
        </div>
        <div class="text">
            <h1>Markdown Headline</h1></p>
            Integer <i>posuere erat a ante</i> venenatis dapibus posuere velit aliquet.
        </div>
    </div>

</body>

降价标题

Lorem ipsum dolar集合。 降价标题

整数是一个完整的数字。
每个html页面都是不同的,因此模板是不可能的,因为我收到了副本(作为标记文件),我想如果我能在html中“包含”标记并让grunt为我编译它,那就太好了

我在stackoverflow中寻找解决方案,但什么也没找到(也许,我搜索错了)

我还研究了以下方面:

  • -接近,但似乎“在飞行中”起作用,这对我来说是不必要的

  • -同上

  • -显示为仅将
    markdown
    文件编译为
    html
    文件

  • -我真的对assemble抱有希望,但不知道如何实现它

  • -车把正是我希望能够包含
    标记的方式,但我如何在HTML文件中读取
    车把
    ,并使用grunt进行渲染(预编译)

使用(根据Simon的评论)的组合来呈现标记并将其注入到构建中。一个示例配置(未经测试,因此您可能需要稍微处理一下):

导入任务采用一个字符串,例如
@import“path/to/other/file”并将该文件的内容注入到目标文件。

非常棒

用HTML内联编写标记,或者只需在Grunt配置中指定所需的任何标记,Assemble就会使用它。使用以下帮助程序将内联或外部标记转换为HTML:

{{md}}helper 此帮助程序将像对待include一样处理标记文件,并将标记转换为HTML:

{{md "path/to/file.md"}}
{{markdown}}块辅助程序 这是一个块帮助器,使您能够使用HTML内联编写标记:

{{#markdown}}
# Foo
> This is markdown
{{/markdown}}
这种方法的美妙之处在于,您可以同时编写HTML和标记,或者只编写标记就可以了

以下是我如何建立我的新博客:

blog: {
  options: {
    layout: 'templates/layouts/default.hbs'
  },
  files: {
    '<%= site.dest %>/': ['content/*.md']
  }
}

??感谢您的快速回复。然而,这并不完全是我想要的,但它让我回到Assembly.io。我正在做一个快速原型。一旦我启动并运行它,我会将结果发布到这里。谢谢Jon给出的全面回答。在发布我的问题后,我意识到这对我自己来说太难了。然后我实现了一个类似于您建议的解决方案。我只是为每个不同的HTML页面创建了一个不同的把手模板,这个系统就像一个梦,向Assembly.io的家伙致敬。
blog: {
  options: {
    layout: 'templates/layouts/default.hbs'
  },
  files: {
    '<%= site.dest %>/': ['content/*.md']
  }
}
<html lang="en">
  <head>
    {{> head }}
  </head>
  <body>
    {{> nav-main }}
    <div class="container">
    {{#markdown}}
      {{> body }}
    {{/markdown}}
    </div>
    {{> footer }}
  </body>
</html>