Skip to content

Commit 8933171

Browse files
committed
Merge branch 'fix-highlight-shortcode-local'
2 parents ff90eab + 268684c commit 8933171

File tree

3 files changed

+54
-2
lines changed

3 files changed

+54
-2
lines changed

hugolib/embedded_shortcodes_test.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,15 @@ void do();
9191
{{< /highlight >}}`,
9292
`(?s)<div class="highlight"><pre style="background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-java"`,
9393
},
94+
{` {{< highlight emacs-lisp >}}
95+
(message "hello")
96+
97+
(message "hello again")
98+
{{< /highlight >}}`,
99+
`(?s)<div class="highlight"><pre style="background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-emacs-lisp" data-lang="emacs-lisp">\(message <span style="font-style:italic">&#34;hello&#34;</span>\)
100+
101+
\(message <span style="font-style:italic">&#34;hello again&#34;</span>\)</code></pre></div>`,
102+
},
94103
{`{{< highlight java "style=friendly" >}}
95104
void do();
96105
{{< /highlight >}}`,

tpl/tplimpl/embedded/templates.autogen.go

Lines changed: 23 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,22 @@
1-
{{ if len .Params | eq 2 }}{{ highlight (trim .Inner "\n\r") (.Get 0) (.Get 1) }}{{ else }}{{ highlight (trim .Inner "\n\r") (.Get 0) "" }}{{ end }}
1+
{{- $code := (trim .Inner "\n\r") -}}
2+
{{- $lang := .Get 0 -}}
3+
{{- $options := .Get 1 | default "" -}}
4+
{{- $code_ending_in_line_with_spaces := (findRE "[\\r\\n][[:blank:]]+$" $code) -}}
5+
{{/* Ref: https://github.com/gohugoio/hugo/issues/4717#issuecomment-449375012 */}}
6+
{{- with $code_ending_in_line_with_spaces -}}
7+
{{- $code = (replace $code "\r" "") -}} {{/* Windows -> Unix style line endings for ease in further parsing */}}
8+
{{- $offset := (trim (index . 0) "\n") -}}
9+
{{- $lines := (split $code "\n") -}}
10+
{{- $num_lines := (len $lines) -}}
11+
{{- $scratch := newScratch -}}
12+
{{- $scratch.Add "lines_minus_offset" (slice) -}}
13+
{{- range $i, $line := $lines -}}
14+
{{- $line_minus_offset := (strings.TrimPrefix $offset $line) -}}
15+
{{- if (lt $i (sub $num_lines 1)) -}} {{/* Do not add the last blank line */}}
16+
{{- $scratch.Add "lines_minus_offset" (slice $line_minus_offset) -}}
17+
{{- end -}}
18+
{{- end -}}
19+
{{- $code = (delimit ($scratch.Get "lines_minus_offset") "\n") -}}
20+
{{- $scratch.Delete "lines_minus_offset" -}}
21+
{{- end -}}
22+
{{- highlight $code $lang $options -}}

0 commit comments

Comments
 (0)