本文整理汇总了TypeScript中@angular/compiler/src/ml_parser/html_parser.HtmlParser类的典型用法代码示例。如果您正苦于以下问题:TypeScript HtmlParser类的具体用法?TypeScript HtmlParser怎么用?TypeScript HtmlParser使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了HtmlParser类的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: _extractMessages
export function _extractMessages(
html: string, implicitTags: string[] = [],
implicitAttrs: {[k: string]: string[]} = {}): Message[] {
const htmlParser = new HtmlParser();
const parseResult = htmlParser.parse(html, 'extractor spec', true);
if (parseResult.errors.length > 1) {
throw Error(`unexpected parse errors: ${parseResult.errors.join('\n')}`);
}
return extractMessages(
parseResult.rootNodes, DEFAULT_INTERPOLATION_CONFIG, implicitTags, implicitAttrs)
.messages;
}
示例2: describe
describe('Node serializer', () => {
let parser: HtmlParser;
beforeEach(() => { parser = new HtmlParser(); });
it('should support element', () => {
const html = '<p></p>';
const ast = parser.parse(html, 'url');
expect(serializeNodes(ast.rootNodes)).toEqual([html]);
});
it('should support attributes', () => {
const html = '<p k="value"></p>';
const ast = parser.parse(html, 'url');
expect(serializeNodes(ast.rootNodes)).toEqual([html]);
});
it('should support text', () => {
const html = 'some text';
const ast = parser.parse(html, 'url');
expect(serializeNodes(ast.rootNodes)).toEqual([html]);
});
it('should support expansion', () => {
const html = '{number, plural, =0 {none} =1 {one} other {many}}';
const ast = parser.parse(html, 'url', {tokenizeExpansionForms: true});
expect(serializeNodes(ast.rootNodes)).toEqual([html]);
});
it('should support comment', () => {
const html = '<!--comment-->';
const ast = parser.parse(html, 'url', {tokenizeExpansionForms: true});
expect(serializeNodes(ast.rootNodes)).toEqual([html]);
});
it('should support nesting', () => {
const html = `<div i18n="meaning|desc">
<span>{{ interpolation }}</span>
<!--comment-->
<p expansion="true">
{number, plural, =0 {{sex, select, other {<b>?</b>}}}}
</p>
</div>`;
const ast = parser.parse(html, 'url', {tokenizeExpansionForms: true});
expect(serializeNodes(ast.rootNodes)).toEqual([html]);
});
});
示例3: it
it('should support nesting', () => {
const html = `<div i18n="meaning|desc">
<span>{{ interpolation }}</span>
<!--comment-->
<p expansion="true">
{number, plural, =0 {{sex, select, other {<b>?</b>}}}}
</p>
</div>`;
const ast = parser.parse(html, 'url', {tokenizeExpansionForms: true});
expect(serializeNodes(ast.rootNodes)).toEqual([html]);
});