Skip to content

Added styling to ghcode shortcode #220

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 15, 2025
Merged
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
17 changes: 16 additions & 1 deletion layouts/shortcodes/ghcode.html
Original file line number Diff line number Diff line change
@@ -1,11 +1,26 @@
{{ $file := .Get 0 }}
{{ $params := .Get 1 }}
{{ $codeBlockId := printf "id-%x" (now.UnixNano) }}
{{ with resources.GetRemote $file }}
{{ with .Err }}
{{ errorf "%s" . }}
{{ else }}
{{ $lang := path.Ext $file | strings.TrimPrefix "." }}
{{ highlight .Content $lang $params }}
<div id="code-block-v1" data-mf="false">
{{ highlight .Content $lang $params }}
</div>

<div class="code-block" data-mf="true" style="display: none;">
{{- if and (ne $lang "") (ne $lang "none") -}}
<span class="code-type chroma">{{ $lang }}</span>
{{- end -}}
<div class="code-container chroma">
<button onclick="copyToClipBoard(this, {{ $codeBlockId }})" class="code-copy-button multi-line" type="button">Copy</button>
<div class="highlight-v2" id="{{ $codeBlockId }}">
{{ highlight .Content $lang $params }}
</div>
</div>
</div>
{{ end }}
{{ else }}
{{ errorf "Unable to load github content from %s from %q" $file .Position}}
Expand Down
Loading