babel-plugin-import-md-to-js

1.0.0 • Public • Published

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.

Usage

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>`
}

Use Cases

The only use case of this plugin is to be able to bundle markdown pages with your js components. It is good for portability.

Versions

Current Tags

  • Version
    Downloads (Last 7 Days)
    • Tag
  • 1.0.0
    1
    • latest

Version History

  • Version
    Downloads (Last 7 Days)
    • Published
  • 1.0.0
    1

Package Sidebar

Install

npm i babel-plugin-import-md-to-js

Weekly Downloads

1

Version

1.0.0

License

MIT

Last publish

Collaborators

  • wsmaster