html to bemjson converter
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
test
.eslintrc Add linters, coverage, switch on CI May 11, 2017
.gitignore Add linters, coverage, switch on CI May 11, 2017
.travis.yml Add linters, coverage, switch on CI May 11, 2017
README.md Support for inline strings, comments and doctype Aug 12, 2015
index.js Add linters, coverage, switch on CI May 11, 2017
package.json 1.10.0 May 11, 2017

README.md

html2bemjson

Converts HTML to BEMJSON.

Installation

npm install html2bemjson --save

Usage

var html2bemjson = require('html2bemjson');
var html = '<div class="b1"><div class="b1__elem1"></div></div>';

html2bemjson.convert(html); // BEMJSON object

html2bemjson.stringify(html);
// {
//     block: 'b1',
//     content: [
//         {
//             block: 'b1',
//             elem: 'elem1'
//         }
//     ]
// }

Options

Both methods can take options object as a second argument:

require('html2bemjson').stringify('<div class="b1 b1--mod">', {
    preserveComments: false,
    naming: { elem: '__', mod: '--' }, // refer to https://en.bem.info/tools/bem/bem-naming/ for details
    indent: '\t'
});

For more examples please refer to test folder.