【问题标题】:Markdown to html, include a linkMarkdown 到 html,包括一个链接
【发布时间】:2020-02-05 01:49:33
【问题描述】:

可以使用gulp-markdown 将文件从markdown 获取到html。

但是,如果不能自动包含指向样式表的链接,这仍然不是很有帮助。

其含义的最小示例:

Markdown 文件example.md

# MD files are simple to write
 * then it could be interesting to use them to write blog-posts with a minimal formatting
 * New bullet

gulp-markdown之后example.html

<h1 id="md-files-are-simple-to-write">MD files are simple to write</h1>
<ul>
<li>then it could be interesting to use them to write blog-posts with a minimal formatting</li>
<li>New bullet</li>
</ul>

预期

<html>
<head>
<link rel='stylesheet' href='path/to/style.css'/>
</head>
    <h1 id="md-files-are-simple-to-write">MD files are simple to write</h1>
    <ul>
    <li>then it could be interesting to use them to write blog-posts with a minimal formatting</li>
    <li>New bullet</li>
    </ul>
</html>

我可以在哪里查看或如何实现这一点?

【问题讨论】:

    标签: html gulp markdown


    【解决方案1】:

    https://marked.js.org/#/USING_PRO.md#renderer

    您可以通过添加自定义渲染器来做一种模板:

    // myHtml is the HTML you already made
    let myTemplate = new markdown.Renderer()
    myTemplate.html(someHtml) {
      return `<html><head></head><body>${someHtml}</body></html>`
    }
    let fullHtml = marked(myHtml, {renderer: myTemplate}
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-01-01
      • 1970-01-01
      • 2017-07-10
      • 2021-01-26
      • 1970-01-01
      • 2018-01-16
      • 2015-08-21
      • 2020-11-09
      相关资源
      最近更新 更多