diff --git a/layout/includes/third-party/abcjs/abcjs.pug b/layout/includes/third-party/abcjs/abcjs.pug index 453f84b..9de2b97 100644 --- a/layout/includes/third-party/abcjs/abcjs.pug +++ b/layout/includes/third-party/abcjs/abcjs.pug @@ -1,17 +1,46 @@ script. - (() => { - const abcjsInit = () => { - const abcjsFn = () => setTimeout(() => { - document.querySelectorAll(".abc-music-sheet").forEach(ele => { - if (ele.children.length > 0) return - ABCJS.renderAbc(ele, ele.innerHTML, {responsive: 'resize'}) - }) - }, 100) - - typeof ABCJS === 'object' ? abcjsFn() - : btf.getScript('!{url_for(theme.asset.abcjs_basic_js)}').then(abcjsFn) + (function() { + const abcjsInit = function() { + const abcjsFn = function() { + setTimeout(function() { + const sheets = document.querySelectorAll(".abc-music-sheet") + for (let i = 0; i < sheets.length; i++) { + const ele = sheets[i] + if (ele.children.length > 0) continue + + // Parse parameters from data-params attribute + let params = {} + const dp = ele.getAttribute("data-params") + if (dp) { + try { + params = JSON.parse(dp) + } catch (e) { + console.error("Failed to parse data-params:", e) + } + } + + // Merge parsed parameters with the responsive option + // Ensures params content appears before responsive + const options = { ...params, responsive: "resize" } + + // Render the music score using ABCJS.renderAbc + ABCJS.renderAbc(ele, ele.innerHTML, options) + } + }, 100) + } + + if (typeof ABCJS === "object") { + abcjsFn() + } else { + btf.getScript("!{url_for(theme.asset.abcjs_basic_js)}").then(abcjsFn) + } } - window.pjax ? abcjsInit() : window.addEventListener('load', abcjsInit) - btf.addGlobalFn('encrypt', abcjsInit, 'abcjs') - })() \ No newline at end of file + if (window.pjax) { + abcjsInit() + } else { + window.addEventListener("load", abcjsInit) + } + + btf.addGlobalFn("encrypt", abcjsInit, "abcjs") + })() diff --git a/layout/includes/third-party/pjax.pug b/layout/includes/third-party/pjax.pug index a8094f1..94ec038 100644 --- a/layout/includes/third-party/pjax.pug +++ b/layout/includes/third-party/pjax.pug @@ -59,7 +59,10 @@ script. document.addEventListener('pjax:error', e => { if (e.request.status === 404) { - window.location.href = e.request.responseURL + const usePjax = !{theme.pjax && theme.pjax.enable} + !{theme.error_404 && theme.error_404.enable} + ? (usePjax ? pjax.loadUrl('!{url_for("/404.html")}') : window.location.href = '!{url_for("/404.html")}') + : window.location.href = e.request.responseURL } }) - })() \ No newline at end of file + })() diff --git a/scripts/tag/score.js b/scripts/tag/score.js index dc380a5..df345e5 100644 --- a/scripts/tag/score.js +++ b/scripts/tag/score.js @@ -6,17 +6,45 @@ 'use strict' const score = (args, content) => { + // Escape HTML tags and some special characters, including curly braces const escapeHtmlTags = s => { const lookup = { '&': '&', '"': '"', - '\'': ''', + "'": ''', '<': '<', - '>': '>' + '>': '>', + '{': '{', + '}': '}' } - return s.replace(/[&"'<>]/g, c => lookup[c]) + return s.replace(/[&"'<>{}]/g, c => lookup[c]) } - return `