Skip to content
Parser that converts html templates into json trees
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
lib
test
.babelrc
.gitignore
.jshintrc
.npmignore
CHANGES.md
LICENSE
README.md
package.json

README.md

rogain-parser

Parses html strings with rogain flavor into JSON-compatible rogain trees. Uses htmlparser2 for initial pass, then walks the outputed tree searching for components (Uppercase elements) and variables (demarcated using {}).

Example

import parse from 'rogain-parser';

parse('<div class="block {key}"><Children /></div>')
  .then(function(tree) {
    // output json
    {
      type: 'tag', 
      name: 'div', 
      attribs: [
        { 
          type: 'attr',
          name: 'class',
          data: [
            { type: 'text', data: 'block '  }, 
            { type: 'variable', path: 'key' }
          ]
        }
      ],
      children: [
        { type: 'component', name: 'Children' }
      ]
    }

  })

parse(template[, options])

Parses template into json tree with options to configure the htmlparser2 parser and handler, returns a Promise resolving a rogain tree.

template

String. Rogain template.

options

Object. Optional. Used with the htmlparser2 module.

opts.parserOptions are options sent to the htmlparser parser.

opts.handlerOptions are options sent to the htmlparser default handler.

Install

With npm do:

npm install rogain-parser

License

MIT

You can’t perform that action at this time.