2024-06-26 21:44:28 +02:00
|
|
|
{{ $url := .Get "url" }}
|
|
|
|
{{ $type := .Get "type" }}
|
2024-07-15 22:27:55 +02:00
|
|
|
{{ $startLine := .Get "startLine" | default 1 | int }}
|
|
|
|
{{ $startLine = sub $startLine 1 }}
|
|
|
|
{{ $endLine := .Get "endLine" | default -1 | int }}
|
|
|
|
{{ $selectedLines := slice }}
|
2024-06-26 21:44:28 +02:00
|
|
|
{{ with resources.GetRemote (urls.Parse $url) }}
|
2024-07-15 22:27:55 +02:00
|
|
|
{{ $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 }}
|
2024-06-26 21:44:28 +02:00
|
|
|
{{ else }}
|
2024-07-15 22:27:55 +02:00
|
|
|
{{ errorf "Code Importer Shortcode - Unable to get remote resource" . }}
|
2024-06-26 21:44:28 +02:00
|
|
|
{{ end }}
|