mirror of
https://github.com/gohugoio/hugo.git
synced 2026-09-04 04:32:37 +00:00
b3d87dd0fd
b654fcba0content: Fix linksd44357418content: Update GitLab Pages workflow example33968c7e2content: Update Netlify configuration filea6d0c8c50content: Update GitHub Pages workflow exampled1aabfa36content: Fix broken link7b50139a6content: Miscellaneous editsa30e2c189Menus: add forgotten link target5c2aa88b4content: Updates for v0.146.7114413c18netlify: Hugo 0.146.767e9261b1netlify: Hugo 0.146.6efa040229content: Update templates/embedded.mdb8f888c76theme: Rename internal templates from partials/ to _partials/727178cbbcontent: Fix broken anchor links0f12708f1Fix typo380b1c163Update Current.md8b500f3e5netlify: Hugo 0.146.5e3d6b6fadnetlify: Hugo 0.146.4ac1b92713content: Fix text formatting in templates/partial.md719329530content: Clarify usage of template functiona95eca524theme: Misc adjustments for the themes site8e6c26067Add package.hugo.json9691007fbnetlify: Hugo 0.146.3ec08acc59netlify: Hugo 0.146.28f320a0b6netlify: Hugo 0.146.1d5e6cb618content: Remove expired new-in badgesb5779d7fccontent: Update templates.Current function5df1229d5theme: Move templates to new structurea7a6a614dtheme: Remove accidentally added template195b368e8content: Miscellaneous updates related to v0.146.00a906ad49netlify: Hugo 0.146.0 git-subtree-dir: docs git-subtree-split:b654fcba0d
99 lines
2.8 KiB
HTML
99 lines
2.8 KiB
HTML
{{/* prettier-ignore-start */}}
|
|
{{/*
|
|
Renders a highlighted code block using the given options and attributes.
|
|
|
|
In addition to the options available to the transform.Highlight function, you
|
|
may also specify the following parameters:
|
|
|
|
@param {bool} [copy=false] Whether to display a copy-to-clipboard button.
|
|
@param {string} [file] The file name to display above the rendered code.
|
|
@param {bool} [details=false] Whether to wrap the highlighted code block within a details element.
|
|
@param {bool} [open=false] Whether to initially display the content of the details element.
|
|
@param {string} [summary=Details] The content of the details summary element rendered from Markdown to HTML.
|
|
|
|
@returns {template.HTML}
|
|
|
|
@examples
|
|
|
|
```go
|
|
fmt.Println("Hello world!")
|
|
```
|
|
|
|
```go {linenos=true file="layouts/index.html" copy=true}
|
|
fmt.Println("Hello world!")
|
|
```
|
|
*/}}
|
|
{{/* prettier-ignore-end */}}
|
|
|
|
{{- $copy := false }}
|
|
{{- $file := or .Attributes.file "" }}
|
|
{{- $details := false }}
|
|
{{- $open := "" }}
|
|
{{- $summary := or .Attributes.summary "Details" | .Page.RenderString }}
|
|
{{- $ext := strings.TrimPrefix "." (path.Ext $file) }}
|
|
{{- $lang := or .Type $ext "text" }}
|
|
{{- if in (slice "html" "gotmpl") $lang }}
|
|
{{- $lang = "go-html-template" }}
|
|
{{- end }}
|
|
{{- if eq $lang "md" }}
|
|
{{- $lang = "text" }}
|
|
{{- end }}
|
|
|
|
{{- with .Attributes.copy }}
|
|
{{- if in (slice true "true" 1) . }}
|
|
{{- $copy = true }}
|
|
{{- else if in (slice false "false" 0) . }}
|
|
{{- $copy = false }}
|
|
{{- end }}
|
|
{{- end }}
|
|
|
|
{{- with .Attributes.details }}
|
|
{{- if in (slice true "true" 1) . }}
|
|
{{- $details = true }}
|
|
{{- else if in (slice false "false" 0) . }}
|
|
{{- $details = false }}
|
|
{{- end }}
|
|
{{- end }}
|
|
|
|
{{- with .Attributes.open }}
|
|
{{- if in (slice true "true" 1) . }}
|
|
{{- $open = "open" }}
|
|
{{- else if in (slice false "false" 0) . }}
|
|
{{- $open = "" }}
|
|
{{- end }}
|
|
{{- end }}
|
|
|
|
{{- if $details }}
|
|
<details class="cursor-pointer" {{ $open }}>
|
|
<summary>{{ $summary }}</summary>
|
|
{{- end }}
|
|
|
|
<div
|
|
x-data
|
|
class="render-hook-codeblock font-mono not-prose relative mt-6 mb-8 border-1 border-gray-200 dark:border-gray-800 bg-light dark:bg-dark">
|
|
{{- $fileSelectClass := "select-none" }}
|
|
{{- if $copy }}
|
|
{{- $fileSelectClass = "select-text" }}
|
|
<svg
|
|
class="absolute right-4 top-2 z-30 text-blue-600 hover:text-blue-500 dark:text-gray-400 dark:hover:text-gray-300 cursor-pointer w-6 h-6"
|
|
@click="$copy($refs.code)">
|
|
<use href="#icon--copy"></use>
|
|
</svg>
|
|
{{- end }}
|
|
{{- with $file }}
|
|
<div
|
|
class="san-serif text-sm inline-block leading-none pl-2 py-3 bg-gray-300 dark:bg-slate-700 w-full {{ $fileSelectClass }}
|
|
">
|
|
{{ . }}
|
|
</div>
|
|
{{- end }}
|
|
|
|
<div x-ref="code">
|
|
{{- transform.Highlight (strings.TrimSpace .Inner) $lang .Options }}
|
|
</div>
|
|
</div>
|
|
|
|
{{- if $details }}
|
|
</details>
|
|
{{- end }}
|