Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 | 1x 1x 1x 4x 4x 4x 18x 4x 5x 5x | import { VirtualNode } from "../interfaces";
import nodeToVirtualNode from "./nodeToVirtualNode";
import parseFromString from "./parseFromString";
export default function markupToVirtualNode(
markup: string,
type: 'html' | 'xml' = 'xml',
options: any = {}
): VirtualNode | string | null {
let nodes = Array.from(parseFromString(markup, type));
Iif (nodes === null) {
return null;
}
Eif (options.excludeTextWithWhiteSpacesOnly === true) {
nodes = nodes.filter(node => node instanceof HTMLElement ||
node instanceof Text && !(/^\s*$/g.test((node as Text).textContent)))
}
return nodes.length > 1 ?
{
tag: null,
attributes: null,
children: nodes
.map(n => nodeToVirtualNode(n, options))
.filter(n => n !== null)
} :
nodeToVirtualNode(nodes[0], options);
} |