diff --git a/src/main/java/run/halo/prismjs/PrismJSHeadProcessor.java b/src/main/java/run/halo/prismjs/PrismJSHeadProcessor.java index 3c5d12e..829b29a 100644 --- a/src/main/java/run/halo/prismjs/PrismJSHeadProcessor.java +++ b/src/main/java/run/halo/prismjs/PrismJSHeadProcessor.java @@ -36,11 +36,12 @@ public Mono process(ITemplateContext context, IModel model, IElementModelS } private String highlightJsScript(String css, String customCss, Boolean lineNumber) { + // language=html return """ - + @@ -57,22 +58,20 @@ private String highlightJsScript(String css, String customCss, Boolean lineNumbe document.addEventListener("DOMContentLoaded", async function () { var customCss = %s; - - if (customCss !== null || customCss !== undefined || customCss !== '') { + + if (customCss !== null && customCss !== undefined && customCss !== '') { await loadCss(`customCss`); - s console.log("CustomCss: ", customCss); } if (%s) { + console.log("ShowLineNumber"); await loadCss(`/plugins/PluginPrismJS/assets/static/plugins/line-numbers/prism-line-numbers.min.css`); await loadScript(`/plugins/PluginPrismJS/assets/static/plugins/line-numbers/prism-line-numbers.min.js`); - - console.log("ShowLineNumber"); } - }); + }) function loadScript(url) { return new Promise(function (resolve, reject) { @@ -88,10 +87,11 @@ function loadScript(url) { function loadCss(url) { return new Promise(function (resolve, reject) { const css = document.createElement("link"); - css.rel = 'stylesheet'; + css.rel = "stylesheet"; css.href = url; css.onload = resolve; css.onerror = reject; + document.head.appendChild(css); }); }