From e884f4927f3e48285ca6689507f5e0f61072de04 Mon Sep 17 00:00:00 2001
From: Jacky Zhao <j.zhao2k19@gmail.com>
Date: Thu, 30 Jun 2022 00:17:53 +0000
Subject: [PATCH] fix: anchor formatting (closes #141)

---
 layouts/partials/textprocessing.html |    6 +++++-
 1 files changed, 5 insertions(+), 1 deletions(-)

diff --git a/layouts/partials/textprocessing.html b/layouts/partials/textprocessing.html
index 2312aa4..56e2e8b 100644
--- a/layouts/partials/textprocessing.html
+++ b/layouts/partials/textprocessing.html
@@ -39,7 +39,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 +53,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