本文整理汇总了TypeScript中dom5.remove函数的典型用法代码示例。如果您正苦于以下问题:TypeScript remove函数的具体用法?TypeScript remove怎么用?TypeScript remove使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了remove函数的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: removeElementAndNewline
export function removeElementAndNewline(node: ASTNode, replacement?: ASTNode) {
const siblings = Array.from(node.parentNode!.childNodes!);
let nextIdx = siblings.indexOf(node) + 1;
let next = siblings[nextIdx];
while (next && isBlankTextNode(next)) {
dom5.remove(next);
next = siblings[++nextIdx];
}
if (replacement) {
dom5.replace(node, replacement);
} else {
dom5.remove(node);
}
}
示例2: _removeEmptyHiddenDivs
/**
* Removes all empty hidden container divs from the AST.
*/
private _removeEmptyHiddenDivs(ast: ASTNode) {
for (const div of dom5.queryAll(ast, matchers.hiddenDiv)) {
if (serialize(div).trim() === '') {
dom5.remove(div);
}
}
}
示例3: _addSharedImportsToShell
_addSharedImportsToShell(bundles: Map<string, string[]>): string {
console.assert(this.shell != null);
let shellDeps = bundles.get(this.shell)
.map((d) => path.relative(path.dirname(this.shell), d));
let file = this.analyzer.files.get(this.shell);
console.assert(file != null);
let contents = file.contents.toString();
let doc = dom5.parse(contents);
let imports = dom5.queryAll(doc, dom5.predicates.AND(
dom5.predicates.hasTagName('link'),
dom5.predicates.hasAttrValue('rel', 'import')
));
// Remove all imports that are in the shared deps list so that we prefer
// the ordering or shared deps. Any imports left should be independent of
// ordering of shared deps.
let shellDepsSet = new Set(shellDeps);
for (let _import of imports) {
if (shellDepsSet.has(dom5.getAttribute(_import, 'href'))) {
dom5.remove(_import);
}
}
// Append all shared imports to the end of <head>
let head = dom5.query(doc, dom5.predicates.hasTagName('head'));
for (let dep of shellDeps) {
let newImport = dom5.constructors.element('link');
dom5.setAttribute(newImport, 'rel', 'import');
dom5.setAttribute(newImport, 'href', dep);
dom5.append(head, newImport);
}
let newContents = dom5.serialize(doc);
return newContents;
}
示例4: _addSharedImportsToShell
_addSharedImportsToShell(bundles: Map<string, string[]>): string {
console.assert(this.shell != null);
let shellUrl = urlFromPath(this.root, this.shell);
let shellUrlDir = posixPath.dirname(shellUrl);
let shellDeps = bundles.get(shellUrl)
.map((d) => posixPath.relative(shellUrlDir, d));
logger.debug('found shell dependencies', {
shellUrl: shellUrl,
shellUrlDir: shellUrlDir,
shellDeps: shellDeps,
});
let file = this.analyzer.getFile(this.shell);
console.assert(file != null);
let contents = file.contents.toString();
let doc = dom5.parse(contents);
let imports = dom5.queryAll(doc, dom5.predicates.AND(
dom5.predicates.hasTagName('link'),
dom5.predicates.hasAttrValue('rel', 'import')
));
logger.debug('found html import elements', {
imports: imports.map((el) => dom5.getAttribute(el, 'href')),
});
// Remove all imports that are in the shared deps list so that we prefer
// the ordering or shared deps. Any imports left should be independent of
// ordering of shared deps.
let shellDepsSet = new Set(shellDeps);
for (let _import of imports) {
let importHref = dom5.getAttribute(_import, 'href');
if (shellDepsSet.has(importHref)) {
logger.debug(`removing duplicate import element "${importHref}"...`);
dom5.remove(_import);
}
}
// Append all shared imports to the end of <head>
let head = dom5.query(doc, dom5.predicates.hasTagName('head'));
for (let dep of shellDeps) {
let newImport = dom5.constructors.element('link');
dom5.setAttribute(newImport, 'rel', 'import');
dom5.setAttribute(newImport, 'href', dep);
dom5.append(head, newImport);
}
let newContents = dom5.serialize(doc);
return newContents;
}
示例5: insertAfter
export function insertAfter(target: ASTNode, node: ASTNode) {
dom5.remove(node);
const index = target.parentNode!.childNodes!.indexOf(target);
target.parentNode!.childNodes!.splice(index + 1, 0, node);
node.parentNode = target.parentNode!;
}