Created
October 25, 2020 08:06
-
-
Save janosh/0b78ec17b8f296a82ae243c9c76165dc to your computer and use it in GitHub Desktop.
Rollup plugin for parsing markdown files
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
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