Skip to content
Snippets Groups Projects
Commit 5ecb5b02 authored by Igor Markin's avatar Igor Markin
Browse files

Add missing build files

parent 942b7c3b
No related branches found
No related tags found
1 merge request!5Rework with parse 5
export declare const unwindTags: (node: Element | Document, tagName: string) => void;
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.unwindTags = void 0;
const unwindTags = (node, tagName) => {
const tags = node.getElementsByTagName(tagName);
//Sort tags by depth to start unwinding the deepest ones, which does not contain nested spans
const tagsDepths = {};
Array.from(tags).forEach((span) => {
let descendant = span;
let parent = descendant.parentNode;
let depth = 0;
while (parent && descendant !== parent) {
descendant = parent;
parent = descendant.parentNode;
depth++;
}
if (!tagsDepths[depth]) {
tagsDepths[depth] = [];
}
tagsDepths[depth].push(span);
});
Object.keys(tagsDepths)
.sort((a, b) => parseInt(b) - parseInt(a))
.forEach((depth) => {
tagsDepths[depth].forEach((span) => {
let child = span.firstChild;
const parent = span.parentNode;
while (child) {
parent.insertBefore(child.cloneNode(true), span);
child = child.nextSibling;
}
span.parentNode.removeChild(span);
});
});
};
exports.unwindTags = unwindTags;
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment