Last active
August 14, 2018 17:01
-
-
Save ryanflorence/7e0bc800adba87797c840b2dc1a46838 to your computer and use it in GitHub Desktop.
This file contains 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