mirror of
https://github.com/hugo-fixit/FixIt.git
synced 2026-08-24 15:28:57 +00:00
93478b47e1
* feat: optimize code highlighting for diff language * refactor: update codeblock configuration and enhance code wrapper functionality * fix: extra blank lines would appear when copying lines containing code highlighting * refactor: enhance code block wrapper functionality and add new styles (mac style) * refactor: enhance code block normal mode * feat: do noting for code block simple mode * feat: add copy btn for code block modes mac and simple * refactor: add code-related variables and update styles for code blocks and gist layout * feat: update code copy button visibility on hover for larger screens * feat: update code block mode attribute and remove mac wrapper * feat!: code block parameters accurate to a single Remove the `data-open` attribute and use `.open` instead. * refactor: enhance initCopyCode method to accept optional button parameter * feat: improve code/diagram copy button styles and transitions for better visibility * fix: disable copy buttons for simple/mac mode code blocks when copyable set to false * chore: rename normal partial to code-header * feat: add preview and expand feature for code blocks (close #312) * fix: adjust transition timing for code header and fade-out animation * test: update code block test case * docs: update comments for code highlight and markup configurations * feat: adjust code header background color darkening for light and dark themes * fix: hide aside and breadcrumb pseudo-elements on small screens * perf: change the code copy button and code expand button to server-side rendering * fix: the code expand button obscured the code content * fix: update code background and header colors for improved visibility * fix: ensure code copy button is only added for copyable code blocks * feat(code block): add lineNosToggler and lineWrapToggler params and feature for code blocks * refactor: code syntax highlighting styles * fix: update background color for line numbers and ensure proper sticky effect * feat(code block): add support for code file names in code blocks * fix: code review for PR #665 * feat(i18n): add Japanese and Korean translations; update toggle options in multiple languages * docs: update configurations and comments
46 lines
2.8 KiB
HTML
46 lines
2.8 KiB
HTML
{{- /* Code header for classic mode code blocks */ -}}
|
|
{{- $config := .Config -}}
|
|
{{- $wrapper := .Wrapper -}}
|
|
{{- $type := lower .Type | default "fallback" -}}
|
|
{{- $name := $config.name -}}
|
|
{{- $lineNosBtn := "" -}}
|
|
{{- $lineWrapBtn := "" -}}
|
|
{{- $editBtn := "" -}}
|
|
{{- $copyBtn := "" -}}
|
|
{{- $foldIcon := dict "Class" "arrow fa-solid fa-chevron-down fa-fw" | partial "plugin/icon.html" -}}
|
|
{{- $titleEl := printf `<span class="code-title">%s</span>` $foldIcon -}}
|
|
{{- $ellipsisBtn := printf `<span class="ellipses-btn" aria-label="Show more options" role="button">%s</span>` (dict "Class" "fa-solid fa-ellipsis-h fa-fw" | partial "plugin/icon.html") -}}
|
|
|
|
{{- if $config.title -}}
|
|
{{- $titleEl = printf `<span class="code-title">%s<span class="title-inner">%s</span></span>` $foldIcon $config.title -}}
|
|
{{- end -}}
|
|
{{- if $config.linenostoggler -}}
|
|
{{- $lineNosIcon := dict "Class" "fa-solid fa-list-ol fa-fw" | partial "plugin/icon.html" -}}
|
|
{{- $lineNosBtn = printf `<span class="line-nos-btn" aria-label="%s" role="button" title="%s">%s</span>` (T "assets.toggleLineNumbers") (T "assets.toggleLineNumbers") $lineNosIcon -}}
|
|
{{- end -}}
|
|
{{- if $config.linewraptoggler -}}
|
|
{{- $lineWrapIcon := dict "Class" "fa-solid fa-right-left fa-fw" | partial "plugin/icon.html" -}}
|
|
{{- $lineWrapBtn = printf `<span class="line-wrap-btn" aria-label="%s" role="button" title="%s">%s</span>` (T "assets.toggleLineWrap") (T "assets.toggleLineWrap") $lineWrapIcon -}}
|
|
{{- end -}}
|
|
{{- if $config.editable -}}
|
|
{{- $editIcon := dict "Class" "fa-solid fa-pen-to-square fa-fw" | partial "plugin/icon.html" -}}
|
|
{{- $editBtn = printf `<span class="edit-btn" aria-label="%s" role="button" title="%s">%s</span>` (T "assets.toggleCodeEditable") (T "assets.toggleCodeEditable") $editIcon -}}
|
|
{{- end -}}
|
|
{{- if $config.copyable -}}
|
|
{{- $copyIcon := dict "Class" "fa-regular fa-clone fa-fw" | partial "plugin/icon.html" -}}
|
|
{{- $copyBtn = printf `<span class="copy-btn" aria-label="%s" role="button" title="%s">%s</span>` (T "assets.copyToClipboard") (T "assets.copyToClipboard") $copyIcon -}}
|
|
{{- end -}}
|
|
{{- with $config.name -}}
|
|
{{- $titleEl = replace $titleEl `<span class="code-title">` (printf `<span class="code-title" data-name="%s">` .) -}}
|
|
{{- end -}}
|
|
{{- $codeHeader := printf `<div class="code-header language-%s">%s%s%s%s%s%s</div>` $type $titleEl $ellipsisBtn $lineNosBtn $lineWrapBtn $editBtn $copyBtn -}}
|
|
|
|
{{- if strings.Contains $wrapper `<table class="lntable">` -}}
|
|
{{- $wrapper = replaceRE `(<table class="lntable">)` (printf "%s$1" $codeHeader) $wrapper -}}
|
|
{{- else -}}
|
|
{{- /* linenos=false or lineNumbersInTable=false */ -}}
|
|
{{- $wrapper = replaceRE `(<pre[^>]*class="[^"]*chroma[^"]*">[\s\S]*?<\/pre>)` (printf `%s<div class="table-wrapper">$1</div>` $codeHeader) $wrapper -}}
|
|
{{- end -}}
|
|
|
|
{{- return $wrapper -}}
|