Skip to content

Instantly share code, notes, and snippets.

@janosh
Created October 25, 2020 08:06
Show Gist options
  • Save janosh/0b78ec17b8f296a82ae243c9c76165dc to your computer and use it in GitHub Desktop.
Save janosh/0b78ec17b8f296a82ae243c9c76165dc to your computer and use it in GitHub Desktop.
Rollup plugin for parsing markdown files
import marked from 'marked'
// Import and compile markdown files. Adapted from
// https://github.com/xiaofuzi/rollup-plugin-md/blob/master/src/index.js
export function markdown(options = {}) {
if (options.marked) marked.setOptions(options.marked)
return {
name: `markdown`,
transform(md, id) {
if (!/\.md$/.test(id)) return null
const data = marked(md)
return {
code: `export default ${JSON.stringify(data.toString())};`,
map: { mappings: `` },
}
},
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment