本文整理匯總了TypeScript中dom5.getTextContent函數的典型用法代碼示例。如果您正苦於以下問題:TypeScript getTextContent函數的具體用法?TypeScript getTextContent怎麽用?TypeScript getTextContent使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了getTextContent函數的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。
示例1: getDomModules
analyzer.elements.forEach(function(element){
// Ignore Polymer.Base since it's special.
if (element.is == "Polymer.Base") return;
var domModules = getDomModules(analyzer, element.is);
if (!domModules[0]) {
return;
}
if (domModules.length > 1) {
domModules.forEach(function(domModule) {
unorderedModules.push(lintErrorFromNode(domModule, "dom-module " +
"has a repeated value for id " + element.is + "."));
});
return;
}
var scriptContent = dom5.getTextContent(element.scriptElement);
var scriptFinderPredicate = p.hasTextValue(scriptContent);
var script = dom5.nodeWalk(loadedDoc, scriptFinderPredicate);
var otherDomModule = dom5.nodeWalkPrior(script, domModuleForId(element.is));
if (!otherDomModule) {
var originalDomModule = domModules[0];
unorderedModules.push(lintErrorFromNode(originalDomModule, "dom-module " +
"for " + element.is +
" should be a parent of it or earlier in the document."));
}
});
示例2: offsetSourceMap
inlineScripts.forEach((script) => {
let content = dom5.getTextContent(script);
const sourceMapUrlParts = content.match(sourceMappingUrlExpr);
if (!sourceMapUrlParts) {
return;
}
const sourceMapContentParts =
sourceMapUrlParts[1].match(inlineSourceMapExpr);
if (!sourceMapContentParts) {
return;
}
const sourceRange = reparsedDoc.sourceRangeForStartTag(script)!;
const sourceMap = base64StringToRawSourceMap(sourceMapContentParts[2]);
const updatedMap = offsetSourceMap(
sourceMap, sourceRange.end.line, sourceRange.end.column);
const base64Map = rawSourceMapToBase64String(updatedMap);
content = content.replace(
sourceMappingUrlExpr, `${inlineSourcemapPrefix}${base64Map}\n`);
dom5.setTextContent(script, content);
});
示例3: canDomModuleBeInlined
export function canDomModuleBeInlined(domModule: parse5.ASTNode) {
if (domModule.attrs.some((a) => a.name !== 'id')) {
return false; // attributes other than 'id' on dom-module
}
let templateTagsSeen = 0;
for (const node of domModule.childNodes || []) {
if (node.tagName === 'template') {
if (node.attrs.length > 0) {
return false; // attributes on template
}
templateTagsSeen++;
} else if (node.tagName === 'script') {
// this is fine, scripts are handled elsewhere
} else if (
dom5.isTextNode(node) && dom5.getTextContent(node).trim() === '') {
// empty text nodes are fine
} else {
return false; // anything else, we can't convert it
}
}
if (templateTagsSeen > 1) {
return false; // more than one template tag, can't convert
}
return true;
}
示例4: ScannedScriptTagImport
const myVisitor: HtmlVisitor = (node) => {
if (isJsScriptNode(node)) {
const src =
dom5.getAttribute(node, 'src') as FileRelativeUrl | undefined;
if (src) {
features.push(new ScannedScriptTagImport(
'html-script',
src,
document.sourceRangeForNode(node)!,
document.sourceRangeForAttributeValue(node, 'src')!,
node,
false));
} else {
const locationOffset = getLocationOffsetOfStartOfTextContent(node);
const attachedCommentText = getAttachedCommentText(node) || '';
const contents = dom5.getTextContent(node);
features.push(new ScannedInlineDocument(
'js',
contents,
locationOffset,
attachedCommentText,
document.sourceRangeForNode(node)!,
node));
}
}
};
示例5: test
test('Escape inline <script>', async () => {
const {ast: doc} = await bundle('xss.html', options);
const script = dom5.query(doc, matchers.inlineNonModuleScript)!;
assert.include(
dom5.getTextContent(script),
'var b = 0<\\/script><script>alert(\'XSS\'); //2;',
'Inline <script> should be escaped');
});