From ce5df837f5f6ed57f9e9f85439ee9a40ebf234dc Mon Sep 17 00:00:00 2001 From: Jacky Zhao Date: Sat, 3 Dec 2022 21:03:12 -0800 Subject: [PATCH] feat: latex in search results --- assets/js/popover.js | 4 ++-- assets/js/util.js | 10 ++++++++++ layouts/partials/head.html | 4 ++-- 3 files changed, 14 insertions(+), 4 deletions(-) diff --git a/assets/js/popover.js b/assets/js/popover.js index 29104b919..ca13f9a68 100644 --- a/assets/js/popover.js +++ b/assets/js/popover.js @@ -5,7 +5,7 @@ function htmlToElement(html) { return template.content.firstChild } -function initPopover(baseURL, useContextualBacklinks, renderLatex) { +function initPopover(baseURL, useContextualBacklinks) { const basePath = baseURL.replace(window.location.origin, "") fetchData.then(({ content }) => { const links = [...document.getElementsByClassName("internal-link")] @@ -42,7 +42,7 @@ function initPopover(baseURL, useContextualBacklinks, renderLatex) { if (el) { li.appendChild(el) - if (renderLatex) { + if (LATEX_ENABLED) { renderMathInElement(el, { delimiters: [ { left: '$$', right: '$$', display: false }, diff --git a/assets/js/util.js b/assets/js/util.js index d17594ae2..3346b7d41 100644 --- a/assets/js/util.js +++ b/assets/js/util.js @@ -203,6 +203,16 @@ const displayResults = (term, finalResults, extractHighlight = false) => { } ) .join("\n") + if (LATEX_ENABLED) { + renderMathInElement(results, { + delimiters: [ + { left: '$$', right: '$$', display: false }, + { left: '$', right: '$', display: false }, + ], + throwOnError: false + }) + } + const anchors = [...document.getElementsByClassName("result-card")] anchors.forEach((anchor) => { anchor.onclick = () => redir(anchor.id, term) diff --git a/layouts/partials/head.html b/layouts/partials/head.html index b5b015490..b9c54387e 100644 --- a/layouts/partials/head.html +++ b/layouts/partials/head.html @@ -82,6 +82,7 @@ }}