Share your code. npm Orgs help your team discover, share, and reuse code. Create a free org »

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

install

npm i rogain-parser

Downloadsweekly downloads

3

version

0.6.0

license

MIT

homepage

github.com

repository

Gitgithub

last publish

collaborators

  • avatar
Report a vulnerability