Attention!
This is the documenation for the version of mithril-node-render for mithril v1.0
(rewrite).
Here you can find the
version for the current version of mithril (0.2.x).
mithril-node-render
![Gitter](https://badges.gitter.im/Join Chat.svg)
Use mithril views to render server side
Installation
npm install mithril-node-render@rewrite
Usage
var m = require('mithril');
var render = require('mithril-node-render');
render(m('span', 'huhu')).then(function (html) {
})
Async components
As you see the rendering is asyncronous. It waits for resolve of all promises
that might get returned from oninit
callbacks.
myAsyncComponent = {
oninit: function (node) {
return new Promise(function (resolve) {
node.state.foo = 'bar'
resolve()
})
},
view: function (node) {
return m('div', node.state.foo)
}
}
render(myAsyncComponent).then(function (html) {
}
Options
Optionally pass in options as an object: m.render(component, options)
.
The following options are supported:
escapeAttributeValue(value)
Default: render.escapeHtml
A filter function for attribute values. Receives value, returns what is printed.
escapeString(value)
Default: render.escapeHtml
A filter function for string nodes. Receives value, returns what is printed.
strict
Default: false
Set this to true to close all empty tags automatically. Default is HTML mode where tags like <br>
and <meta>
are allowed without closing tags. This is required if you're rendering XML or XHTML documents.
See also