Skip to content

Commit 1cd4dac

Browse files
committed
try again
1 parent 2080bee commit 1cd4dac

File tree

1 file changed

+9
-10
lines changed

1 file changed

+9
-10
lines changed

website_and_docs/layouts/shortcodes/gh-codeblock.html

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -39,23 +39,22 @@
3939
{{ $content := base64Decode $apiResults.content }}
4040
{{ $codeSnippet := $content }}
4141

42-
{{ $parsedApiUrl := urls.Parse $webUrl }}
43-
{{ with $parsedApiUrl.Fragment }}
44-
{{ $codeLines := split $parsedApiUrl.Fragment "-" }}
45-
{{ $fromLine := sub (int (replace (index $codeLines 0) "L" "")) 1 }}
46-
{{ $toLine := int (cond (eq (len $codeLines) 1) (replace (index $codeLines 0) "L" "") (replace (index $codeLines 1) "L" "")) }}
47-
{{ $numOfLines := cond (eq (sub $toLine $fromLine) 0) 1 (sub $toLine $fromLine) }}
48-
{{ $splitContent := split $content "\n" }}
49-
{{ $codeSnippet = delimit (first $numOfLines (after $fromLine $splitContent)) "\n" }}
50-
{{ end }}
42+
{{ if $hasFragment }}
43+
{{ $fragment := index (split $fullPath "#") 1 }}
44+
{{ $codeLines := split $fragment "-" }}
45+
{{ $fromLine := sub (int (replace (index $codeLines 0) "L" "")) 1 }}
46+
{{ $toLine := int (cond (eq (len $codeLines) 1) (replace (index $codeLines 0) "L" "") (replace (index $codeLines 1) "L" "")) }}
47+
{{ $splitContent := split $content "\n" }}
48+
{{ $codeSnippet = delimit (slice $splitContent $fromLine (add $toLine 1)) "\n" }}
49+
{{ end }}
5150

5251
<div class="gh-codeblock-wrapper">
5352
{{ highlight $codeSnippet $language }}
5453

5554
{{ if $hasFragment }}
5655
<details class="mt-3">
5756
<summary>Show full example</summary>
58-
<div class="pt-2 highlight">
57+
<div class="pt-2">
5958
{{ highlight $content $language }}
6059
</div>
6160
</details>

0 commit comments

Comments
 (0)