本文整理汇总了TypeScript中polymer-analyzer/lib/html/html-parser.HtmlParser类的典型用法代码示例。如果您正苦于以下问题:TypeScript HtmlParser类的具体用法?TypeScript HtmlParser怎么用?TypeScript HtmlParser使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了HtmlParser类的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: suite
suite('getLocationInfoForPosition', () => {
const parser = new HtmlParser();
test('works for an empty string', () => {
const allKindsSpaceSeparated = getAllKindsSpaceSeparated('');
assert.equal(allKindsSpaceSeparated, 'text');
});
test('works when just starting a tag', () => {
const allKindsSpaceSeparated = getAllKindsSpaceSeparated('<t');
// We assume that you're starting to write an html tag in a text node, so
// this works.
assert.equal(allKindsSpaceSeparated, 'text text text');
});
test('works with a closed tag', () => {
const allKindsSpaceSeparated = getAllKindsSpaceSeparated('<t></t>');
assert.equal(
allKindsSpaceSeparated,
'text tagName tagName text endTag endTag endTag text');
});
test('works with an unclosed tag', () => {
const allKindsSpaceSeparated = getAllKindsSpaceSeparated('<t>');
assert.equal(allKindsSpaceSeparated, 'text tagName tagName text');
});
test('works for a closed tag with empty attributes section', () => {
const allKindsSpaceSeparated = getAllKindsSpaceSeparated('<t ></t>');
assert.equal(
allKindsSpaceSeparated,
'text tagName tagName attribute text endTag endTag endTag text');
});
test('works for an unclosed tag with empty attributes section', () => {
const allKindsSpaceSeparated = getAllKindsSpaceSeparated('<t >');
assert.equal(allKindsSpaceSeparated, 'text tagName tagName attribute text');
});
test('works for a closed tag with a boolean attribute', () => {
const allKindsSpaceSeparated = getAllKindsSpaceSeparated('<t a></t>');
assert.equal(
allKindsSpaceSeparated, 'text tagName tagName attribute attribute ' +
'text endTag endTag endTag text');
});
test('works for an unclosed tag with a boolean attribute', () => {
const allKindsSpaceSeparated = getAllKindsSpaceSeparated('<t a>');
assert.equal(
allKindsSpaceSeparated,
'text tagName tagName attribute attribute text');
});
test('works with an empty attribute value in a closed tag', () => {
let allKindsSpaceSeparated = getAllKindsSpaceSeparated('<t a=></t>');
assert.equal(
allKindsSpaceSeparated,
'text tagName tagName attribute attribute attributeValue text ' +
'endTag endTag endTag text');
allKindsSpaceSeparated = getAllKindsSpaceSeparated('<t a=""></t>');
assert.equal(
allKindsSpaceSeparated, 'text tagName tagName attribute attribute ' +
'attributeValue attributeValue attributeValue text ' +
'endTag endTag endTag text');
allKindsSpaceSeparated = getAllKindsSpaceSeparated('<t a=\'\'></t>');
assert.equal(
allKindsSpaceSeparated, 'text tagName tagName attribute attribute ' +
'attributeValue attributeValue attributeValue text ' +
'endTag endTag endTag text');
});
test('works with an empty attribute value in an unclosed tag', () => {
let allKindsSpaceSeparated = getAllKindsSpaceSeparated('<t a=>');
assert.equal(
allKindsSpaceSeparated,
'text tagName tagName attribute attribute attributeValue text');
allKindsSpaceSeparated = getAllKindsSpaceSeparated('<t a="">');
assert.equal(
allKindsSpaceSeparated,
'text tagName tagName attribute attribute attributeValue attributeValue attributeValue text');
allKindsSpaceSeparated = getAllKindsSpaceSeparated('<t a=\'\'>');
assert.equal(
allKindsSpaceSeparated,
'text tagName tagName attribute attribute attributeValue attributeValue attributeValue text');
});
test(`works with a closed tag with text content`, () => {
const allKindsSpaceSeparated = getAllKindsSpaceSeparated('<t> </t>');
assert.equal(
allKindsSpaceSeparated,
'text tagName tagName text text endTag endTag endTag text');
});
test(`works with an unclosed tag with text content`, () => {
const allKindsSpaceSeparated = getAllKindsSpaceSeparated('<t> ');
assert.equal(allKindsSpaceSeparated, 'text tagName tagName text text');
//.........这里部分代码省略.........
示例2: getAllKindsSpaceSeparated
/**
* Return a space separated string of the `kind` for every location in the
* given html text.
*
* For small documents you can just assert against this string. For larger
* documents you can write a regexp to express your assertion.
*/
function getAllKindsSpaceSeparated(text: string) {
const doc =
parser.parse(text, 'uninteresting file name.html' as ResolvedUrl);
return getEveryPosition(text)
.map(pos => getHtmlAstLocationForPosition(doc, pos).kind)
.join(' ');
}