From 2b50e1778b164e641c03c2e77176b6f47ca1e278 Mon Sep 17 00:00:00 2001 From: nsfisis Date: Sat, 18 Mar 2023 15:47:05 +0900 Subject: refactor: add RawHTML type to represent text node not being escaped --- nuldoc-src/docbook/to_html.ts | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) (limited to 'nuldoc-src/docbook') diff --git a/nuldoc-src/docbook/to_html.ts b/nuldoc-src/docbook/to_html.ts index c824780..9f176d4 100644 --- a/nuldoc-src/docbook/to_html.ts +++ b/nuldoc-src/docbook/to_html.ts @@ -9,6 +9,7 @@ import { forEachChild, forEachChildRecursively, Node, + RawHTML, removeChildElements, Text, } from "../dom.ts"; @@ -239,6 +240,7 @@ function transformNoteElement(doc: Document) { children: [{ kind: "text", content: "Note", + raw: true, }], }; const contentElement: Element = { @@ -298,12 +300,18 @@ function highlightPrograms(doc: Document) { if (!language) { return; } - const sourceCode = (codeElement.children[0] as Text).content; + const sourceCodeNode = codeElement.children[0] as Text | RawHTML; + const sourceCode = sourceCodeNode.content; + + if (!hljs.getLanguage(language)) { + return; + } const highlighted = hljs.highlight(sourceCode, { language: language }).value; - (codeElement.children[0] as Text).content = highlighted; + sourceCodeNode.content = highlighted; + sourceCodeNode.raw = true; codeElement.attributes.set("class", "highlight"); }); } -- cgit v1.2.3-70-g09d2