summaryrefslogtreecommitdiffhomepage
path: root/vhosts/blog/nuldoc-src/renderers
diff options
context:
space:
mode:
Diffstat (limited to 'vhosts/blog/nuldoc-src/renderers')
-rw-r--r--vhosts/blog/nuldoc-src/renderers/html.ts46
-rw-r--r--vhosts/blog/nuldoc-src/renderers/xml.ts45
2 files changed, 43 insertions, 48 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)) {
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 `<?xml version="1.0" encoding="utf-8"?>\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 += `</${e.name}>`;
- s += "\n";
+ if (isBlockNode(e)) {
+ s += indent(ctx);
}
+ s += `</${e.name}>`;
+ s += "\n";
+
return s;
}