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.
*/