From 67da389005c9fb669eff133e58fc13fec03d896f Mon Sep 17 00:00:00 2001 From: Danila Fedorin Date: Tue, 21 May 2024 20:39:21 -0700 Subject: [PATCH] Break up code creating highlight groups and pass in line numbers Signed-off-by: Danila Fedorin --- layouts/shortcodes/codeblock.html | 10 +++++++++- layouts/shortcodes/codelines.html | 12 +++++++++++- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/layouts/shortcodes/codeblock.html b/layouts/shortcodes/codeblock.html index a8a432c..722b746 100644 --- a/layouts/shortcodes/codeblock.html +++ b/layouts/shortcodes/codeblock.html @@ -1,2 +1,10 @@ {{ 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") + "path" (.Get 1) + "comment" ", entire file" + "code" (readFile (printf "code/%s" (.Get 1))) + "language" (.Get 0) + "opts" "linenos=table" +}} +{{ partial "highlightgroup.html" $groupconfig }} diff --git a/layouts/shortcodes/codelines.html b/layouts/shortcodes/codelines.html index bdab526..76e27e1 100644 --- a/layouts/shortcodes/codelines.html +++ b/layouts/shortcodes/codelines.html @@ -23,7 +23,17 @@ {{ with (.Scratch.Get "hidden") }}
{{ . | markdownify }} {{ 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 + "url" (.Scratch.Get "bestUrl") + "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") }}
{{ end }}