Denis 346b78aee1 first commit 2 anos atrás
..
lib 346b78aee1 first commit 2 anos atrás
CHANGELOG.md 346b78aee1 first commit 2 anos atrás
LICENSE 346b78aee1 first commit 2 anos atrás
README.md 346b78aee1 first commit 2 anos atrás
ThirdPartyNoticeText.txt 346b78aee1 first commit 2 anos atrás
package.json 346b78aee1 first commit 2 anos atrás

README.md

angular-html-parser

npm build

A HTML parser extracted from Angular with some modifications

Changelog

Install

# using npm
npm install --save angular-html-parser

# using yarn
yarn add angular-html-parser

Usage

const ngHtmlParser = require('angular-html-parser');

const { rootNodes, errors } = ngHtmlParser.parse('<div>hello world</div>');

API

declare function parse(input: string, options?: Options): ng.ParseTreeResult;

interface Options {
  /**
   * any element can self close
   *
   * defaults to false
   */
  canSelfClose?: boolean;
  /**
   * support [`htm`](https://github.com/developit/htm) component closing tags (`<//>`) 
   *
   * defaults to false
   */
  allowHtmComponentClosingTags?: boolean;
  /**
   * do not lowercase tag names before querying their tag definitions
   *
   * defaults to false
   */
  isTagNameCaseSensitive?: boolean;
  /**
   * customize tag content type
   *
   * defaults to the content type defined in the HTML spec
   */
  getTagContentType?: (tagName: string, prefix: string, hasParent: boolean) => void | ng.TagContentType,
}

Modifications

  • add CDATA node
  • add DocType node
  • add nameSpan field to Element and Attribute
  • allow case-insensitive closing tags for non-foreign elements
  • fix Comment#sourceSpan
  • support bogus comments (<!...>, <?...>)
  • support full named entities
  • add type property to nodes

Development

# build
yarn run build

# test
yarn run test

License

MIT © Ika