fix: use manual Prism highlighting

This commit is contained in:
Oliver Booth 2023-08-10 16:16:29 +01:00
parent 4244f9f014
commit 5bb6463a4b
Signed by: oliverbooth
GPG Key ID: 725DB725A0D9EE61
2 changed files with 15 additions and 2 deletions

View File

@ -71,7 +71,7 @@
<script src="https://cdnjs.cloudflare.com/ajax/libs/KaTeX/0.16.8/katex.min.js" integrity="sha512-aoZChv+8imY/U1O7KIHXvO87EOzCuKO0GhFtpD6G2Cyjo/xPeTgdf3/bchB10iB+AojMTDkMHDPLKNxPJVqDcw==" crossorigin="anonymous" referrerpolicy="no-referrer"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.2/js/all.min.js" integrity="sha512-uKQ39gEGiyUJl4AI6L+ekBdGKpGw4xJ55+xyJG7YFlJokPNYegn9KwQ3P8A7aFQAUtUsAQHep+d/lrGqrbPIDQ==" crossorigin="anonymous" referrerpolicy="no-referrer"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/handlebars.js/4.7.8/handlebars.min.js" integrity="sha512-E1dSFxg+wsfJ4HKjutk/WaCzK7S2wv1POn1RRPGh8ZK+ag9l244Vqxji3r6wgz9YBf6+vhQEYJZpSjqWFPg9gg==" crossorigin="anonymous" referrerpolicy="no-referrer"></script>
<script src="~/js/prism.min.js" asp-append-version="true"></script>
<script src="~/js/prism.min.js" asp-append-version="true" data-manual></script>
<script src="~/js/app.min.js" asp-append-version="true"></script>
@await RenderSectionAsync("Scripts", required: false)

View File

@ -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 <pre> <code> blocks in the element.
* @param element The element to search for <pre> <code> 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.
*/