From 4ce1f674055ac1dd1c4864f366aac212f5643248 Mon Sep 17 00:00:00 2001 From: nsfisis Date: Sat, 18 Mar 2023 15:28:50 +0900 Subject: refactor: provide type declaration of highlight.js --- nuldoc-src/docbook/to_html.ts | 12 ++++-------- nuldoc-src/types/highlight-js.d.ts | 6 ++++++ 2 files changed, 10 insertions(+), 8 deletions(-) create mode 100644 nuldoc-src/types/highlight-js.d.ts (limited to 'nuldoc-src') diff --git a/nuldoc-src/docbook/to_html.ts b/nuldoc-src/docbook/to_html.ts index 7c21036..c824780 100644 --- a/nuldoc-src/docbook/to_html.ts +++ b/nuldoc-src/docbook/to_html.ts @@ -1,4 +1,5 @@ -import hljs from "hljs/highlight.min.js"; +// @deno-types="../types/highlight-js.d.ts" +import hljs from "npm:highlight.js"; import { Document } from "./document.ts"; import { DocBookError } from "../errors.ts"; import { @@ -299,13 +300,8 @@ function highlightPrograms(doc: Document) { } const sourceCode = (codeElement.children[0] as Text).content; - const validLanguage = - (hljs as { getLanguage: (s: string) => string }).getLanguage(language) - ? language - : "plaintext"; - const highlighted = (hljs as { - highlight: (s: string, o: { language: string }) => { value: string }; - }).highlight(sourceCode, { language: validLanguage }).value; + const highlighted = + hljs.highlight(sourceCode, { language: language }).value; (codeElement.children[0] as Text).content = highlighted; codeElement.attributes.set("class", "highlight"); diff --git a/nuldoc-src/types/highlight-js.d.ts b/nuldoc-src/types/highlight-js.d.ts new file mode 100644 index 0000000..312cd06 --- /dev/null +++ b/nuldoc-src/types/highlight-js.d.ts @@ -0,0 +1,6 @@ +declare module "highlight.js" { + function highlight( + code: string, + options: { language: string }, + ): { value: string }; +} -- cgit v1.2.3-70-g09d2