當前位置: 首頁>>代碼示例>>TypeScript>>正文


TypeScript html_parser.HtmlParser類代碼示例

本文整理匯總了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;
}
開發者ID:AnthonyPAlicea,項目名稱:angular,代碼行數:13,代碼來源:i18n_parser_spec.ts

示例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]);
    });
  });
開發者ID:Cammisuli,項目名稱:angular,代碼行數:47,代碼來源:ast_serializer_spec.ts

示例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]);
 });
開發者ID:Cammisuli,項目名稱:angular,代碼行數:11,代碼來源:ast_serializer_spec.ts


注:本文中的@angular/compiler/src/ml_parser/html_parser.HtmlParser類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。