Parses html and magic tags.
Parse HTML and mustache tokens.
Parse an html string:
var parser = require("can-view-parser");
var html = '<h1><span bob="phillips"></span><span bob="meyers"></span>' +
'</h1>';
var bobs = {};
var curAttr;
parser(html, {
attrStart: function(attrName){
curAttr = attrName;
},
attrValue: function(value){
bobs[curAttr] = value;
}
});
for(var first in bobs) {
var last = bobs[first];
console.log("Hello", first, last);
}
- html
{String|Object}
: A mustache and html string to parse or an intermediate object the represents a previous parsing. - handler
{Object}
: An object of callbacks. - returnIntermediate
{Boolean}
: If true, returns a JS object representation of the parsing.
An object consisting of callback functions that handle stages in the parsing process.
Called when parsing a tag begins.
- tagName
{String}
: The name of the tag. - unary
{Boolean}
: If this tag is unary (has no closing tag).
Called at the end of parsing a tag.
- tagName
{String}
: The name of the tag. - unary
{Boolean}
: If this tag is unary (has no closing tag).
Called when a closing tag is found. If no closing tag exists for this tag (because it is self-closing) this function will not be called.
- tagName
{String}
: The name of the tag.
Called when an attribute is found on an element.
- attrName
{String}
: The name of the attribute.
Called at the end of parsing an attribute; after the attrStart and attrValue functions have been called.
- attrName
{String}
: The name of the attribute.
Called when an attribute's value has been found.
- value
{String}
: The value discovered associated with an attribute.
Called when CharacterData is found within a tag.
- value
{String}
: The character data within the tag.
Called when a Comment is found within a tag.
- value
{String}
: The Comment within the tag.
Called at the end of parsing the template.
To make a build of the distributables into dist/
in the cloned repository run
npm install
node build
Tests can run in the browser by opening a webserver and visiting the test.html
page.
Automated tests that run the tests from the command line in Firefox can be run with
npm test