Jacky Zhao
2022-07-14 7ccff2cf3d4f7a96be2cf890093798067951fd2e
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 }}