rogain-parser

0.6.0 • Public • Published

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

Versions

Current Tags

  • Version
    Downloads (Last 7 Days)
    • Tag
  • 0.6.0
    0
    • latest

Version History

Package Sidebar

Install

npm i rogain-parser

Weekly Downloads

0

Version

0.6.0

License

MIT

Last publish

Collaborators

  • krambuhl