diff options
| author | littleblack111 <littleblack11111@gmail.com> | 2023-10-14 15:05:55 +0800 |
|---|---|---|
| committer | littleblack111 <littleblack11111@gmail.com> | 2023-10-14 15:05:55 +0800 |
| commit | c06f7ee0a40255214c477e13d9b956a7e07c2900 (patch) | |
| tree | f5982a568ef8fab865d0142e71c7494fea3e4c1b /node_modules/domutils/lib/esm/stringify.js | |
| parent | 3fd9400d4dccc25aa29b5702216732e0b7542073 (diff) | |
postcss,(plugins): nanocss, postcss-preset-env
Diffstat (limited to 'node_modules/domutils/lib/esm/stringify.js')
| -rw-r--r-- | node_modules/domutils/lib/esm/stringify.js | 81 |
1 files changed, 81 insertions, 0 deletions
diff --git a/node_modules/domutils/lib/esm/stringify.js b/node_modules/domutils/lib/esm/stringify.js new file mode 100644 index 00000000..8fa46029 --- /dev/null +++ b/node_modules/domutils/lib/esm/stringify.js @@ -0,0 +1,81 @@ +import { isTag, isCDATA, isText, hasChildren, isComment, } from "domhandler"; +import renderHTML from "dom-serializer"; +import { ElementType } from "domelementtype"; +/** + * @category Stringify + * @deprecated Use the `dom-serializer` module directly. + * @param node Node to get the outer HTML of. + * @param options Options for serialization. + * @returns `node`'s outer HTML. + */ +export function getOuterHTML(node, options) { + return renderHTML(node, options); +} +/** + * @category Stringify + * @deprecated Use the `dom-serializer` module directly. + * @param node Node to get the inner HTML of. + * @param options Options for serialization. + * @returns `node`'s inner HTML. + */ +export function getInnerHTML(node, options) { + return hasChildren(node) + ? node.children.map((node) => getOuterHTML(node, options)).join("") + : ""; +} +/** + * Get a node's inner text. Same as `textContent`, but inserts newlines for `<br>` tags. Ignores comments. + * + * @category Stringify + * @deprecated Use `textContent` instead. + * @param node Node to get the inner text of. + * @returns `node`'s inner text. + */ +export function getText(node) { + if (Array.isArray(node)) + return node.map(getText).join(""); + if (isTag(node)) + return node.name === "br" ? "\n" : getText(node.children); + if (isCDATA(node)) + return getText(node.children); + if (isText(node)) + return node.data; + return ""; +} +/** + * Get a node's text content. Ignores comments. + * + * @category Stringify + * @param node Node to get the text content of. + * @returns `node`'s text content. + * @see {@link https://developer.mozilla.org/en-US/docs/Web/API/Node/textContent} + */ +export function textContent(node) { + if (Array.isArray(node)) + return node.map(textContent).join(""); + if (hasChildren(node) && !isComment(node)) { + return textContent(node.children); + } + if (isText(node)) + return node.data; + return ""; +} +/** + * Get a node's inner text, ignoring `<script>` and `<style>` tags. Ignores comments. + * + * @category Stringify + * @param node Node to get the inner text of. + * @returns `node`'s inner text. + * @see {@link https://developer.mozilla.org/en-US/docs/Web/API/Node/innerText} + */ +export function innerText(node) { + if (Array.isArray(node)) + return node.map(innerText).join(""); + if (hasChildren(node) && (node.type === ElementType.Tag || isCDATA(node))) { + return innerText(node.children); + } + if (isText(node)) + return node.data; + return ""; +} +//# sourceMappingURL=stringify.js.map
\ No newline at end of file |
