can-view-parser
Parse HTML and mustache tokens.
parse(html, handler, [returnIntermediate])
Parse an html string:
import parser from "can-view-parser";
const html = "<h1><span bob=\"phillips\"></span><span bob=\"meyers\"></span>" +
"</h1>";
const bobs = {};
let curAttr;
parser( html, {
attrStart: function( attrName ) {
curAttr = attrName;
},
attrValue: function( value ) {
bobs[ curAttr ] = value;
}
} );
for ( const first in bobs ) {
const last = bobs[ first ];
console.log( "Hello", first, last );
}
Parameters
- html
{String|Object}
:A mustache and html string to parse or an intermediate object the represents a previous parsing.
- handler
{ParseHandler}
:An object of callbacks.
- returnIntermediate
{Boolean}
:If true, returns a JS object representation of the parsing.