Skip to content
This repository has been archived by the owner on Oct 31, 2022. It is now read-only.

websecurify/babel-plugin-import-md-to-js

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Follow on Twitter

babel-plugin-import-md-to-js

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.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Packages

No packages published