How to use the simple-html-tokenizer.EntityParser function in simple-html-tokenizer

To help you get started, we’ve selected a few simple-html-tokenizer 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 tildeio / simple-html-tokenizer / tests / evented-tokenizer-tests.ts View on Github external
function tokenize(input: string) {
  var tokenizer = new EventedTokenizer(
    delegate,
    new EntityParser(HTML5NamedCharRefs)
  );

  tokenizer.tokenize(input);
}
github glimmerjs / glimmer-vm / packages / @glimmer / syntax / lib / parser.ts View on Github external
let combined = new Parser(html, options).acceptNode(ast);

  if (options && options.plugins && options.plugins.ast) {
    for (let i = 0, l = options.plugins.ast.length; i < l; i++) {
      let plugin = new options.plugins.ast[i](options);

      plugin.syntax = syntax;

      combined = plugin.transform(combined);
    }
  }

  return combined;
}

const entityParser = new EntityParser(namedCharRefs);

export class Parser {
  private elementStack = [];
  private options: Object;
  private source: string[];
  public currentAttribute = null;
  public currentNode = null;
  public tokenizer = new EventedTokenizer(this, entityParser);

  constructor(source, options: Object = {}) {
    this.options = options;

    if (typeof source === 'string') {
      this.source = source.split(/(?:\r\n?|\n)/g);
    }
  }
github glimmerjs / glimmer-vm / packages / glimmer-syntax / lib / parser.ts View on Github external
let combined = new Parser(html, options).acceptNode(ast);

  if (options && options.plugins && options.plugins.ast) {
    for (let i = 0, l = options.plugins.ast.length; i < l; i++) {
      let plugin = new options.plugins.ast[i](options);

      plugin.syntax = syntax;

      combined = plugin.transform(combined);
    }
  }

  return combined;
}

const entityParser = new EntityParser(namedCharRefs);

export function Parser(source, options) {
  this.options = options || {};
  this.elementStack = [];
  this.tokenizer = new EventedTokenizer(this, entityParser);

  this.currentNode = null;
  this.currentAttribute = null;

  if (typeof source === 'string') {
    this.source = source.split(/(?:\r\n?|\n)/g);
  }
}

for (let key in handlebarsNodeVisitors) {
  Parser.prototype[key] = handlebarsNodeVisitors[key];
github glimmerjs / glimmer-vm / packages / @glimmer / syntax / lib / hbs / parse / html.ts View on Github external
import {
  TokenizerDelegate,
  EventedTokenizer,
  EntityParser,
  HTML5NamedCharRefs,
  TokenizerState,
} from 'simple-html-tokenizer';

import * as hbs from '../../types/handlebars-ast';
import { Option } from '@glimmer/interfaces';
import { expect, assert } from '@glimmer/util';
import { HandlebarsParser } from './core';

const entityParser = new EntityParser(HTML5NamedCharRefs);

type ConstructingParent = ConstructingElement | ConstructingFragment;

class ConstructingFragment {
  readonly description = 'fragment';
  readonly body: hbs.Statement[] = [];

  appendNode(node: hbs.Statement): void {
    this.body.push(node);
  }
}

class ConstructingText {
  readonly description = 'text';
  private text = '';
github glimmerjs / glimmer-vm / packages / @glimmer / syntax / lib / parser / tokenizer-event-handlers.ts View on Github external
export function preprocess(html: string, options: PreprocessOptions = {}): AST.Template {
  let mode = options.mode || 'precompile';

  let ast: HBS.Program;
  if (typeof html === 'object') {
    ast = html;
  } else if (mode === 'codemod') {
    ast = handlebars.parseWithoutProcessing(html, options.parseOptions) as HBS.Program;
  } else {
    ast = handlebars.parse(html, options.parseOptions) as HBS.Program;
  }

  let entityParser = undefined;
  if (mode === 'codemod') {
    entityParser = new EntityParser({});
  }

  let program = new TokenizerEventHandlers(html, entityParser).acceptTemplate(ast);

  if (options && options.plugins && options.plugins.ast) {
    for (let i = 0, l = options.plugins.ast.length; i < l; i++) {
      let transform = options.plugins.ast[i];
      let env = assign({}, options, { syntax }, { plugins: undefined });

      let pluginResult = transform(env);

      traverse(program, pluginResult.visitor);
    }
  }

  return program;