angular-html-parser

9.2.0 • Public • Published

angular-html-parser

npm

An HTML parser extracted from Angular with some modifications

Changelog

Diff from upstream

Link

[!TIP] Try sync main and dev branch with upstream first

Install

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

# using yarn
yarn add angular-html-parser

Usage

import { parse } from "angular-html-parser";

const { rootNodes, errors } = parse(`
<!DOCTYPE html>
<html>
  <head>
    <title>Hello world!</title>
  </head>
  <body>
    <div>Hello world!</div>
  </body>
</html>
`);

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,
    attrs: Array<{ prefix: string; name: string; value?: string | undefined }>,
  ) => void | ng.TagContentType;
  /**
   * tokenize angular control flow block syntax
   */
  tokenizeAngularBlocks?: boolean;
  /**
   * tokenize angular let declaration syntax
   */
  tokenizeAngularLetDeclaration?: boolean;
}

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 (fixed upstream)
  • add type property to nodes
  • value span for attributes includes quotes

Development

# build
yarn run build

# test
yarn run test

License

MIT © Ika

Versions

Current Tags

VersionDownloads (Last 7 Days)Tag
9.2.0313latest

Version History

VersionDownloads (Last 7 Days)Published
9.2.0313
9.1.125,230
9.1.05,473
9.0.216
9.0.10
9.0.01
8.1.01,380
8.0.1245
8.0.01
7.0.136
7.0.057
6.0.252,358
6.0.11
6.0.01
5.2.012,738
5.1.01
5.0.22,224
5.0.10
5.0.02
4.0.149,065
4.0.043
3.0.02,080
2.1.01,800
2.0.02,018
1.8.067,853
1.7.16,872
1.7.01,370
1.6.019
1.5.013
1.4.09,061
1.3.02,879
1.2.01,016
1.1.0276
1.0.01,715

Package Sidebar

Install

npm i angular-html-parser

Weekly Downloads

246,157

Version

9.2.0

License

MIT

Unpacked Size

317 kB

Total Files

44

Last publish

Collaborators

  • thorn0
  • fisker
  • ikatyang
  • sosukesuzuki