mirror of
https://github.com/hugo-fixit/FixIt.git
synced 2026-08-24 23:38:56 +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
66 lines
2.4 KiB
HTML
66 lines
2.4 KiB
HTML
{{- $config := .Attributes | merge (.Page.Param "codeblock") -}}
|
|
{{- $result := transform.HighlightCodeBlock . -}}
|
|
{{- $wrapper := $result.Wrapped -}}
|
|
|
|
{{- if $config.wrapper -}}
|
|
{{- $mode := $config.mode | default "classic" -}}
|
|
{{- $class := "highlight" -}}
|
|
{{- with $config.class -}}{{ $class = add $class " " . }}{{- end -}}
|
|
{{- $targetClass := add "code-block " $class -}}
|
|
{{- with $config.wrapperclass -}}{{ $targetClass = add $targetClass " " . }}{{- end -}}
|
|
|
|
{{- /* add code expand button */ -}}
|
|
{{- $lines := cond .Inner (len (split .Inner "\n")) 0 -}}
|
|
{{- $maxShownLines := $config.maxshownlines -}}
|
|
{{- if (gt $lines $maxShownLines) | and (gt $lines 0) | and (gt $maxShownLines 0) -}}
|
|
{{- $wrapper = dict "Wrapper" $wrapper | partial "function/code-expand-btn.html" -}}
|
|
{{- end -}}
|
|
|
|
{{- /* render for different modes */ -}}
|
|
{{- if eq $mode "classic" -}}
|
|
{{- $wrapper = dict "Wrapper" $wrapper "Config" $config "Type" .Type | partial "function/code-header.html" -}}
|
|
{{- if eq .Options.linenos false -}}
|
|
{{- $targetClass = add $targetClass " line-nos-hidden" -}}
|
|
{{- end -}}
|
|
{{- else -}}
|
|
{{- $wrapper = dict "Wrapper" $wrapper "Config" $config | partial "function/code-copy-btn.html" -}}
|
|
{{- end -}}
|
|
|
|
{{- /* add data attributes and class */ -}}
|
|
{{- if $config.editable -}}
|
|
{{- $wrapper =
|
|
replace $wrapper
|
|
(printf `class="%s"` $class)
|
|
(printf `class="%s" data-editable="%v"` $class $config.editable)
|
|
-}}
|
|
{{- end -}}
|
|
{{- if $config.copyable -}}
|
|
{{- $wrapper =
|
|
replace $wrapper
|
|
(printf `class="%s"` $class)
|
|
(printf `class="%s" data-copyable="%v"` $class $config.copyable)
|
|
-}}
|
|
{{- end -}}
|
|
{{- if ne .Options.linenostart nil -}}
|
|
{{- $wrapper =
|
|
replace $wrapper
|
|
(printf `class="%s"` $class)
|
|
(printf `class="%s" data-linenostart="%v"` $class .Options.linenostart)
|
|
-}}
|
|
{{- end -}}
|
|
{{- $wrapper =
|
|
replace $wrapper
|
|
(printf `class="%s"` $class)
|
|
(printf `class="%s" data-mode="%s" data-max="%v" data-lines="%d"` $targetClass $mode $maxShownLines $lines)
|
|
-}}
|
|
|
|
{{- /* remove redundant attributes */ -}}
|
|
{{- $configKeys := slice -}}
|
|
{{- range $key, $_ := .Page.Param "codeblock" -}}
|
|
{{- $configKeys = $configKeys | append $key -}}
|
|
{{- end -}}
|
|
{{- $wrapper = replaceRE (printf `\s+(?:%s|name)="[^"]*"` (delimit $configKeys "|")) "" $wrapper -}}
|
|
{{- end -}}
|
|
|
|
{{- $wrapper | safeHTML -}}
|