$ npm install md-to-bemjson
const toBemjson = require('md-to-bemjson').convertSync;
const bjson = toBemjson('# Hello world');
console.log(JSON.stringify(bjson, null, 4));
Yields:
{
"block": "md-root",
"content": {
"block": "heading",
"content": "Hello world",
"level": 1,
"mods": {
"level": 1
}
}
}
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.
- remark-inline-links - bemjson don't support references.
- remark-github - Github integrations (issues, commits, mentions)
- remark-bemjson - custom bemjson compiler
- 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])
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 } |
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.
Parameter | Type | Description |
---|---|---|
markdown |
string | Markdown text |
Asynchronously converts markdown to bemjson.
const Converter = require('md-to-bemjson');
const md2Bemjson = new Converter();
md2Bemjson.convert('# Hello world').then(bjson => console.log(JSON.stringify(bjson, null, 4)))
Yields:
{
"block": "md-root",
"content": {
"block": "heading",
"content": "Hello world",
"level": 1,
"mods": {
"level": 1
}
}
}
Parameter | Type | Description |
---|---|---|
markdown |
string | Markdown text |
Synchronously converts markdown to bemjson.
const Converter = require('md-to-bemjson');
const md2Bemjson = new Converter();
console.log(JSON.stringify(md2Bemjson.convertSync('# Hello world'), null, 4));
Yields:
{
"block": "md-root",
"content": {
"block": "heading",
"content": "Hello world",
"level": 1,
"mods": {
"level": 1
}
}
}
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 = require('md-to-bemjson');
const md2Bemjson = new Converter();
md2Bemjson.stringify('# Hello world').then(content => console.log(content))
Yields:
module.exports = {
block: 'md-root',
content: {
block: 'heading',
content: 'Hello world',
"level": 1,
mods: {
'level': 1
}
}
};
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 = require('md-to-bemjson');
const md2Bemjson = new Converter();
console.log(md2Bemjson.stringifySync('# Hello world'));
Yields:
module.exports = {
block: 'md-root',
content: {
block: 'heading',
content: 'Hello world',
level: 1,
mods: {
'level': 1
}
}
};
Parameter | Type | Description |
---|---|---|
markdown |
string | Markdown text |
options |
Object | plugin options |
Asynchronously converts markdown to bemjson.
const toBemjson = require('md-to-bemjson').convert;
toBemjson('# Hello world').then(bjson => console.log(JSON.stringify(bjson, null, 4)))
Yields:
{
"block": "md-root",
"content": {
"block": "heading",
"content": "Hello world",
"level": 1,
"mods": {
"level": 1
}
}
}
Parameter | Type | Description |
---|---|---|
markdown |
string | Markdown text |
options |
Object | plugin options |
Synchronously converts markdown to bemjson.
const toBemjson = require('md-to-bemjson').convertSync;
console.log(JSON.stringify(toBemjson('# Hello world'), null, 4));
Yields:
{
"block": "md-root",
"content": {
"block": "heading",
"content": "Hello world",
"level": 1,
"mods": {
"level": 1
}
}
}
Parameter | Type | Description |
---|---|---|
markdown |
string | Markdown text |
options |
Object | plugin options |
Asynchronously converts and stringify markdown to bemjson module with exports.
const toBemjsonString = require('md-to-bemjson').stringify;
toBemjsonString('# Hello world').then(bjson => console.log(JSON.stringify(bjson, null, 4)));
Yields:
module.exports = {
block: 'md-root',
content: {
block: 'heading',
content: 'Hello world',
level: 1,
mods: {
level: 1
}
}
};
Parameter | Type | Description |
---|---|---|
markdown |
string | Markdown text |
options |
Object | plugin options |
Synchronously converts and stringify markdown to bemjson module with exports.
const toBemjsonString = require('md-to-bemjson').stringifySync;
console.log(toBemjsonString('# Hello world'));
Yields:
module.exports = {
block: 'md-root',
content: {
block: 'heading',
content: 'Hello world',
level: 1,
mods: {
'level': 1
}
}
};
Code and documentation copyright 2017 YANDEX LLC. Code released under the Mozilla Public License 2.0.