Render Snabbdom Vnode’s to HTML strings
With npm
do:
npm install snabbdom-to-html
var h = require('snabbdom/h')
var toHTML = require('snabbdom-to-html')
var output = toHTML(
h('div', { style: { color: 'red' } }, 'The quick brown fox jumps')
)
console.log(output)
// => <div style="color: red">The quick brown fox jumps</div>
This library is built replicating the modular approach used in Snabbdom. So you can do the following if you need to implement any custom functionality.
var h = require('snabbdom/h')
var init = require('snabbdom-to-html/init')
var toHTML = init([
require('snabbdom-to-html/modules/attributes'),
require('snabbdom-to-html/modules/style')
])
var output = toHTML(
h('div', { style: { color: 'lime' } }, 'over the lazy fox')
)
console.log(output)
// => <div style="color: lime">over the lazy fox</div>
The init
function accepts an array of functions (modules). Modules have the following signature: (vnode) => String
. And this output string represents a part of the HTML opening tag, e.g. class="foo" data-bar="baz"
.
The built-in modules are:
Takes care of attributes (and props
), including classes.
Yes, takes care of styles.
MIT