src/transformer.js
function _renderMarkdown( htmlDoc ) {
    const replacements = {};

    // First turn all outputs into text so *<span class="or-output></span>* can be detected
    htmlDoc.find( '/root/form//span[contains(@class, "or-output")]' ).forEach( ( el, index ) => {
        const key = `---output-${index}`;
        const textNode = el.childNodes()[ 0 ].clone();
        replacements[ key ] = el.toString();
        textNode.text( key );
        el.replace( textNode );
        // Note that we end up in a situation where we likely have sibling text nodes...
    } );

    // Now render markdown
    htmlDoc.find( '/root/form//span[contains(@class, "question-label") or contains(@class, "or-hint")]' ).forEach( ( el, index ) => {
        let key;
        /**
         * Using text() is done because:
         * a) We are certain that these <span>s do not contain other elements, other than formatting/markdown <span>s.
         * b) This avoids the need to merge any sibling text nodes that could have been created in the previous step.
         *
         * Note that text() will convert &gt; to >
         */
        const original = el.text().replace( '<', '&lt;' ).replace( '>', '&gt;' );
        const rendered = markdown.toHtml( original );
        if ( original !== rendered ) {
            key = `$$$${index}`;
            replacements[ key ] = rendered;
            el.text( key );
        }
    } );

    // TODO: does this result in self-closing tags?
    let htmlStr = _docToString( htmlDoc );

    // Now replace the placeholders with the rendered HTML
    // in reverse order so outputs are done last
    Object.keys( replacements ).reverse().forEach( key => {
        const replacement = replacements[ key ];
        if ( replacement ) {
            htmlStr = htmlStr.replace( key, replacement );
        }
    } );

    return htmlStr;
}
function _renderMarkdown( htmlDoc ) {
    const replacements = {};

    // First turn all outputs into text so *<span class="or-output></span>* can be detected
    htmlDoc.find( '/root/form//span[contains(@class, "or-output")]' ).forEach( ( el, index ) => {
        const key = `---output-${index}`;
        const textNode = el.childNodes()[ 0 ].clone();
        replacements[ key ] = el.toString();
        textNode.text( key );
        el.replace( textNode );
        // Note that we end up in a situation where we likely have sibling text nodes...
    } );

    // Now render markdown
    htmlDoc.find( '/root/form//span[contains(@class, "question-label") or contains(@class, "or-hint")]' ).forEach( ( el, index ) => {
        let key;
        /**
         * Using text() is done because:
         * a) We are certain that these <span>s do not contain other elements, other than formatting/markdown <span>s.
         * b) This avoids the need to merge any sibling text nodes that could have been created in the previous step.
         *
         * Note that text() will convert &gt; to >
         */
        const original = el.text().replace( '<', '&lt;' ).replace( '>', '&gt;' );
        const rendered = markdown.toHtml( original );
        if ( original !== rendered ) {
            key = `$$$${index}`;
            replacements[ key ] = rendered;
            el.text( key );
        }
    } );

    // TODO: does this result in self-closing tags?
    let htmlStr = _docToString( htmlDoc );

    // Now replace the placeholders with the rendered HTML
    // in reverse order so outputs are done last
    Object.keys( replacements ).reverse().forEach( key => {
        const replacement = replacements[ key ];
        if ( replacement ) {
            htmlStr = htmlStr.replace( key, replacement );
        }
    } );

    return htmlStr;
}
function _renderMarkdown ( htmlDoc ) { const replacements = { } ; // First turn all outputs into text so *<span class="or-output></span>* can be detected htmlDoc . find ( '/root/form//span[contains(@class, "or-output")]' ) . forEach ( ( el , index ) => { const key = ` ${ index } ` ; const textNode = el . childNodes ( ) [ 0 ] . clone ( ) ; replacements [ key ] = el . toString ( ) ; textNode . text ( key ) ; el . replace ( textNode ) ; // Note that we end up in a situation where we likely have sibling text nodes... } ) ; // Now render markdown htmlDoc . find ( '/root/form//span[contains(@class, "question-label") or contains(@class, "or-hint")]' ) . forEach ( ( el , index ) => { let key ; /**
         * Using text() is done because:
         * a) We are certain that these <span>s do not contain other elements, other than formatting/markdown <span>s.
         * b) This avoids the need to merge any sibling text nodes that could have been created in the previous step.
         *
         * Note that text() will convert &gt; to >
         */ const original = el . text ( ) . replace ( '<' , '&lt;' ) . replace ( '>' , '&gt;' ) ; const rendered = markdown . toHtml ( original ) ; if ( original !== rendered ) { key = ` ${ index } ` ; replacements [ key ] = rendered ; el . text ( key ) ; } } ) ; // TODO: does this result in self-closing tags? let htmlStr = _docToString ( htmlDoc ) ; // Now replace the placeholders with the rendered HTML // in reverse order so outputs are done last Object . keys ( replacements ) . reverse ( ) . forEach ( key => { const replacement = replacements [ key ] ; if ( replacement ) { htmlStr = htmlStr . replace ( key , replacement ) ; } } ) ; return htmlStr ; }
Converts a subset of Markdown in all textnode children of labels and hints into HTML

@param  {[type]} htmlDoc libxmljs object
@return {[type]}     libxmljs object
Converts a subset of Markdown in all textnode children of labels and hints into HTML