From 5a06fb56b9c8ea1bb51fd45c56802b41338c9c65 Mon Sep 17 00:00:00 2001 From: liuzhihang Date: Wed, 26 Oct 2022 20:36:29 +0800 Subject: [PATCH] =?UTF-8?q?fix:=E4=B8=8D=E6=98=BE=E7=A4=BA=E5=A4=8D?= =?UTF-8?q?=E5=88=B6=E5=92=8C=E8=AF=AD=E8=A8=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../run/halo/prismjs/PrismJSHeadProcessor.java | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) 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); }); }