How to use the htmlparser2/lib/Parser function in htmlparser2

To help you get started, we’ve selected a few htmlparser2 examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github wayfair / tungstenjs / src / template / compiler / parser.js View on Github external
// common self closing svg elements
  path: true,
  circle: true,
  ellipse: true,
  line: true,
  rect: true,
  use: true,
  stop: true,
  polyline: true,
  polygon: true
};

/*
 * Since htmlparser2 doesn't expose its states, run some tests to grep them
 */
const testParser = new Parser({});
testParser.write('<div></div>
github wayfair / tungstenjs / src / template / compiler / parser.js View on Github external
ATTRIBUTE_STATES[IN_ATTRIBUTE_VALUE_NQ] = true;
ATTRIBUTE_STATES[IN_COMMENT] = true;

/**
 * Extend Parser to override some built-ins
 *
 * @param {[type]} cbs  [description]
 * @param {[type]} opts [description]
 */
function MustacheParser(cbs) {
  Parser.call(this, cbs, {
    decodeEntities: false,
    recognizeSelfClosing: true
  });
}
MustacheParser.prototype = new Parser();
MustacheParser.prototype.constructor = MustacheParser;

// Runs when the '=' after an attribute name is encountered
MustacheParser.prototype.onattribname = function(name) {
  if (name) {
    stack.createObject({
      type: 'attributename',
      value: name
    });
  }
  stack.createObject({
    type: 'attributenameend'
  });
};

// Runs when attribute value data has been encountered
github huridocs / uwazi / app / react / Markdown / markdownDatasets.js View on Github external
const parseDatasets = (markdown) => {
  const result = {};
  const parser = new HtmlParser({
      onopentag(name, attribs) {
        if (name === 'dataset') {
          result[attribs.name || 'default'] = conformValues(attribs);
        }
        if (name === 'query') {
          result[attribs.name || 'default'] = { url: attribs.url, query: true };
        }
      }
  }, { decodeEntities: true });

  parser.parseComplete(markdown);
  return result;
};
github yhatt / markdown-it-incremental-dom / src / mixins / renderer.js View on Github external
export default function(incrementalDom) {
  const {
    attr,
    elementClose,
    elementOpen,
    elementOpenEnd,
    elementOpenStart,
    elementVoid,
    text,
  } = incrementalDom

  const sanitizeName = name => name.replace(/[^-:\w]/g, '')

  const iDOMParser = new Parser(
    {
      onopentag: name => elementOpenEnd(sanitizeName(name)),
      onopentagname: name => elementOpenStart(sanitizeName(name)),
      onattribute: (name, value) => {
        const sanitizedName = sanitizeName(name)
        if (sanitizedName !== '') attr(sanitizedName, value)
      },
      ontext: text,
      onclosetag: name => elementClose(sanitizeName(name)),
    },
    {
      decodeEntities: true,
      lowerCaseAttributeNames: false,
      lowerCaseTags: false,
    }
  )