diff --git a/assets/js/popover.js b/assets/js/popover.js index 6fec7e5e0..94edc3df3 100644 --- a/assets/js/popover.js +++ b/assets/js/popover.js @@ -7,6 +7,7 @@ function htmlToElement(html) { function initPopover(baseURL, useContextualBacklinks, renderLatex) { const basePath = baseURL.replace(window.location.origin, "") + const regex = /\[!.+\]-? /; fetchData.then(({ content }) => { const links = [...document.getElementsByClassName("internal-link")] links @@ -17,7 +18,7 @@ function initPopover(baseURL, useContextualBacklinks, renderLatex) { const linkDest = content[li.dataset.src] const popoverElement = `

${linkDest.title}

-

${highlight(removeMarkdown(linkDest.content), li.dataset.ctx)}...

+

${highlight(removeMarkdown(linkDest.content), li.dataset.ctx).replace(regex, "")}...

${new Date(linkDest.lastmodified).toLocaleDateString()}

` el = htmlToElement(popoverElement) @@ -26,7 +27,7 @@ function initPopover(baseURL, useContextualBacklinks, renderLatex) { if (linkDest) { const popoverElement = `

${linkDest.title}

-

${removeMarkdown(linkDest.content).split(" ", 20).join(" ")}...

+

${removeMarkdown(linkDest.content).split(" ", 20).join(" ").replace(regex, "")}...

${new Date(linkDest.lastmodified).toLocaleDateString()}

` el = htmlToElement(popoverElement) diff --git a/assets/js/search.js b/assets/js/search.js index 5896061ba..bca57b3b1 100644 --- a/assets/js/search.js +++ b/assets/js/search.js @@ -138,12 +138,13 @@ const highlight = (content, term) => { } const resultToHTML = ({ url, title, content, term }) => { + const regex = /\[!.+\]-? /; const text = removeMarkdown(content) const resultTitle = highlight(title, term) const resultText = highlight(text, term) return `` } diff --git a/layouts/partials/head.html b/layouts/partials/head.html index 4338c0b97..f804870ab 100644 --- a/layouts/partials/head.html +++ b/layouts/partials/head.html @@ -3,7 +3,7 @@ {{ if .Title }}{{ .Title }}{{ else }}{{ $.Site.Data.config.page_title }}{{ diff --git a/layouts/partials/textprocessing.html b/layouts/partials/textprocessing.html index dfb0ff2ef..aea3cec29 100644 --- a/layouts/partials/textprocessing.html +++ b/layouts/partials/textprocessing.html @@ -55,4 +55,29 @@ {{/* Add jumpable anchors */}} {{ $content = $content | replaceRE "(<h[1-9] id=\"([^\"]+)\">)(.+)(</h[1-9]>)" `<a href="#${2}">${1}<span class="hanchor" ariaLabel="Anchor"># </span>${3}${4}</a>` }} +{{/* Callouts */}} +{{ $content = $content | replaceRE "<blockquote>" "<blockquote class=callout>" }} +{{ $blockquoteclasses := findRE `\[!.+\]` $content }} +{{ $blockquoteclasses1 := findRE "<blockquote.*?>(.|\n)*?</blockquote>" $content }} +{{ $blockquotetags := findRE `blockquote class=callout` $content }} +{{ $counter := 0 }} +{{ $counter1 := 0 }} +{{ $finder := index $blockquoteclasses1 $counter }} +{{range $blockquotetags}} + {{ $finder = index $blockquoteclasses1 $counter }} + {{ if (in $finder "[!") }} + {{ $inner := index $blockquoteclasses $counter1 }} + {{ $inner = $inner | replaceRE `\[!(.+)\]` `${1}` }} + {{ $inner = printf "blockquote class=%s-callout" $inner}} + {{ $content = replace $content . $inner 1}} + {{ $counter1 = add $counter1 1 }} + {{ else }} + {{ $inner := print "blockquote" }} + {{ $content = replace $content . $inner 1}} + {{ end }} + {{ $counter = add $counter 1 }} +{{end}} +{{ $content = $content | replaceRE `\[!.+\]-?` "" }} +{{ $content = $content | replaceRE "blockquote class=callout" "blockquote" }} + {{ $content | safeHTML }}