mirror of
https://github.com/nunocoracao/blowfish.git
synced 2025-01-22 14:35:43 -06:00
feat: add startLine and endLine support for codeimporter
This commit is contained in:
parent
efba32b076
commit
2b001f0761
1 changed files with 23 additions and 4 deletions
|
@ -1,8 +1,27 @@
|
|||
{{ $url := .Get "url" }}
|
||||
{{ $type := .Get "type" }}
|
||||
{{ with resources.GetRemote (urls.Parse $url) }}
|
||||
{{ $codeBlock := printf "```%s\n%s\n```" $type .Content }}
|
||||
{{ $codeBlock | markdownify }}
|
||||
{{ $startLine := .Get "startLine" | default 1 | int }}
|
||||
{{ $startLine = sub $startLine 1 }}
|
||||
{{ $endLine := .Get "endLine" | default -1 | int }}
|
||||
{{ $selectedLines := slice }}
|
||||
{{ with resources.GetRemote ( printf $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" . }}
|
||||
{{ errorf "Code Importer Shortcode - Unable to get remote resource" . }}
|
||||
{{ end }}
|
||||
|
|
Loading…
Reference in a new issue