diff --git a/static/js/libs/hljs.js b/static/js/libs/hljs.js new file mode 100644 index 0000000..5172c31 --- /dev/null +++ b/static/js/libs/hljs.js @@ -0,0 +1,9 @@ +window.addEventListener("load", () => { + hljs.configure({ + noHighlightRe: /^$/i, + languageDetectRe: /\blanguage-hljs-([\w-]+)\b/i, + }); + + hljs.addPlugin(new CopyButtonPlugin()); + hljs.highlightAll(); +}); diff --git a/static/js/libs/jspdf.js b/static/js/libs/jspdf.js new file mode 100644 index 0000000..1a89587 --- /dev/null +++ b/static/js/libs/jspdf.js @@ -0,0 +1,14 @@ +window.addEventListener("DOMContentLoaded", () => { + const { jsPDF } = window.jspdf; + + const doc = new jsPDF(); + + doc.html(document.body, { + width: doc.internal.pageSize.getWidth() - 20, + windowWidth: 800, + margin: [15, 10, 10, 10], + callback: function (doc) { + doc.save(`${document.title}.pdf`); + }, + }); +}); diff --git a/static/js/libs/katex.js b/static/js/libs/katex.js new file mode 100644 index 0000000..9eb5541 --- /dev/null +++ b/static/js/libs/katex.js @@ -0,0 +1,26 @@ +window.addEventListener("load", () => { + const macros = {}; + for (const item of new Map( + Object.entries({ + N: "mathbb{N}", + R: "mathbb{R}", + Z: "mathbb{Z}", + O: "Theta", + ra: "rightarrow", + la: "leftarrow", + RA: "Rightarrow", + LA: "Leftarrow", + }) + )[Symbol.iterator]()) { + macros[`\\${item[0]}`] = `\\${item[1]}`; + } + + renderMathInElement(document.body, { + delimiters: [ + { left: "$$", right: "$$", display: true }, + { left: "$", right: "$", display: false }, + ], + throwOnError: false, + macros, + }); +}); diff --git a/static/js/libs/mermaid.js b/static/js/libs/mermaid.js new file mode 100644 index 0000000..1656d4a --- /dev/null +++ b/static/js/libs/mermaid.js @@ -0,0 +1,8 @@ +import mermaid from "https://cdn.jsdelivr.net/npm/mermaid@10/dist/mermaid.esm.min.mjs"; + +window.addEventListener("load", async () => { + mermaid.initialize({ startOnLoad: false }); + await mermaid.run({ + querySelector: ".language-mermaid", + }); +}); diff --git a/templates/libs/hljs_footer.html b/templates/libs/hljs_footer.html index e50064d..7d2469d 100644 --- a/templates/libs/hljs_footer.html +++ b/templates/libs/hljs_footer.html @@ -1,11 +1,3 @@ - + diff --git a/templates/libs/jspdf_footer.html b/templates/libs/jspdf_footer.html index c5e8199..8888de1 100644 --- a/templates/libs/jspdf_footer.html +++ b/templates/libs/jspdf_footer.html @@ -5,19 +5,4 @@ crossorigin="anonymous" referrerpolicy="no-referrer" > - + diff --git a/templates/libs/katex_footer.html b/templates/libs/katex_footer.html index 9cb2be2..2b2a92b 100644 --- a/templates/libs/katex_footer.html +++ b/templates/libs/katex_footer.html @@ -10,31 +10,4 @@ integrity="sha384-+VBxd3r6XgURycqtZ117nYw44OOcIax56Z4dCRWbxyPt0Koah1uHoK0o4+/RRE05" crossorigin="anonymous" > - + diff --git a/templates/libs/mermaid_footer.html b/templates/libs/mermaid_footer.html index c1cb642..bd94931 100644 --- a/templates/libs/mermaid_footer.html +++ b/templates/libs/mermaid_footer.html @@ -1,7 +1 @@ - +