
Security News
Browserslist-rs Gets Major Refactor, Cutting Binary Size by Over 1MB
Browserslist-rs now uses static data to reduce binary size by over 1MB, improving memory use and performance for Rust-based frontend tools.
bemhtml-syntax
Advanced tools
BEMHTML source code converter:
Given the impedence mismatch between Bemhtml and Bh it does not seem possible to convert every template or guarantee that the applicative semantics of the source is preserved in the result. Bemhtml is much too expressive and lenient to deliver on such promise. The ability to apply templates in a modified context powered by xjst methods apply, applyNext, applyCtx employing the result is one feature prominantly missing in Bh. Its applyBase method carries a very particular meaning that doesn't map clearly on Bemhtml machinery and as of this writing appears to be broken anyway.
####Install
npm -g install bemhtml-syntax
####Use
bemhtml-syntax [OPTIONS] [ARGS]
# convert to new JS-syntax (bemhtml is the default and -f can be dropped)
bemhtml-syntax -f bemhtml [OPTIONS] [ARGS]
# convert to BH
bemhtml-syntax -f bh [OPTIONS] [ARGS]
-S
flag aka --strictOff
is the only option specific to BH converter and as
the name suggests turns the default strict compiler mode off. Generally we don't
recommend it, but this may help you convert many more templates to BH without
warnings so it's there for when you have a fairly big BEMHTML template you want
to convert to BH and you'd rather have some skeleton you can flesh out rather
than starting completely from scratch. The result is not guaranteed to carry
proper BEMHTML semantics over to BH and assumes that you'll fix it by hand.
Other options mostly control the code-style of generated code. E.g. you may
prefer -q double
quotes for strings and enforcing -Q
quotes around object
keys, etc. Most options used by js-beautify should just work.
For example, convert
block b-wrapper {
tag: 'wrap'
content: this.ctx.content
}
block b-inner, default: applyCtx({ block: 'b-wrapper', content: this.ctx.content })
with bemhtml-syntax -f bemhtml -q "double" -Q -i test/basic/info6.bemhtml
into
block("b-wrapper")(
tag()("wrap"),
content()(function() {
return this.ctx.content
})
);
block("b-inner").def()(function() {
return applyCtx({
"block": "b-wrapper",
"content": this.ctx.content
})
})
####API
var syntax = require('bemhtml-syntax'),
source = 'block b1, tag: "a"',
options = { indent_size: 2 };
// Parse BEMHTML code
var ast = syntax.parse(source);
// Transform AST for serialisation
var newAst = syntax.translate(ast);
// Serialise to JavaScript
var jsCode1 = syntax.generate(newAst, options);
// Or do everything in one go
var jsCode2 = syntax.compile(source, options);
// BH converter (see notes in [bemhtml-source-convert] repo)
var bhStxConstructor = syntax.getBhConstructor(),
stx = new bhStxConstructor(source, options);
FAQs
BEMHTML syntax converter
The npm package bemhtml-syntax receives a total of 13 weekly downloads. As such, bemhtml-syntax popularity was classified as not popular.
We found that bemhtml-syntax demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 4 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Browserslist-rs now uses static data to reduce binary size by over 1MB, improving memory use and performance for Rust-based frontend tools.
Research
Security News
Eight new malicious Firefox extensions impersonate games, steal OAuth tokens, hijack sessions, and exploit browser permissions to spy on users.
Security News
The official Go SDK for the Model Context Protocol is in development, with a stable, production-ready release expected by August 2025.