Markdown 到 html,包括一个 link

Markdown to html, include a link

可以使用 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>

有什么想法可以在哪里查看或如何实现吗?

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}