本文整理汇总了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() === '';
}