From c117e38899a7e122fb4dee87f5d091e654e0939f Mon Sep 17 00:00:00 2001 From: Jacky Zhao Date: Sat, 2 Apr 2022 20:06:31 -0700 Subject: [PATCH] feat: wikilinks implementation --- assets/js/popover.js | 1 + content/notes/CJK + Latex Support (测试).md | 8 +++++- layouts/_default/single.html | 2 +- layouts/index.html | 2 +- layouts/partials/textprocessing.html | 31 +++++++++++++++++++++ 5 files changed, 41 insertions(+), 3 deletions(-) create mode 100644 layouts/partials/textprocessing.html diff --git a/assets/js/popover.js b/assets/js/popover.js index 3d0d18b16..83cdc03d0 100644 --- a/assets/js/popover.js +++ b/assets/js/popover.js @@ -11,6 +11,7 @@ function initPopover(baseURL) { fetchData.then(({ content }) => { const links = [...document.getElementsByClassName("internal-link")] links.forEach(li => { + console.log(li.dataset) const linkDest = content[li.dataset.src.replace(basePath, "")] if (linkDest) { const popoverElement = `
diff --git a/content/notes/CJK + Latex Support (测试).md b/content/notes/CJK + Latex Support (测试).md index 5dc0b48a1..e4692d732 100644 --- a/content/notes/CJK + Latex Support (测试).md +++ b/content/notes/CJK + Latex Support (测试).md @@ -38,4 +38,10 @@ a & b & c $$ ## RTL -More information on configuring RTL languages like Arabic in the [config](notes/config.md) page \ No newline at end of file +More information on configuring RTL languages like Arabic in the [config](notes/config.md) page + +[[notes/troubleshooting]] + +[[notes/editing#Folder Structure|edit]] + +[[asdfasdf|todo]] \ No newline at end of file diff --git a/layouts/_default/single.html b/layouts/_default/single.html index 21e706641..c09f2dcf2 100644 --- a/layouts/_default/single.html +++ b/layouts/_default/single.html @@ -28,7 +28,7 @@ {{ .TableOfContents }} {{end}} - {{.Content | safeHTML}} + {{partial "textprocessing.html" . }} {{partial "footer.html" .}} {{partial "popover.html" .}} diff --git a/layouts/index.html b/layouts/index.html index 75b24bf8e..d449c2733 100644 --- a/layouts/index.html +++ b/layouts/index.html @@ -19,7 +19,7 @@ {{ .TableOfContents }} {{end}} - {{.Content | safeHTML}} + {{partial "textprocessing.html" . }} {{partial "footer.html" .}} {{partial "popover.html" .}} diff --git a/layouts/partials/textprocessing.html b/layouts/partials/textprocessing.html new file mode 100644 index 000000000..8e4a794f9 --- /dev/null +++ b/layouts/partials/textprocessing.html @@ -0,0 +1,31 @@ +{{ $content := .Content }} +{{ $page := .Page }} + +{{/* Replace right arrow */}} +{{ $content = replace $content "->" "→" }} + +{{/* Escape slashes for Latex to fix line breaks */}} +{{ $content = replaceRE "\\\\ *\n" "\\\\" $content }} + +{{/* Wikilinks */}} +{{$wikilinks := $content | findRE "\\[\\[[^\\[\\]\\|]*(?:\\|[^\\[\\]]*)?\\]\\]" }} +{{range $wikilinks}} + {{$inner := . | strings.TrimPrefix "[[" | strings.TrimSuffix "]]" }} + {{$split := split $inner "|"}} + {{$path := index $split 0}} + {{$reference := split $path "#"}} + {{$title := index $reference 0}} + {{$block := default "" (index $reference 1)}} + {{$block = strings.TrimRight "/" (cond (eq $block "") $block (printf "#%s" $block))}} + {{$href := strings.TrimRight "/" ($page.GetPage $title).RelPermalink}} + {{$display := default $title (index $split 1)}} + {{if not $href}} + {{$link := printf "%s" $display}} + {{ $content = replace $content . $link }} + {{else}} + {{$fullhref := printf "%s%s" $href $block }} + {{$link := printf "%s" $fullhref $href $display}} + {{ $content = replace $content . $link }} + {{end}} +{{end}} +{{ $content | safeHTML }}