This is a simple babel plugin to inline markdown into js via marked and js-yaml.
This plugin is very much experimental due to use of the Babel6 API - largely undocumented. Contributions are welcome.
The following command will convert everything in the src
folder to lib
using babel and our plugin.
babel src/ -d lib/ --presets stage-0,es2015,react --plugins import-md-to-js
Every js file that has a statement such as:
import page from './page.md'
will be roughtly translated to:
var page = {
...metadata
contents: `...` // the md file without the metadata converted to html
}
You can also import markdown pages raw by placing the ! symbol at the end of the file. For example:
import page from './page.md!'
will be roughtly translated to:
var page = {
...metadata
contents: `...` // the md file without the metadata
}
Notice that in both examples we split the metadata. This is done via the js-yaml module. Consider the following page:
---
a: 1
b: 2
---
# Hello
will be translated to:
var page = {
a: 1,
b: 2
contents: `<h1>Hello</h1>`
}
The only use case of this plugin is to be able to bundle markdown pages with your js components. It is good for portability.