UNPKG

docutils-ts

Version:

Port of the Python Docutils library to TypeScript

25 lines (24 loc) 656 B
import { xmlescape } from "./xml-escape.js"; import { Text } from "./nodes.js"; /** * convert a node to XML */ export function nodeToXml(node) { if (node instanceof Text) { const text = xmlescape(node.astext()); return text; } if (node.hasChildren()) { return [node.starttag(), ...node.getChildren().map((c) => nodeToXml(c)), node.endtag()].join(""); } return node.emptytag(); } /** * Return a whitespace-normalized name. */ export function whitespaceNormalizeName(name) { return name.replace(/\s+/, " "); } export function fullyNormalizeName(name) { return name.toLowerCase().replace(/\s+/, " "); }