angular-html-parser

A HTML parser extracted from Angular with some modifications

MIT 49 个版本
安装
npm install angular-html-parser
yarn add angular-html-parser
pnpm add angular-html-parser
bun add angular-html-parser
README

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

版本列表
10.11.0 2026-07-08
10.10.0 2026-06-25
10.9.0 2026-06-23
10.8.0 2026-06-22
10.7.0 2026-06-03
10.6.1 2026-05-19
10.6.0 2026-05-19
10.5.0 2026-04-10
10.4.0 2026-01-15
10.3.0 2026-01-09
10.2.1 2025-12-16
10.1.1 2025-11-21
10.1.0 2025-11-21
10.0.0 2025-10-11
9.3.0 2025-08-31
9.2.0 2025-05-28
9.1.1 2025-05-25
9.1.0 2025-04-25
9.0.2 2025-04-16
9.0.1 2025-04-16
9.0.0 2025-04-16
8.1.0 2025-03-12
8.0.1 2024-11-25
8.0.0 2024-11-25
7.0.1 2024-10-08
7.0.0 2024-09-29
6.0.2 2024-07-11
6.0.1 2024-07-11
6.0.0 2024-07-11
5.2.0 2023-12-10
5.1.0 2023-12-10
5.0.2 2023-10-29
5.0.1 2023-10-29
5.0.0 2023-10-29
4.0.1 2023-01-30
4.0.0 2023-01-05
3.0.0 2022-11-20
2.1.0 2022-10-18
2.0.0 2022-10-02
1.8.0 2021-04-05
1.7.1 2020-06-26
1.7.0 2020-05-09
1.6.0 2020-05-03
1.5.0 2020-04-21
1.4.0 2020-01-28
1.3.0 2019-11-02
1.2.0 2018-12-07
1.1.0 2018-11-27
1.0.0 2018-10-24