DoneJS StealJS jQuery ++ FuncUnit DocumentJS
3.0.0
2.3.27

 

  • Github
  • Twitter
  • Chat
  • Forum
  • Guides
  • Core
  • Ecosystem
  • Infrastructure
    • can-construct
    • can-control
    • can-event
    • can-event/async/async
    • can-event/batch/batch
    • can-observation
    • can-simple-map
    • can-util
    • can-view-callbacks
    • can-view-live
    • can-view-model
    • can-view-nodelist
    • can-view-parser
    • can-view-scope
    • can-view-target
  • Legacy
  • Bitovi
    • Bitovi.com
    • Blog
    • Consulting
    • Training
    • Open Source
  • Chat
  • Forum
  • Star
  • Follow @canjs
  • CanJS
  • /
  • Infrastructure
  • /
  • can-view-parser
  • / On this page
    • can-view-parser

      module

      Parse HTML and mustache tokens.

      • npm package badge
      • Star
      • source

      parse(html, handler, [returnIntermediate])

      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);
      }
      

      Parameters

      1. html {String|Object}:

        A mustache and html string to parse or an intermediate object the represents a previous parsing.

      2. handler {Object}:

        An object of callbacks.

      3. returnIntermediate {Boolean}:

        If true, returns a JS object representation of the parsing.

      CanJS is part of DoneJS. Created and maintained by the core DoneJS team and Bitovi. Currently 3.0.0.