aboutsummaryrefslogtreecommitdiffhomepage
path: root/nuldoc-src/renderers
diff options
context:
space:
mode:
authornsfisis <nsfisis@gmail.com>2023-06-20 21:29:47 +0900
committernsfisis <nsfisis@gmail.com>2023-06-20 21:29:47 +0900
commit92c7b41ea10b0d43557e45bf24ed70dc1cdace18 (patch)
treeb4cc2414c3eb1b287ceeb7b762be029cc0f6ff56 /nuldoc-src/renderers
parent0f0d396f961a1bdac520a56bdc53e27b70ff6e08 (diff)
downloadblog.nsfisis.dev-92c7b41ea10b0d43557e45bf24ed70dc1cdace18.tar.gz
blog.nsfisis.dev-92c7b41ea10b0d43557e45bf24ed70dc1cdace18.tar.zst
blog.nsfisis.dev-92c7b41ea10b0d43557e45bf24ed70dc1cdace18.zip
feat(nuldoc): improve indentation of <a> tag
Diffstat (limited to 'nuldoc-src/renderers')
-rw-r--r--nuldoc-src/renderers/html.ts22
1 files changed, 16 insertions, 6 deletions
diff --git a/nuldoc-src/renderers/html.ts b/nuldoc-src/renderers/html.ts
index e8743c5..3b6c6eb 100644
--- a/nuldoc-src/renderers/html.ts
+++ b/nuldoc-src/renderers/html.ts
@@ -113,7 +113,17 @@ function getDtd(name: string): Dtd {
}
function isInlineNode(n: Node): boolean {
- return n.kind === "text" || getDtd(n.name).type === "inline";
+ if (n.kind === "text") {
+ return true;
+ }
+ if (n.name !== "a") {
+ return getDtd(n.name).type === "inline";
+ }
+
+ // a tag: check if all children are inline elements.
+ let allInline = true;
+ forEachChild(n, (c) => allInline &&= isInlineNode(c));
+ return allInline;
}
function isBlockNode(n: Node): boolean {
@@ -153,7 +163,7 @@ function elementNodeToHtmlText(e: Element, ctx: Context): string {
let s = "";
if (e.name !== "__root__") {
- if (dtd.type === "block") {
+ if (isBlockNode(e)) {
s += indent(ctx);
}
s += `<${e.name}`;
@@ -169,7 +179,7 @@ function elementNodeToHtmlText(e: Element, ctx: Context): string {
}
}
s += ">";
- if (dtd.type === "block" && e.name !== "pre") {
+ if (isBlockNode(e) && e.name !== "pre") {
s += "\n";
}
}
@@ -180,7 +190,7 @@ function elementNodeToHtmlText(e: Element, ctx: Context): string {
ctx.isInPre = true;
}
forEachChild(e, (c) => {
- if (dtd.type === "block" && !ctx.isInPre) {
+ if (isBlockNode(e) && !ctx.isInPre) {
if (isInlineNode(c)) {
if (needsIndent(prevChild)) {
s += indent(ctx);
@@ -201,7 +211,7 @@ function elementNodeToHtmlText(e: Element, ctx: Context): string {
ctx.indentLevel -= 1;
if (e.name !== "__root__" && !dtd.auto_closing) {
if (e.name !== "pre") {
- if (dtd.type === "block") {
+ if (isBlockNode(e)) {
if (needsLineBreak(prevChild)) {
s += "\n";
}
@@ -209,7 +219,7 @@ function elementNodeToHtmlText(e: Element, ctx: Context): string {
}
}
s += `</${e.name}>`;
- if (dtd.type === "block") {
+ if (isBlockNode(e)) {
s += "\n";
}
}