src/Htmlizer.js
function (dom) {
            var html = '';
            dom.forEach(function (node) {
                if (node.type === 'tag') {
                    var tag = node.name;
                    html += '<' + tag;
                    Object.keys(node.attribs).forEach(function (attr) {
                        html += ' ' + attr + '=' + this.generateAttribute(node.attribs[attr]);
                    }, this);
                    html += (voidTags[tag] ? '/>' : '>');
                    if (!voidTags[tag]) {
                        html += this.vdomToHtml(node.children);
                        html += '</' + tag + '>';
                    }
                } else if (node.type === 'text') {
                    var text = node.data || '';
                    html += this.htmlEncode(text); //escape <,> and &.
                } else if (node.type === 'comment') {
                    html += '<!-- ' + node.data.trim() + ' -->';
                } else if (node.type === 'script' || node.type === 'style') {
                    //No need to escape text inside script or style tag.
                    html += '<' + node.name;
                    Object.keys(node.attribs).forEach(function (attr) {
                        html += ' ' + attr + '=' + this.generateAttribute(node.attribs[attr]);
                    }, this);
                    html += '>' + ((node.children[0] || {}).data || '') + '</' + node.name + '>';
                } else if (node.type === 'directive') {
                    html += '<' + node.data + '>';
                }
            }, this);
            return html;
        }
function (dom) {
            var html = '';
            dom.forEach(function (node) {
                if (node.type === 'tag') {
                    var tag = node.name;
                    html += '<' + tag;
                    Object.keys(node.attribs).forEach(function (attr) {
                        html += ' ' + attr + '=' + this.generateAttribute(node.attribs[attr]);
                    }, this);
                    html += (voidTags[tag] ? '/>' : '>');
                    if (!voidTags[tag]) {
                        html += this.vdomToHtml(node.children);
                        html += '</' + tag + '>';
                    }
                } else if (node.type === 'text') {
                    var text = node.data || '';
                    html += this.htmlEncode(text); //escape <,> and &.
                } else if (node.type === 'comment') {
                    html += '<!-- ' + node.data.trim() + ' -->';
                } else if (node.type === 'script' || node.type === 'style') {
                    //No need to escape text inside script or style tag.
                    html += '<' + node.name;
                    Object.keys(node.attribs).forEach(function (attr) {
                        html += ' ' + attr + '=' + this.generateAttribute(node.attribs[attr]);
                    }, this);
                    html += '>' + ((node.children[0] || {}).data || '') + '</' + node.name + '>';
                } else if (node.type === 'directive') {
                    html += '<' + node.data + '>';
                }
            }, this);
            return html;
        }
function ( dom ) { var html = '' ; dom . forEach ( function ( node ) { if ( node . type === 'tag' ) { var tag = node . name ; html += '<' + tag ; Object . keys ( node . attribs ) . forEach ( function ( attr ) { html += ' ' + attr + '=' + this . generateAttribute ( node . attribs [ attr ] ) ; } , this ) ; html += ( voidTags [ tag ] ? '/>' : '>' ) ; if ( ! voidTags [ tag ] ) { html += this . vdomToHtml ( node . children ) ; html += '</' + tag + '>' ; } } else if ( node . type === 'text' ) { var text = node . data || '' ; html += this . htmlEncode ( text ) ; //escape <,> and &. } else if ( node . type === 'comment' ) { html += '<!-- ' + node . data . trim ( ) + ' -->' ; } else if ( node . type === 'script' || node . type === 'style' ) { //No need to escape text inside script or style tag. html += '<' + node . name ; Object . keys ( node . attribs ) . forEach ( function ( attr ) { html += ' ' + attr + '=' + this . generateAttribute ( node . attribs [ attr ] ) ; } , this ) ; html += '>' + ( ( node . children [ 0 ] || { } ) . data || '' ) + '</' + node . name + '>' ; } else if ( node . type === 'directive' ) { html += '<' + node . data + '>' ; } } , this ) ; return html ; }
Converts vdom from domhandler to HTML.
Converts vdom from domhandler to HTML .