blowfish
This commit is contained in:
parent
bfbe0de3c6
commit
30c2170ae7
1369 changed files with 92622 additions and 16 deletions
27
themes/blowfish/layouts/shortcodes/codeimporter.html
Normal file
27
themes/blowfish/layouts/shortcodes/codeimporter.html
Normal file
|
@ -0,0 +1,27 @@
|
|||
{{ $url := .Get "url" }}
|
||||
{{ $type := .Get "type" }}
|
||||
{{ $startLine := .Get "startLine" | default 1 | int }}
|
||||
{{ $startLine = sub $startLine 1 }}
|
||||
{{ $endLine := .Get "endLine" | default -1 | int }}
|
||||
{{ $selectedLines := slice }}
|
||||
{{ with resources.GetRemote (urls.Parse $url) }}
|
||||
{{ $lines := split .Content "\n" }}
|
||||
{{ $totalLine := $lines | len }}
|
||||
|
||||
{{ if ne $endLine -1 }}
|
||||
{{ $endLine = math.Min $endLine $totalLine }}
|
||||
{{ else }}
|
||||
{{ $endLine = $totalLine }}
|
||||
{{ end }}
|
||||
|
||||
{{ if gt $startLine $endLine }}
|
||||
{{ errorf "Code Importer Shortcode - startLine is greater than endLine" . }}
|
||||
{{ end }}
|
||||
|
||||
{{ $selectedLines := first $endLine $lines }}
|
||||
{{ $selectedLines = after $startLine $selectedLines }}
|
||||
{{ $codeBlock := printf "```%s\n%s\n```" $type (delimit $selectedLines "\n") }}
|
||||
{{ $codeBlock | markdownify }}
|
||||
{{ else }}
|
||||
{{ errorf "Code Importer Shortcode - Unable to get remote resource" . }}
|
||||
{{ end }}
|
Loading…
Add table
Add a link
Reference in a new issue