本文整理匯總了TypeScript中dom5.isTextNode函數的典型用法代碼示例。如果您正苦於以下問題:TypeScript isTextNode函數的具體用法?TypeScript isTextNode怎麽用?TypeScript isTextNode使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了isTextNode函數的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。
示例1: 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;
}
示例2: addIndentation
export function addIndentation(
textNode: dom5.Node, additionalIndentation = ' ') {
if (!dom5.isTextNode(textNode)) {
return;
}
const text = dom5.getTextContent(textNode);
const indentedText =
text.split('\n')
.map((line) => {
return line.length > 0 ? additionalIndentation + line : line;
})
.join('\n');
dom5.setTextContent(textNode, indentedText);
}
示例3: removeNode
export function removeNode(
parsedDocument: ParsedHtmlDocument, node: dom5.Node): Replacement[] {
const parentChildren = node.parentNode!.childNodes!;
const prevNode = parentChildren[parentChildren.indexOf(node)! - 1];
const fix: Replacement[] = [];
if (prevNode && dom5.isTextNode(prevNode)) {
const trailingWhiteSpace =
removeTrailingWhitespace(prevNode, parsedDocument);
if (trailingWhiteSpace) {
fix.push(trailingWhiteSpace);
}
}
fix.push(
{replacementText: '', range: parsedDocument.sourceRangeForNode(node)!});
return fix;
}
示例4: getIndentationInside
export function getIndentationInside(parentNode: dom5.Node) {
if (!parentNode.childNodes || parentNode.childNodes.length === 0) {
return '';
}
const firstChild = parentNode.childNodes[0];
if (!dom5.isTextNode(firstChild)) {
return '';
}
const text = dom5.getTextContent(firstChild);
const match = text.match(/(^|\n)([ \t]+)/);
if (!match) {
return '';
}
// If the it's an empty node with just one line of whitespace, like this:
// <div>
// </div>
// Then the indentation of actual content inside is one level deeper than
// the whitespace on that second line.
if (parentNode.childNodes.length === 1 && text.match(/^\n[ \t]+$/)) {
return match[2] + ' ';
}
return match[2];
}
示例5: isBlankTextNode
export function isBlankTextNode(node: ASTNode): boolean {
return node && dom5.isTextNode(node) &&
dom5.getTextContent(node).trim() === '';
}