Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -83,12 +83,26 @@ Specify that line_numbers are true in the following way:
\`\`\`bash { line_numbers = "true" } \
echo 'hello world' \
echo ‘I am line two’ \
\`\`\`
\`\`\`
```bash { line_numbers = "true" }
echo ‘hello world’
echo ‘I am line two’
```

In some cases, the line numbering should not start from one but from another
value, e.g. if the code excerpt is extracted from a larger file. Use the
`line_start` attribute to achieve this:

```bash { line_numbers = "true" }
echo ‘hello world’
echo ‘I am line two’
```
\`\`\`bash { line_numbers = "true" line_start = "10" } \
echo 'hello world' \
echo ‘I am line two’ \
\`\`\`

```bash { line_numbers = "true" line_start = "10" }
echo ‘hello world’
echo ‘I am line eleven’
```

### Output Lines

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@
```
*/}}
{{partial "general-formatting/prismjs-codeblock.html" (dict "input_from" "normal" "code" .Inner "language" .Type
"line_numbers" .Attributes.line_numbers "output_lines" .Attributes.output_lines "command_line" .Attributes.command_line)
}}
"line_numbers" .Attributes.line_numbers "output_lines" .Attributes.output_lines "command_line" .Attributes.command_line "line_start" .Attributes.line_start)
}}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
code Str: echo('Hello world')....
language Str: python
line_numbers Bool: true or false
line_start Str: 123
output_lines Str: 5 or 1-4, 9
command_line Str: "root@localhost"
*/}}
Expand Down Expand Up @@ -42,14 +43,24 @@
{{$output_present = true}}
{{end}}


<!-- Start with the 'pre' element, then 'code' element, then the code content -->
<pre
{{if .command_line}}
class="command-line"
data-user= {{ trim (index (split (index (split .command_line "|") 0) "@") 0 ) " "}}
data-host= {{ trim (index (split (index (split .command_line "|") 0) "@") 1 ) " "}}
data-output={{ trim (index (split .command_line "|") 1) " "}}
{{if or (.command_line) (.line_start)}}
{{if and (.command_line) (.line_start)}}
class="command-line line-numbers"
{{else if .command_line}}
class="command-line"
{{else if .line_start}}
class="line-numbers"
{{end}}
{{if .command_line}}
data-user= {{ trim (index (split (index (split .command_line "|") 0) "@") 0 ) " "}}
data-host= {{ trim (index (split (index (split .command_line "|") 0) "@") 1 ) " "}}
data-output={{ trim (index (split .command_line "|") 1) " "}}
{{end}}
{{if .line_start}}
data-start="{{.line_start}}"
{{end}}
{{end}}
>
<code class='language-{{.language}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
{{ else }}
{{ with $.Get "language" }} {{ $tab = merge $tab (dict "language" ($.Get "language")) }} {{ end }}
{{ with $.Get "line_numbers" }} {{ $tab = merge $tab (dict "line_numbers" ($.Get "line_numbers")) }} {{ end }}
{{ with $.Get "line_start" }} {{ $tab = merge $tab (dict "line_start" ($.Get "line_start")) }} {{ end }}
{{ with $.Get "output_lines" }} {{ $tab = merge $tab (dict "output_lines" ($.Get "output_lines")) }} {{ end }}
{{ with $.Get "command_line" }} {{ $tab = merge $tab (dict "command_line" ($.Get "command_line")) }} {{ end }}
{{ with $.Inner }}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
"code" $element.content
"language" $element.language
"line_numbers" $element.line_numbers
"line_start" $element.line_start
"output_lines" $element.output_lines
"command_line" $element.command_line) }}
{{- end -}}
Expand Down