From 8b2fba895aa804e895eaa02a622f318113a35663 Mon Sep 17 00:00:00 2001
From: Jacky Zhao <j.zhao2k19@gmail.com>
Date: Thu, 30 Jun 2022 00:34:05 +0000
Subject: [PATCH] feat: image scaling (closes #131)
---
layouts/partials/textprocessing.html | 14 ++++++++------
1 files changed, 8 insertions(+), 6 deletions(-)
diff --git a/layouts/partials/textprocessing.html b/layouts/partials/textprocessing.html
index f614868..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}}
@@ -27,10 +27,8 @@
{{$inner := . | strings.TrimPrefix "![[" | strings.TrimSuffix "]]" }}
{{$split := split $inner "|"}}
{{$path := index $split 0 | relURL}}
- {{$reference := split $path "#"}}
- {{$title := index $reference 0}}
- {{$display := default $title (index $split 1)}}
- {{$img := printf "<img src=\"%s\" title=\"%s\">" $path $display}}
+ {{$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