Skip to content

Commit 5525485

Browse files
authored
Merge pull request #2276 from Arnaud-de-Grandmaison-ARM/line-numbering-start
Add a line numbering start attribute.
2 parents d0308de + c73ed9c commit 5525485

File tree

5 files changed

+40
-13
lines changed

5 files changed

+40
-13
lines changed

content/learning-paths/cross-platform/_example-learning-path/appendix-1-formatting.md

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -83,12 +83,26 @@ Specify that line_numbers are true in the following way:
8383
\`\`\`bash { line_numbers = "true" } \
8484
echo 'hello world' \
8585
echo ‘I am line two’ \
86-
\`\`\`
86+
\`\`\`
87+
88+
```bash { line_numbers = "true" }
89+
echo ‘hello world’
90+
echo ‘I am line two’
91+
```
92+
93+
In some cases, the line numbering should not start from one but from another
94+
value, e.g. if the code excerpt is extracted from a larger file. Use the
95+
`line_start` attribute to achieve this:
8796

88-
```bash { line_numbers = "true" }
89-
echo ‘hello world’
90-
echo ‘I am line two’
91-
```
97+
\`\`\`bash { line_numbers = "true" line_start = "10" } \
98+
echo 'hello world' \
99+
echo ‘I am line two’ \
100+
\`\`\`
101+
102+
```bash { line_numbers = "true" line_start = "10" }
103+
echo ‘hello world’
104+
echo ‘I am line eleven’
105+
```
92106

93107
### Output Lines
94108

themes/arm-design-system-hugo-theme/layouts/_default/_markup/render-codeblock.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,5 @@
66
```
77
*/}}
88
{{partial "general-formatting/prismjs-codeblock.html" (dict "input_from" "normal" "code" .Inner "language" .Type
9-
"line_numbers" .Attributes.line_numbers "output_lines" .Attributes.output_lines "command_line" .Attributes.command_line)
10-
}}
9+
"line_numbers" .Attributes.line_numbers "output_lines" .Attributes.output_lines "command_line" .Attributes.command_line "line_start" .Attributes.line_start)
10+
}}

themes/arm-design-system-hugo-theme/layouts/partials/general-formatting/prismjs-codeblock.html

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
code Str: echo('Hello world')....
1515
language Str: python
1616
line_numbers Bool: true or false
17+
line_start Str: 123
1718
output_lines Str: 5 or 1-4, 9
1819
command_line Str: "root@localhost"
1920
*/}}
@@ -42,14 +43,24 @@
4243
{{$output_present = true}}
4344
{{end}}
4445

45-
4646
<!-- Start with the 'pre' element, then 'code' element, then the code content -->
4747
<pre
48-
{{if .command_line}}
49-
class="command-line"
50-
data-user= {{ trim (index (split (index (split .command_line "|") 0) "@") 0 ) " "}}
51-
data-host= {{ trim (index (split (index (split .command_line "|") 0) "@") 1 ) " "}}
52-
data-output={{ trim (index (split .command_line "|") 1) " "}}
48+
{{if or (.command_line) (.line_start)}}
49+
{{if and (.command_line) (.line_start)}}
50+
class="command-line line-numbers"
51+
{{else if .command_line}}
52+
class="command-line"
53+
{{else if .line_start}}
54+
class="line-numbers"
55+
{{end}}
56+
{{if .command_line}}
57+
data-user= {{ trim (index (split (index (split .command_line "|") 0) "@") 0 ) " "}}
58+
data-host= {{ trim (index (split (index (split .command_line "|") 0) "@") 1 ) " "}}
59+
data-output={{ trim (index (split .command_line "|") 1) " "}}
60+
{{end}}
61+
{{if .line_start}}
62+
data-start="{{.line_start}}"
63+
{{end}}
5364
{{end}}
5465
>
5566
<code class='language-{{.language}}

themes/arm-design-system-hugo-theme/layouts/shortcodes/tab.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
{{ else }}
2828
{{ with $.Get "language" }} {{ $tab = merge $tab (dict "language" ($.Get "language")) }} {{ end }}
2929
{{ with $.Get "line_numbers" }} {{ $tab = merge $tab (dict "line_numbers" ($.Get "line_numbers")) }} {{ end }}
30+
{{ with $.Get "line_start" }} {{ $tab = merge $tab (dict "line_start" ($.Get "line_start")) }} {{ end }}
3031
{{ with $.Get "output_lines" }} {{ $tab = merge $tab (dict "output_lines" ($.Get "output_lines")) }} {{ end }}
3132
{{ with $.Get "command_line" }} {{ $tab = merge $tab (dict "command_line" ($.Get "command_line")) }} {{ end }}
3233
{{ with $.Inner }}

themes/arm-design-system-hugo-theme/layouts/shortcodes/tabpane.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
"code" $element.content
2424
"language" $element.language
2525
"line_numbers" $element.line_numbers
26+
"line_start" $element.line_start
2627
"output_lines" $element.output_lines
2728
"command_line" $element.command_line) }}
2829
{{- end -}}

0 commit comments

Comments
 (0)