diff options
| author | nsfisis <nsfisis@gmail.com> | 2023-03-18 15:47:05 +0900 |
|---|---|---|
| committer | nsfisis <nsfisis@gmail.com> | 2023-03-18 15:47:05 +0900 |
| commit | 2b50e1778b164e641c03c2e77176b6f47ca1e278 (patch) | |
| tree | 3fa48f5c5c3c2b9d8753ce82d438aa2523856660 /nuldoc-src/docbook/to_html.ts | |
| parent | 4ce1f674055ac1dd1c4864f366aac212f5643248 (diff) | |
| download | blog.nsfisis.dev-2b50e1778b164e641c03c2e77176b6f47ca1e278.tar.gz blog.nsfisis.dev-2b50e1778b164e641c03c2e77176b6f47ca1e278.tar.zst blog.nsfisis.dev-2b50e1778b164e641c03c2e77176b6f47ca1e278.zip | |
refactor: add RawHTML type to represent text node not being escaped
Diffstat (limited to 'nuldoc-src/docbook/to_html.ts')
| -rw-r--r-- | nuldoc-src/docbook/to_html.ts | 12 |
1 files changed, 10 insertions, 2 deletions
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"); }); } |
