html2bemjson

HTML to BEMJSON convertor

MIT 13 个版本
安装
npm install html2bemjson
yarn add html2bemjson
pnpm add html2bemjson
bun add html2bemjson
README

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.

版本列表
1.10.0 2017-05-11
1.9.0 2015-08-19
1.8.0 2015-08-19
1.7.0 2015-08-18
1.6.1 2015-08-13
1.6.0 2015-08-12
1.5.0 2015-08-12
1.4.0 2015-08-03
1.3.0 2015-08-03
1.2.0 2015-08-03
1.1.0 2015-06-23
1.0.1 2014-09-12
1.0.0 2014-01-20