summaryrefslogtreecommitdiffhomepage
path: root/vhosts/blog/nuldoc-src/renderers/html.ts
diff options
context:
space:
mode:
authornsfisis <nsfisis@gmail.com>2025-01-12 21:50:13 +0900
committernsfisis <nsfisis@gmail.com>2025-01-12 21:50:13 +0900
commitf31d24cd1417088b7806ddc7d2e0df982d666e38 (patch)
tree9cbaf34e7e68cdc29c4fca357534dcb00037538f /vhosts/blog/nuldoc-src/renderers/html.ts
parent940eae61767214eb1ee573284dc8b5876d536fb3 (diff)
downloadnsfisis.dev-f31d24cd1417088b7806ddc7d2e0df982d666e38.tar.gz
nsfisis.dev-f31d24cd1417088b7806ddc7d2e0df982d666e38.tar.zst
nsfisis.dev-f31d24cd1417088b7806ddc7d2e0df982d666e38.zip
refactor(blog/nuldoc): remove top-level __root__ element
Diffstat (limited to 'vhosts/blog/nuldoc-src/renderers/html.ts')
-rw-r--r--vhosts/blog/nuldoc-src/renderers/html.ts46
1 files changed, 22 insertions, 24 deletions
diff --git a/vhosts/blog/nuldoc-src/renderers/html.ts b/vhosts/blog/nuldoc-src/renderers/html.ts
index 70d097b2..5f1342f1 100644
--- a/vhosts/blog/nuldoc-src/renderers/html.ts
+++ b/vhosts/blog/nuldoc-src/renderers/html.ts
@@ -3,7 +3,7 @@ import { DocBookError } from "../errors.ts";
export function renderHtml(root: Node): string {
return `<!DOCTYPE html>\n` + nodeToHtmlText(root, {
- indentLevel: -1,
+ indentLevel: 0,
isInPre: false,
});
}
@@ -17,8 +17,6 @@ type Dtd = { type: "block" | "inline"; auto_closing?: boolean };
function getDtd(name: string): Dtd {
switch (name) {
- case "__root__":
- return { type: "block" };
case "a":
return { type: "inline" };
case "article":
@@ -164,29 +162,29 @@ function elementNodeToHtmlText(e: Element, ctx: Context): string {
const dtd = getDtd(e.name);
let s = "";
- if (e.name !== "__root__") {
- if (isBlockNode(e)) {
- 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 === "className" ? "class" : name}="${
- encodeSpecialCharacters(value)
- }"`;
- if (i !== attributes.length - 1) {
- s += " ";
- }
+
+ if (isBlockNode(e)) {
+ 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 === "className" ? "class" : name}="${
+ encodeSpecialCharacters(value)
+ }"`;
+ if (i !== attributes.length - 1) {
+ s += " ";
}
}
- s += ">";
- if (isBlockNode(e) && e.name !== "pre") {
- s += "\n";
- }
}
+ s += ">";
+ if (isBlockNode(e) && e.name !== "pre") {
+ s += "\n";
+ }
+
ctx.indentLevel += 1;
let prevChild: Node | null = null;
@@ -213,7 +211,7 @@ function elementNodeToHtmlText(e: Element, ctx: Context): string {
}
ctx.indentLevel -= 1;
- if (e.name !== "__root__" && !dtd.auto_closing) {
+ if (!dtd.auto_closing) {
if (e.name !== "pre") {
if (isBlockNode(e)) {
if (needsLineBreak(prevChild)) {