Compare commits

..

8 Commits

Author SHA1 Message Date
e531ebd992 Also include the base path and the file path in highlight groups
Signed-off-by: Danila Fedorin <danila.fedorin@gmail.com>
2024-05-21 21:44:59 -07:00
8a5bbf460b Trim whitespace in more places
Signed-off-by: Danila Fedorin <danila.fedorin@gmail.com>
2024-05-21 21:42:35 -07:00
48bdf9ef08 Remove newlines from group dict info
Signed-off-by: Danila Fedorin <danila.fedorin@gmail.com>
2024-05-21 21:31:37 -07:00
b1334455ea Track the best path for a submodule that was added
For Agda, this is a proxy for 'root directory' of a project

Signed-off-by: Danila Fedorin <danila.fedorin@gmail.com>
2024-05-21 20:59:08 -07:00
a6425c7510 Always add line numbers (why not?), but specially tag Agda blocks
Signed-off-by: Danila Fedorin <danila.fedorin@gmail.com>
2024-05-21 20:41:10 -07:00
52ea5abbc8 For Agda code blocks, thread through line numbers
Signed-off-by: Danila Fedorin <danila.fedorin@gmail.com>
2024-05-21 20:39:28 -07:00
67da389005 Break up code creating highlight groups and pass in line numbers
Signed-off-by: Danila Fedorin <danila.fedorin@gmail.com>
2024-05-21 20:39:21 -07:00
a6a14c3909 Allow "group" partial to accept custom attributes
Signed-off-by: Danila Fedorin <danila.fedorin@gmail.com>
2024-05-21 20:38:42 -07:00
6 changed files with 72 additions and 38 deletions

View File

@@ -1,11 +1,12 @@
{{ $scratch := .scratch }} {{- $scratch := .scratch -}}
{{ $scratch.Set "bestLength" -1 }} {{- $scratch.Set "bestLength" -1 -}}
{{ $scratch.Set "bestUrl" (printf "%s/code/%s" .siteSourceUrl .path) }} {{- $scratch.Set "bestUrl" (printf "%s/code/%s" .siteSourceUrl .path) -}}
{{ $filePath := .path }} {{- $filePath := .path -}}
{{ range $path, $url := .submoduleLinks }} {{- range $path, $url := .submoduleLinks -}}
{{ $bestLength := $scratch.Get "bestLength" }} {{- $bestLength := $scratch.Get "bestLength" -}}
{{ if and (le $bestLength (len $path)) (hasPrefix $filePath $path) }} {{- if and (le $bestLength (len $path)) (hasPrefix $filePath $path) -}}
{{ $scratch.Set "bestLength" (len $path) }} {{- $scratch.Set "bestLength" (len $path) -}}
{{ $scratch.Set "bestUrl" (printf "%s%s" $url (strings.TrimPrefix $path $filePath)) }} {{- $scratch.Set "bestPath" $path -}}
{{ end }} {{- $scratch.Set "bestUrl" (printf "%s%s" $url (strings.TrimPrefix $path $filePath)) -}}
{{ end }} {{- end -}}
{{- end -}}

View File

@@ -1,3 +1,3 @@
<div class="highlight-group"> <div class="highlight-group" {{ with .attrs }}{{ . | safeHTMLAttr }}{{ end }}>
<div class="highlight-label">{{ i18n "from" }} <a href="{{ .url }}">{{ path.Base .path }}</a>{{ .comment }}</div>{{ .content }} <div class="highlight-label">{{ i18n "from" }} <a href="{{ .url }}">{{ path.Base .path }}</a>{{ .comment }}</div>{{ .content }}
</div> </div>

View File

@@ -1 +1,7 @@
{{ partial "group.html" (dict "url" .url "path" .path "comment" .comment "content" (highlight .code .language .opts)) }} {{- if (or .firstLine .lastLine) -}}
{{- page.Scratch.Set "highlightGroupAttrs" (printf "data-first-line=\"%v\" data-last-line=\"%v\" data-base-path=\"%s\" data-file-path=\"%v\"" .firstLine .lastLine .basePath .path) -}}
{{- end -}}
{{- if eq .language "Agda" -}}
{{- page.Scratch.Add "highlightGroupAttrs" " data-agda-block" -}}
{{- end -}}
{{ partial "group.html" (dict "url" .url "path" .path "comment" .comment "content" (highlight .code .language .opts) "attrs" (page.Scratch.Get "highlightGroupAttrs")) }}

View File

@@ -1,2 +1,11 @@
{{ partial "geturl.html" (dict "scratch" .Scratch "path" (.Get 1) "siteSourceUrl" .Site.Params.siteSourceUrl "submoduleLinks" .Site.Data.submodules) }} {{ partial "geturl.html" (dict "scratch" .Scratch "path" (.Get 1) "siteSourceUrl" .Site.Params.siteSourceUrl "submoduleLinks" .Site.Data.submodules) }}
{{ partial "highlightgroup.html" (dict "url" (.Scratch.Get "bestUrl") "path" (.Get 1) "comment" ", entire file" "code" (readFile (printf "code/%s" (.Get 1))) "language" (.Get 0) "opts" "linenos=table") }} {{- $groupconfig := dict
"url" (.Scratch.Get "bestUrl")
"basePath" (.Scratch.Get "bestPath")
"path" (.Get 1)
"comment" ", entire file"
"code" (readFile (printf "code/%s" (.Get 1)))
"language" (.Get 0)
"opts" "linenos=table"
-}}
{{ partial "highlightgroup.html" $groupconfig }}

View File

@@ -1,29 +1,40 @@
{{ $source := (readFile (printf "code/%s" (.Get 1))) }} {{- $source := (readFile (printf "code/%s" (.Get 1))) -}}
{{ $allLines := split $source "\n" }} {{- $allLines := split $source "\n" -}}
{{ if not (eq (int (.Get 2)) 1) }} {{- if not (eq (int (.Get 2)) 1) -}}
{{ .Scratch.Set "remLines" (after (sub (int (.Get 2)) 1) $allLines) }} {{- .Scratch.Set "remLines" (after (sub (int (.Get 2)) 1) $allLines) -}}
{{ else }} {{- else -}}
{{ .Scratch.Set "remLines" $allLines }} {{- .Scratch.Set "remLines" $allLines -}}
{{ end }} {{- end -}}
{{ $lines := first (add (sub (int (.Get 3)) (int (.Get 2))) 1) (.Scratch.Get "remLines") }} {{- $lines := first (add (sub (int (.Get 3)) (int (.Get 2))) 1) (.Scratch.Get "remLines") -}}
{{ if (.Get 4) }} {{- if (.Get 4) -}}
{{ .Scratch.Set "opts" (printf ",%s" (.Get 4)) }} {{- .Scratch.Set "opts" (printf ",%s" (.Get 4)) -}}
{{ else }} {{- else -}}
{{ .Scratch.Set "opts" "" }} {{- .Scratch.Set "opts" "" -}}
{{ end }} {{- end -}}
{{ if (.Get 5) }} {{- if (.Get 5) -}}
{{ .Scratch.Set "hidden" (.Get 5) }} {{- .Scratch.Set "hidden" (.Get 5) -}}
{{ end }} {{- end -}}
{{ partial "geturl.html" (dict "scratch" .Scratch "path" (.Get 1) "siteSourceUrl" .Site.Params.siteSourceUrl "submoduleLinks" .Site.Data.submodules) }} {{- partial "geturl.html" (dict "scratch" .Scratch "path" (.Get 1) "siteSourceUrl" .Site.Params.siteSourceUrl "submoduleLinks" .Site.Data.submodules) -}}
{{ partial "linerangestr.html" (dict "scratch" .Scratch "from" (.Get 2) "to" (.Get 3)) }} {{- partial "linerangestr.html" (dict "scratch" .Scratch "from" (.Get 2) "to" (.Get 3)) -}}
{{ with (.Scratch.Get "hidden") }} {{- with (.Scratch.Get "hidden") -}}
<details><summary>{{ . | markdownify }}</summary> <details><summary>{{ . | markdownify }}</summary>
{{ end }} {{- end -}}
{{ partial "highlightgroup.html" (dict "url" (.Scratch.Get "bestUrl") "path" (.Get 1) "comment" (.Scratch.Get "comment") "code" (delimit $lines "\n") "language" (.Get 0) "opts" (printf "linenos=table,linenostart=%d%s" (.Get 2) (.Scratch.Get "opts"))) }} {{- $groupconfig := dict
{{ with (.Scratch.Get "hidden") }} "url" (.Scratch.Get "bestUrl")
"basePath" (.Scratch.Get "bestPath")
"path" (.Get 1)
"comment" (.Scratch.Get "comment")
"code" (delimit $lines "\n")
"firstLine" (int (.Get 2))
"lastLine" (int (.Get 3))
"language" (.Get 0)
"opts" (printf "linenos=table,linenostart=%d%s" (.Get 2) (.Scratch.Get "opts"))
-}}
{{- partial "highlightgroup.html" $groupconfig -}}
{{- with (.Scratch.Get "hidden") -}}
</details> </details>
{{ end }} {{- end -}}

View File

@@ -1,2 +1,9 @@
{{ partial "geturl.html" (dict "scratch" .Scratch "path" (.Get 0) "siteSourceUrl" .Site.Params.siteSourceUrl "submoduleLinks" .Site.Data.submodules) }} {{ partial "geturl.html" (dict "scratch" .Scratch "path" (.Get 0) "siteSourceUrl" .Site.Params.siteSourceUrl "submoduleLinks" .Site.Data.submodules) }}
{{ partial "group.html" (dict "url" (.Scratch.Get "bestUrl") "path" (.Get 0) "comment" ", entire file" "content" (safeHTML (printf "<pre><code>%s</code></pre>" (htmlEscape (readFile (printf "code/%s" (.Get 0))))))) }} {{- $groupconfig := dict
"url" (.Scratch.Get "bestUrl")
"basePath" (.Scratch.Get "bestPath")
"path" (.Get 0)
"comment" ", entire file"
"content" (safeHTML (printf "<pre><code>%s</code></pre>" (htmlEscape (readFile (printf "code/%s" (.Get 0))))))
-}}
{{ partial "group.html" $groupconfig }}