本文整理匯總了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(' ');
}