aboutsummaryrefslogtreecommitdiffhomepage
path: root/services/nuldoc/nuldoc-src/markdown
diff options
context:
space:
mode:
Diffstat (limited to 'services/nuldoc/nuldoc-src/markdown')
-rw-r--r--services/nuldoc/nuldoc-src/markdown/mdast2ndoc.ts46
-rw-r--r--services/nuldoc/nuldoc-src/markdown/to_html.ts21
2 files changed, 39 insertions, 28 deletions
diff --git a/services/nuldoc/nuldoc-src/markdown/mdast2ndoc.ts b/services/nuldoc/nuldoc-src/markdown/mdast2ndoc.ts
index 367627c..626f119 100644
--- a/services/nuldoc/nuldoc-src/markdown/mdast2ndoc.ts
+++ b/services/nuldoc/nuldoc-src/markdown/mdast2ndoc.ts
@@ -29,7 +29,23 @@ import type {
LeafDirective,
TextDirective,
} from "mdast-util-directive";
-import { elem, Element, Node, rawHTML, text } from "../dom.ts";
+import {
+ a,
+ article,
+ div,
+ elem,
+ Element,
+ img,
+ li,
+ Node,
+ ol,
+ p,
+ rawHTML,
+ section,
+ span,
+ text,
+ ul,
+} from "../dom.ts";
type DirectiveNode = ContainerDirective | LeafDirective | TextDirective;
@@ -118,7 +134,7 @@ function processBlock(node: RootContent): Element | Element[] | null {
}
function processParagraph(node: Paragraph): Element {
- return elem("p", {}, ...node.children.map(processInline));
+ return p({}, ...node.children.map(processInline));
}
function processThematicBreak(_node: ThematicBreak): Element {
@@ -182,7 +198,9 @@ function processList(node: List): Element {
processListItem(item, isTaskList)
);
- return elem(node.ordered ? "ol" : "ul", attributes, ...children);
+ return node.ordered
+ ? ol(attributes, ...children)
+ : ul(attributes, ...children);
}
function processListItem(node: ListItem, isTaskList: boolean): Element {
@@ -204,7 +222,7 @@ function processListItem(node: ListItem, isTaskList: boolean): Element {
}
}
- return elem("li", attributes, ...children);
+ return li(attributes, ...children);
}
function processTable(node: Table): Element {
@@ -261,7 +279,7 @@ function processTableCell(
}
function processHtmlBlock(node: Html): Element {
- return elem("div", { class: "raw-html" }, rawHTML(node.value));
+ return div({ class: "raw-html" }, rawHTML(node.value));
}
function processDefinition(_node: Definition): null {
@@ -331,8 +349,7 @@ function processDirective(node: DirectiveNode): Element | null {
}
}
- return elem(
- "div",
+ return div(
node.attributes as Record<string, string> || {},
...children,
);
@@ -366,8 +383,7 @@ function processInline(node: PhrasingContent): Node {
return text(String(node.value));
}
if ("children" in node && Array.isArray(node.children)) {
- return elem(
- "span",
+ return span(
{},
...node.children.map((c: PhrasingContent) => processInline(c)),
);
@@ -407,7 +423,7 @@ function processLink(node: Link): Element {
if (isAutolink) {
attributes.class = "url";
}
- return elem("a", attributes, ...node.children.map(processInline));
+ return a(attributes, ...node.children.map(processInline));
}
function processImage(node: Image): Element {
@@ -421,7 +437,7 @@ function processImage(node: Image): Element {
if (node.title) {
attributes.title = node.title;
}
- return elem("img", attributes);
+ return img(attributes);
}
function processDelete(node: Delete): Element {
@@ -453,8 +469,7 @@ export function mdast2ndoc(root: Root): Element {
// Add footnotes section if any exist
if (footnotes.length > 0) {
- const footnoteSection = elem(
- "section",
+ const footnoteSection = section(
{ class: "footnotes" },
...footnotes,
);
@@ -464,7 +479,7 @@ export function mdast2ndoc(root: Root): Element {
return elem(
"__root__",
undefined,
- elem("article", undefined, ...articleContent),
+ article(undefined, ...articleContent),
);
}
@@ -566,8 +581,7 @@ function createSectionElement(sectionInfo: SectionInfo): Element {
attributes.id = sectionInfo.id;
}
- return elem(
- "section",
+ return section(
attributes,
sectionInfo.heading,
...sectionInfo.children,
diff --git a/services/nuldoc/nuldoc-src/markdown/to_html.ts b/services/nuldoc/nuldoc-src/markdown/to_html.ts
index 8219b74..8758b0d 100644
--- a/services/nuldoc/nuldoc-src/markdown/to_html.ts
+++ b/services/nuldoc/nuldoc-src/markdown/to_html.ts
@@ -2,8 +2,9 @@ import { BundledLanguage, bundledLanguages, codeToHtml } from "shiki";
import { Document, TocEntry } from "./document.ts";
import { NuldocError } from "../errors.ts";
import {
+ a,
addClass,
- elem,
+ div,
Element,
forEachChild,
forEachChildRecursively,
@@ -115,7 +116,7 @@ function transformLinkLikeToAnchorElement(doc: Document) {
}
const [_, prefix, url, suffix] = match;
nodes.push(text(prefix));
- nodes.push(elem("a", { href: url, class: "url" }, text(url)));
+ nodes.push(a({ href: url, class: "url" }, text(url)));
restContent = suffix;
}
return nodes;
@@ -188,7 +189,7 @@ function setSectionTitleAnchor(doc: Document) {
);
}
const sectionId = currentSection.attributes.id;
- const aElement = elem("a", undefined, ...c.children);
+ const aElement = a(undefined, ...c.children);
aElement.attributes.href = `#${sectionId}`;
c.children = [aElement];
}
@@ -224,13 +225,11 @@ function transformNoteElement(doc: Document) {
const operationAttr = n.attributes?.operation;
const isEditBlock = editatAttr && operationAttr;
- const labelElement = elem(
- "div",
+ const labelElement = div(
{ class: "admonition-label" },
text(isEditBlock ? `${editatAttr} ${operationAttr}` : "NOTE"),
);
- const contentElement = elem(
- "div",
+ const contentElement = div(
{ class: "admonition-content" },
...n.children,
);
@@ -273,8 +272,7 @@ function traverseFootnotes(doc: Document) {
delete n.attributes.reference;
n.attributes.class = "footnote";
n.children = [
- elem(
- "a",
+ a(
{
id: `footnoteref--${reference}`,
class: "footnote",
@@ -301,8 +299,7 @@ function traverseFootnotes(doc: Document) {
n.attributes.id = `footnote--${id}`;
n.children = [
- elem(
- "a",
+ a(
{ href: `#footnoteref--${id}` },
text(`${footnoteNumber}. `),
),
@@ -373,7 +370,7 @@ async function transformAndHighlightCodeBlockElement(doc: Document) {
delete n.attributes.filename;
n.children = [
- elem("div", { class: "filename" }, text(filename)),
+ div({ class: "filename" }, text(filename)),
rawHTML(highlighted),
];
} else {