npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

md-to-bemjson

v1.0.2

Published

markdown to bemjson converter

Downloads

32

Readme

md-to-bemjson

Converts markdown to bemjson.

NPM Status Travis Status Coverage Status Dependency Status Greenkeeper badge

Requirements

Install

$ npm install md-to-bemjson

Usage

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

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:

Optional plugins:

Compiler

API

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

convertSync(markdown) => Bemjson

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

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 = 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
        }
    }
};

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 = 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
        }
    }
};

static convert(markdown [, options]) => Promise

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

static convertSync(markdown [, options]) => Bemjson

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

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 = 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
        }
    }
};

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 = 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
        }
    }
};

License

Code and documentation copyright 2017 YANDEX LLC. Code released under the Mozilla Public License 2.0.