From 015ed4cfa2db4636e03debcda0d4201f24346098 Mon Sep 17 00:00:00 2001
From: Aiden Bai 白宇彤 <aiden.bai05@gmail.com>
Date: Sun, 03 Jul 2022 02:40:18 +0000
Subject: [PATCH] Fix `width: auto` for SPA routing (#156)
---
layouts/partials/textprocessing.html | 16 +++++++++-------
1 files changed, 9 insertions(+), 7 deletions(-)
diff --git a/layouts/partials/textprocessing.html b/layouts/partials/textprocessing.html
index ad76d04..dfb0ff2 100644
--- a/layouts/partials/textprocessing.html
+++ b/layouts/partials/textprocessing.html
@@ -10,7 +10,7 @@
{{end}}
{{/* Wikilinks */}}
-{{$wikilinks := $raw | findRE "!?\\[\\[\\S[^\\[\\]\\|]*(?:\\|[^\\[\\]]*)?\\S\\]\\]" }}
+{{$wikilinks := $content | findRE "!?\\[\\[\\S[^\\[\\]\\|]*(?:\\|[^\\[\\]]*)?\\S\\]\\]" }}
{{$codefences := $raw | findRE "\\x60[^\\x60\\n]+\\x60"}}
{{$codeblocks := $raw | findRE "\\x60{3}[^\\x60]+\\x60{3}"}}
{{$code := union $codefences $codeblocks}}
@@ -26,11 +26,9 @@
{{if (hasPrefix . "!")}}
{{$inner := . | strings.TrimPrefix "![[" | strings.TrimSuffix "]]" }}
{{$split := split $inner "|"}}
- {{$path := index $split 0}}
- {{$reference := split $path "#"}}
- {{$title := index $reference 0}}
- {{$display := default $title (index $split 1)}}
- {{$img := printf "<img src=\"%s\" title=\"%s\">" $path $display}}
+ {{$path := index $split 0 | relURL}}
+ {{$width := index $split 1}}
+ {{$img := printf "<img src=\"%s\" width=\"%s\" />" $path (default "auto" $width)}}
{{$content = replace $content . $img}}
{{else}}
{{$inner := . | strings.TrimPrefix "[[" | strings.TrimSuffix "]]" }}
@@ -39,7 +37,7 @@
{{$reference := split $path "#"}}
{{$title := index $reference 0}}
{{$block := default "" (index $reference 1)}}
- {{$block = strings.TrimRight "/" (cond (eq $block "") $block (printf "#%s" $block))}}
+ {{$block = strings.TrimRight "/" (cond (eq $block "") $block (printf "#%s" $block)) | urlize | lower}}
{{$href := strings.TrimRight "/" ($page.GetPage $title).RelPermalink}}
{{$display := default $title (index $split 1)}}
{{if not $href}}
@@ -53,4 +51,8 @@
{{end}}
{{end}}
{{end}}
+
+{{/* 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>` }}
+
{{ $content | safeHTML }}
--
Gitblit v1.10.0