Skip to content

Instantly share code, notes, and snippets.

@ryanflorence
Last active August 14, 2018 17:01
Show Gist options
  • Star 8 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save ryanflorence/7e0bc800adba87797c840b2dc1a46838 to your computer and use it in GitHub Desktop.
Save ryanflorence/7e0bc800adba87797c840b2dc1a46838 to your computer and use it in GitHub Desktop.
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