diff options
Diffstat (limited to 'nuldoc-src/renderers/html.ts')
| -rw-r--r-- | nuldoc-src/renderers/html.ts | 22 |
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"; } } |
