开源软件名称(OpenSource Name):metalsmith/markdown开源软件地址(OpenSource Url):https://github.com/metalsmith/markdown开源编程语言(OpenSource Language):JavaScript 100.0%开源软件介绍(OpenSource Introduction):@metalsmith/markdownA Metalsmith plugin to render markdown files to HTML, using Marked. InstallationNPM: npm install @metalsmith/markdown Yarn: yarn add @metalsmith/markdown Usageconst markdown = require('@metalsmith/markdown')
metalsmith.use(
markdown({
highlight: function (code) {
return require('highlight.js').highlightAuto(code).value
},
pedantic: false,
gfm: true,
tables: true,
breaks: false,
sanitize: false,
smartLists: true,
smartypants: false,
xhtml: false
})
) Options
You can render markdown to HTML in file metadata keys by specifying the metalsmith.use(
markdown({
keys: ['html_desc', 'nested.data']
})
) You can even render all keys at a certain path by setting the metalsmith.use(
markdown({
wildcard: true,
keys: ['html_desc', 'nested.data', 'faq.*.*']
})
) A file ---
html_desc: A **markdown-enabled** _description_
nested:
data: '#metalsmith'
faq:
- q: '**Question1?**'
a: _answer1_
- q: '**Question2?**'
a: _answer2_
--- would be transformed into: {
"html_desc": "A <strong>markdown-enabled</strong> <em>description</em>\n",
"nested": {
"data": "<h1 id=\"metalsmith\">metalsmith</h1>\n"
},
"faq": [
{ "q": "<p><strong>Question1?</strong></p>\n", "a": "<p><em>answer1</em></p>\n"},
{ "q": "<p><strong>Question2?</strong></p>\n", "a": "<p><em>answer2</em></p>\n"}
], Notes about the wildcard
Custom markdown renderingYou can use a custom renderer by using const markdown = require('@metalsmith/markdown')
const marked = require('marked')
const markdownRenderer = new marked.Renderer()
markdownRenderer.image = function (href, title, text) {
return `
<figure>
<img src="${href}" alt="${title}" title="${title}" />
<figcaption>
<p>${text}</p>
</figcaption>
</figure>`
}
metalsmith.use(
markdown({
renderer: markdownRenderer,
pedantic: false,
gfm: true,
tables: true,
breaks: false,
sanitize: false,
smartLists: true,
smartypants: false,
xhtml: false
})
) CLI UsageAdd {
"plugins": {
"@metalsmith/markdown": {
"pedantic": false,
"gfm": true,
"tables": true,
"breaks": false,
"sanitize": false,
"smartLists": true,
"smartypants": false,
"xhtml": false
}
}
} License |
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论