-
-
Save suhaotian/83171bf01f55dec0e4ffb75f4be59c3e to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const markdownIt = require('markdown-it') | |
const frontMatter = require('front-matter') | |
const Prism = require('prismjs') | |
const aliases = { | |
'js': 'jsx', | |
'html': 'markup' | |
} | |
const highlight = (str, lang) => { | |
if (!lang) { | |
return str | |
} else { | |
lang = aliases[lang] || lang | |
require(`prismjs/components/prism-${lang}.js`) | |
if (Prism.languages[lang]) { | |
return Prism.highlight(str, Prism.languages[lang]) | |
} else { | |
return str | |
} | |
} | |
} | |
const md = markdownIt({ | |
html: true, | |
linkify: true, | |
typographer: true, | |
highlight | |
}) | |
module.exports = function (content) { | |
this.cacheable() | |
this.value = md.render(content) | |
return `module.exports = ${JSON.stringify(this.value)}` | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment