md-to-bemjson
Requirements
Install
$ npm install md-to-bemjson
Usage
const toBemjson = convertSync;const bjson = ; console;
Yields:
Markdown converter to bemjson
Module use remark with several plugins and custom compiler to convert markdown to bemjson. Plugins divided into two groups: necessary(you can't disable this plugins) and optional.
Necessary plugins:
- remark-inline-links - bemjson don't support references.
Optional plugins:
- remark-github - Github integrations (issues, commits, mentions)
Compiler
- remark-bemjson - custom bemjson compiler
API
- constructor([options])
- convert(markdown)
- convertSync(markdown)
- stringify(markdown)
- stringifySync(markdown)
- static convert(markdown[, options])
- static convertSync(markdown[, options])
- static stringify(markdown[, options])
- static stringifySync(markdown[, options])
constructor([options])
Options
Parameter | Type | Description |
---|---|---|
github |
Object, boolean | Enables github support with remark plugin remark-github. Default false . |
exportType |
enum | remark-bemjson option. Exports to certain type with .stringify . Supported exports. |
exportName |
string | remark-bemjson option. Used with exportType=(modules, umd, YModules) stringify bemjson with exported given name. |
augment |
Function, Object | Options for augmentation resulting bemjson by every node. As function accepts bemNode and must return it. |
plugins |
Array | Options for additional plugins to be included. Plugin format: { plugin: Function, options: Object } |
Options.augment
Parameter | Type | Description |
---|---|---|
prefix |
string | Add prefix to all blocks. Important: for root replace original prefix. |
scope |
string | Replace root block with scope. And replace all blocks with elems. |
map |
Object | Replace block names with provided in map. Available blocks. |
html |
Object | Options for converting html to bemjson with html2bemjson. |
Important: Augmentation flow is serial. Order: map, prefix, scope. Important: Other augmentations does not affect html.
convert(markdown) => Promise
Parameter | Type | Description |
---|---|---|
markdown |
string | Markdown text |
Asynchronously converts markdown to bemjson.
const Converter = ;const md2Bemjson = ; md2Bemjson
Yields:
convertSync(markdown) => Bemjson
Parameter | Type | Description |
---|---|---|
markdown |
string | Markdown text |
Synchronously converts markdown to bemjson.
const Converter = ;const md2Bemjson = ; console;
Yields:
stringify(markdown [, options]) => Promise
Parameter | Type | Description |
---|---|---|
markdown |
string | Markdown text |
options |
Object | Options prefixed with export* . Important: Creates new processor. For better performance set options via constructor. |
Asynchronously converts and stringify markdown to bemjson module with exports.
const Converter = ;const md2Bemjson = ; md2Bemjson
Yields:
moduleexports = block: 'md-root' content: block: 'heading' content: 'Hello world' "level": 1 mods: 'level': 1 ;
stringifySync(markdown [, options]) => String
Parameter | Type | Description |
---|---|---|
markdown |
string | Markdown text |
options |
Object | Options prefixed with export* . Important: Creates new processor. For better performance set options via constructor. |
Synchronously converts and stringify markdown to bemjson module with exports.
const Converter = ;const md2Bemjson = ; console;
Yields:
moduleexports = block: 'md-root' content: block: 'heading' content: 'Hello world' level: 1 mods: 'level': 1 ;
static convert(markdown [, options]) => Promise
Parameter | Type | Description |
---|---|---|
markdown |
string | Markdown text |
options |
Object | plugin options |
Asynchronously converts markdown to bemjson.
const toBemjson = convert;
Yields:
static convertSync(markdown [, options]) => Bemjson
Parameter | Type | Description |
---|---|---|
markdown |
string | Markdown text |
options |
Object | plugin options |
Synchronously converts markdown to bemjson.
const toBemjson = convertSync; console;
Yields:
static stringify(markdown [, options]) => Promise
Parameter | Type | Description |
---|---|---|
markdown |
string | Markdown text |
options |
Object | plugin options |
Asynchronously converts and stringify markdown to bemjson module with exports.
const toBemjsonString = stringify; ;
Yields:
moduleexports = block: 'md-root' content: block: 'heading' content: 'Hello world' level: 1 mods: level: 1 ;
static stringifySync(markdown [, options]) => String
Parameter | Type | Description |
---|---|---|
markdown |
string | Markdown text |
options |
Object | plugin options |
Synchronously converts and stringify markdown to bemjson module with exports.
const toBemjsonString = stringifySync; console;
Yields:
moduleexports = block: 'md-root' content: block: 'heading' content: 'Hello world' level: 1 mods: 'level': 1 ;
License
Code and documentation copyright 2017 YANDEX LLC. Code released under the Mozilla Public License 2.0.