Updated Regex

This commit is contained in:
saberzero1 2022-07-30 08:07:35 +02:00
parent 6d5914679d
commit 26d838a890
No known key found for this signature in database
GPG Key ID: D2C0887768D969D8
3 changed files with 6 additions and 6 deletions

View File

@ -7,7 +7,6 @@ function htmlToElement(html) {
function initPopover(baseURL, useContextualBacklinks, renderLatex) { function initPopover(baseURL, useContextualBacklinks, renderLatex) {
const basePath = baseURL.replace(window.location.origin, "") const basePath = baseURL.replace(window.location.origin, "")
const regex = /\[!.+\]-? /;
fetchData.then(({ content }) => { fetchData.then(({ content }) => {
const links = [...document.getElementsByClassName("internal-link")] const links = [...document.getElementsByClassName("internal-link")]
links links
@ -18,7 +17,7 @@ function initPopover(baseURL, useContextualBacklinks, renderLatex) {
const linkDest = content[li.dataset.src] const linkDest = content[li.dataset.src]
const popoverElement = `<div class="popover"> const popoverElement = `<div class="popover">
<h3>${linkDest.title}</h3> <h3>${linkDest.title}</h3>
<p>${highlight(removeMarkdown(linkDest.content), li.dataset.ctx).replace(regex, "")}...</p> <p>${highlight(removeMarkdown(linkDest.content), li.dataset.ctx)}...</p>
<p class="meta">${new Date(linkDest.lastmodified).toLocaleDateString()}</p> <p class="meta">${new Date(linkDest.lastmodified).toLocaleDateString()}</p>
</div>` </div>`
el = htmlToElement(popoverElement) el = htmlToElement(popoverElement)
@ -27,7 +26,7 @@ function initPopover(baseURL, useContextualBacklinks, renderLatex) {
if (linkDest) { if (linkDest) {
const popoverElement = `<div class="popover"> const popoverElement = `<div class="popover">
<h3>${linkDest.title}</h3> <h3>${linkDest.title}</h3>
<p>${removeMarkdown(linkDest.content).split(" ", 20).join(" ").replace(regex, "")}...</p> <p>${removeMarkdown(linkDest.content).split(" ", 20).join(" ")}...</p>
<p class="meta">${new Date(linkDest.lastmodified).toLocaleDateString()}</p> <p class="meta">${new Date(linkDest.lastmodified).toLocaleDateString()}</p>
</div>` </div>`
el = htmlToElement(popoverElement) el = htmlToElement(popoverElement)

View File

@ -45,6 +45,7 @@ const removeMarkdown = (
.replace(/(`{3,})(.*?)\1/gm, "$2") .replace(/(`{3,})(.*?)\1/gm, "$2")
.replace(/`(.+?)`/g, "$1") .replace(/`(.+?)`/g, "$1")
.replace(/\n{2,}/g, "\n\n") .replace(/\n{2,}/g, "\n\n")
.replace(/\[![a-zA-Z]+\]-? /g, "")
} catch (e) { } catch (e) {
console.error(e) console.error(e)
return markdown return markdown
@ -138,7 +139,7 @@ const highlight = (content, term) => {
} }
const resultToHTML = ({ url, title, content, term }) => { const resultToHTML = ({ url, title, content, term }) => {
const regex = /\[!.+\]-? /; const regex = /\[![a-zA-z]\]-? /;
const text = removeMarkdown(content) const text = removeMarkdown(content)
const resultTitle = highlight(title, term) const resultTitle = highlight(title, term)
const resultText = highlight(text, term) const resultText = highlight(text, term)

View File

@ -67,7 +67,7 @@
{{ $finder = index $blockquoteclasses1 $counter }} {{ $finder = index $blockquoteclasses1 $counter }}
{{ if (in $finder "[!") }} {{ if (in $finder "[!") }}
{{ $inner := index $blockquoteclasses $counter1 }} {{ $inner := index $blockquoteclasses $counter1 }}
{{ $inner = $inner | replaceRE `\[!(.+)\]` `${1}` }} {{ $inner = $inner | replaceRE `\[!([a-zA-Z]+)\]` `${1}` }}
{{ $inner = printf "blockquote class=%s-callout" $inner}} {{ $inner = printf "blockquote class=%s-callout" $inner}}
{{ $content = replace $content . $inner 1}} {{ $content = replace $content . $inner 1}}
{{ $counter1 = add $counter1 1 }} {{ $counter1 = add $counter1 1 }}
@ -77,7 +77,7 @@
{{ end }} {{ end }}
{{ $counter = add $counter 1 }} {{ $counter = add $counter 1 }}
{{end}} {{end}}
{{ $content = $content | replaceRE `\[!.+\]-?` "" }} {{ $content = $content | replaceRE `\[![a-zA-Z]+\]-?` "" }}
{{ $content = $content | replaceRE "blockquote class=callout" "blockquote" }} {{ $content = $content | replaceRE "blockquote class=callout" "blockquote" }}
{{ $content | safeHTML }} {{ $content | safeHTML }}