From 5bb6463a4b04a9d6f603a3ef2e3f9945209c41fe Mon Sep 17 00:00:00 2001 From: Oliver Booth Date: Thu, 10 Aug 2023 16:16:29 +0100 Subject: [PATCH] fix: use manual Prism highlighting --- OliverBooth/Pages/Shared/_Layout.cshtml | 2 +- src/ts/UI.ts | 15 ++++++++++++++- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/OliverBooth/Pages/Shared/_Layout.cshtml b/OliverBooth/Pages/Shared/_Layout.cshtml index d00e20f..d7a4fea 100644 --- a/OliverBooth/Pages/Shared/_Layout.cshtml +++ b/OliverBooth/Pages/Shared/_Layout.cshtml @@ -71,7 +71,7 @@ - + @await RenderSectionAsync("Scripts", required: false) diff --git a/src/ts/UI.ts b/src/ts/UI.ts index 8a93c78..47accdb 100644 --- a/src/ts/UI.ts +++ b/src/ts/UI.ts @@ -1,5 +1,6 @@ -declare const bootstrap: any; +declare const bootstrap: any; declare const katex: any; +declare const Prism: any; class UI { public static get blogPostContainer(): HTMLDivElement { @@ -27,6 +28,7 @@ class UI { public static updateUI(element?: Element) { element = element || document.body; UI.addLineNumbers(element); + UI.addHighlighting(element); UI.addBootstrapTooltips(element); UI.renderTeX(element); UI.unescapeMarkTags(element); @@ -60,6 +62,17 @@ class UI { }); } + /** + * Adds syntax highlighting to all
  blocks in the element.
+     * @param element The element to search for 
  blocks in.
+     */
+    public static addHighlighting(element?: Element) {
+        element = element || document.body;
+        element.querySelectorAll("pre code").forEach((block) => {
+            Prism.highlightAllUnder(block.parentElement);
+        });
+    }
+
     /**
      * Renders all TeX in the document.
      */