From ed9a8efd1ff4ee569fa4256e044151670abaea82 Mon Sep 17 00:00:00 2001 From: Jacky Zhao Date: Thu, 5 May 2022 21:11:23 -0400 Subject: [PATCH] fix inline link highlighting, safer latex render --- assets/js/popover.js | 37 +++++++++++++++++++------------------ assets/js/search.js | 4 ++-- assets/styles/base.scss | 2 +- 3 files changed, 22 insertions(+), 21 deletions(-) diff --git a/assets/js/popover.js b/assets/js/popover.js index 5fb2244..494cd84 100644 --- a/assets/js/popover.js +++ b/assets/js/popover.js @@ -23,7 +23,6 @@ function initPopover(baseURL, useContextualBacklinks, renderLatex) { el = htmlToElement(popoverElement) } else { const linkDest = content[li.dataset.src.replace(/\/$/g, "").replace(basePath, "")] - console.log(linkDest.content) if (linkDest) { const popoverElement = `

${linkDest.title}

@@ -33,25 +32,27 @@ function initPopover(baseURL, useContextualBacklinks, renderLatex) { el = htmlToElement(popoverElement) } } - li.appendChild(el) - if (renderLatex) { - renderMathInElement(el, { - delimiters: [ - { left: '$$', right: '$$', display: false }, - { left: '$', right: '$', display: false }, - { left: '\\(', right: '\\)', display: false }, - { left: '\\[', right: '\\]', display: false } - ], - throwOnError: false + + if (el) { + li.appendChild(el) + if (renderLatex) { + renderMathInElement(el, { + delimiters: [ + { left: '$$', right: '$$', display: false }, + { left: '$', right: '$', display: false }, + { left: '\\(', right: '\\)', display: false }, + { left: '\\[', right: '\\]', display: false } + ], + throwOnError: false + }) + } + li.addEventListener("mouseover", () => { + el.classList.add("visible") + }) + li.addEventListener("mouseout", () => { + el.classList.remove("visible") }) } - li.addEventListener("mouseover", () => { - el.classList.add("visible") - }) - li.addEventListener("mouseout", () => { - el.classList.remove("visible") - }) - }) }) } diff --git a/assets/js/search.js b/assets/js/search.js index 195a40b..bb94cd3 100644 --- a/assets/js/search.js +++ b/assets/js/search.js @@ -38,8 +38,8 @@ const removeMarkdown = ( .replace(/(#{1,6})\s+(.+)\1?/g, '$2') .replace(/\s{0,2}\[.*?\]: .*?$/g, '') .replace(/\!\[(.*?)\][\[\(].*?[\]\)]/g, options.useImgAltText ? '$1' : '') - .replace(/\[(.*?)\][\[\(].*?[\]\)]/g, '$1') - .replace(/!?\[\[\S[^\[\]\|]*(?:\|([^\[\]]*))?\S\]\]/g, '$1') + .replace(/\[(.*?)\][\[\(].*?[\]\)]/g, '$1') + .replace(/!?\[\[\S[^\[\]\|]*(?:\|([^\[\]]*))?\S\]\]/g, '$1') .replace(/^\s{0,3}>\s?/g, '') .replace(/(^|\n)\s{0,3}>\s?/g, '\n\n') .replace(/^\s{1,2}\[(.*?)\]: (\S+)( ".*?")?\s*$/g, '') diff --git a/assets/styles/base.scss b/assets/styles/base.scss index 6378f90..1b9b936 100644 --- a/assets/styles/base.scss +++ b/assets/styles/base.scss @@ -569,7 +569,7 @@ header { font-size: 0.8rem; } - & > p { + & > p, & > a { margin: 0; font-weight: 400; user-select: none;