From f31d24cd1417088b7806ddc7d2e0df982d666e38 Mon Sep 17 00:00:00 2001 From: nsfisis Date: Sun, 12 Jan 2025 21:50:13 +0900 Subject: refactor(blog/nuldoc): remove top-level __root__ element --- vhosts/blog/nuldoc-src/renderers/xml.ts | 45 +++++++++++++++------------------ 1 file changed, 21 insertions(+), 24 deletions(-) (limited to 'vhosts/blog/nuldoc-src/renderers/xml.ts') diff --git a/vhosts/blog/nuldoc-src/renderers/xml.ts b/vhosts/blog/nuldoc-src/renderers/xml.ts index 69b8266c..77cc1574 100644 --- a/vhosts/blog/nuldoc-src/renderers/xml.ts +++ b/vhosts/blog/nuldoc-src/renderers/xml.ts @@ -2,7 +2,7 @@ import { Element, forEachChild, Node, Text } from "../dom.ts"; export function renderXml(root: Node): string { return `\n` + nodeToXmlText(root, { - indentLevel: -1, + indentLevel: 0, }); } @@ -14,7 +14,6 @@ type Dtd = { type: "block" | "inline" }; function getDtd(name: string): Dtd { switch (name) { - case "__root__": case "feed": case "entry": case "author": @@ -64,24 +63,23 @@ function encodeSpecialCharacters(s: string): string { function elementNodeToXmlText(e: Element, ctx: Context): string { let s = ""; - if (e.name !== "__root__") { - s += indent(ctx); - s += `<${e.name}`; - const attributes = getElementAttributes(e); - if (attributes.length > 0) { - s += " "; - for (let i = 0; i < attributes.length; i++) { - const [name, value] = attributes[i]; - s += `${name}="${encodeSpecialCharacters(value)}"`; - if (i !== attributes.length - 1) { - s += " "; - } + + s += indent(ctx); + s += `<${e.name}`; + const attributes = getElementAttributes(e); + if (attributes.length > 0) { + s += " "; + for (let i = 0; i < attributes.length; i++) { + const [name, value] = attributes[i]; + s += `${name}="${encodeSpecialCharacters(value)}"`; + if (i !== attributes.length - 1) { + s += " "; } } - s += ">"; - if (isBlockNode(e)) { - s += "\n"; - } + } + s += ">"; + if (isBlockNode(e)) { + s += "\n"; } ctx.indentLevel += 1; @@ -90,13 +88,12 @@ function elementNodeToXmlText(e: Element, ctx: Context): string { }); ctx.indentLevel -= 1; - if (e.name !== "__root__") { - if (isBlockNode(e)) { - s += indent(ctx); - } - s += ``; - s += "\n"; + if (isBlockNode(e)) { + s += indent(ctx); } + s += ``; + s += "\n"; + return s; } -- cgit v1.2.3-70-g09d2