UNPKG

scrivito

Version:

Scrivito is a professional, yet easy to use SaaS Enterprise Content Management Service, built for digital agencies and medium to large businesses. It is completely maintenance-free, cost-effective, and has unprecedented performance and security.

21 lines (16 loc) 598 B
import { childNodeListToArray } from './child_node_list_to_array'; const IGNORE_NODE = ['HEAD', 'SCRIPT']; export function nodeToText(node: Node): string { const nodeName = node.nodeName; if (IGNORE_NODE.indexOf(nodeName) > -1) return ''; if (nodeName === '#text') return node.textContent || ''; return childNodeListToArray(node.childNodes) .map((child) => INLINE_NODES.includes(child.nodeName) ? nodeToText(child) : ` ${nodeToText(child)} ` ) .join(''); } /** @see htmlToTextForNode for tags we consider inline */ const INLINE_NODES = ['#text', 'A'];