diff --git a/layouts/partials/textprocessing.html b/layouts/partials/textprocessing.html
index bd2cca5de..7f2902884 100644
--- a/layouts/partials/textprocessing.html
+++ b/layouts/partials/textprocessing.html
@@ -14,6 +14,7 @@
{{$codefences := $raw | findRE "\\x60[^\\x60\\n]+\\x60"}}
{{$codeblocks := $raw | findRE "\\x60{3}[^\\x60]+\\x60{3}"}}
{{$code := union $codefences $codeblocks}}
+
{{range $wikilinks}}
{{$cur := .}}
{{$incode := false}}
@@ -22,41 +23,56 @@
{{$incode = true}}
{{end}}
{{end}}
+
{{if not $incode}}
- {{if (hasPrefix . "!")}}
- {{$inner := . | strings.TrimPrefix "![[" | strings.TrimSuffix "]]" }}
- {{$split := split $inner "|"}}
- {{$path := index $split 0 | relURL}}
- {{$width := index $split 1}}
- {{$img := printf "" $path (default "auto" $width)}}
- {{$content = replace $content . $img}}
- {{else}}
-
- {{$inner := . | strings.TrimPrefix "[[" | strings.TrimSuffix "]]" }}
-
- {{$split := split $inner "|"}}
-
- {{$path := index $split 0}}
- {{$reference := split $path "#"}}
-
- {{$title := index $reference 0}}
-
+
+
+ {{$inner := . | strings.TrimPrefix "!" | strings.TrimPrefix "[[" | strings.TrimSuffix "]]" }}
+
+ {{$split := split $inner "|"}}
+
+ {{$path := index $split 0}}
+
+ {{$reference := split $path "#"}}
+
+ {{$title := index $reference 0}}
+
+
+ {{$display := default $title (index $split 1)}}
+
+ {{$display := index (last 1 (split $display "/")) 0}}
+
+ {{$curpage := $page.GetPage $title}}
+ {{$relpath := relURL $path}}
+
+
+ {{if not (eq $curpage.String "nopPage") }}
{{$block := default "" (index $reference 1)}}
{{$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)}}
-
- {{$display := index (last 1 (split $display "/")) 0}}
- {{if not $href}}
- {{$link := printf "%s" $display}}
+ {{$href := strings.TrimRight "/" $curpage.RelPermalink}}
+ {{$link := printf "%s" $href $block $href $display}}
+ {{$content = replace $content . $link}}
+
+ {{else if fileExists $relpath}}
+ {{$splitpath := split $relpath "/"}}
+ {{$dirname := first (sub (len $splitpath) 1) $splitpath | path.Join | urlize}}
+ {{$basename := index (last 1 $splitpath) 0}}
+ {{$href := printf "/%s/%s" $dirname $basename}}
+
+ {{if (hasPrefix . "!")}}
+ {{$width := index $split 1}}
+ {{$link := printf "" $href (default "auto" $width)}}
{{$content = replace $content . $link}}
{{else}}
- {{$fullhref := printf "%s%s" $href $block }}
- {{$link := printf "%s" $fullhref $href $display}}
+ {{$link := printf "%s" $href $display}}
{{$content = replace $content . $link}}
{{end}}
+
+ {{else}}
+ {{$link := printf "%s" $display}}
+ {{$content = replace $content . $link}}
{{end}}
+
{{end}}
{{end}}