angular-html-parser
An HTML parser extracted from Angular with some modifications
Changelog
Install
npm install --save angular-html-parser
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 {
canSelfClose?: boolean;
allowHtmComponentClosingTags?: boolean;
isTagNameCaseSensitive?: boolean;
getTagContentType?: (
tagName: string,
prefix: string,
hasParent: boolean,
attrs: Array<{prefix: string; name: string; value?: string | undefined}>
) => 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 (fixed upstream)- add
type
property to nodes - value span for attributes includes quotes
Development
yarn run build
yarn run test
License
MIT © Ika