Files
FixIt/layouts/_partials/plugin/code-block-wrapper.html
T
Cell 8af8e806d7 feat(assets): integrate UnoCSS for utility classes and presetIcons (#795)
* refactor(assets): integrate UnoCSS for utility classes

- Add UnoCSS with presetWind3 as pre-built CSS (assets/css/unocss.css)
- Add uno.config.ts with theme breakpoints, colors, safelist, and blocklist
- Replace SCSS utility classes with UnoCSS atomic classes:
  - d-none → hidden
  - d-none-desktop → sm:hidden
  - d-none-mobile → max-sm:hidden
  - order-* (safelist)
  - variant-numeric → tabular-nums lining-nums
- Rename .blur to .is-blur to avoid UnoCSS conflict
- Add @unocss-skip comments for SVG path elements to prevent false positives
- Remove redundant _utilities.scss ($orders map) and simplify _common.scss
- Update documentation (CLAUDE.md, CONTRIBUTING.md, copilot-instructions.md)

* refactor(assets): replace 404/offline SCSS with UnoCSS atomic classes

- Replace _404.scss styles with atomic classes on template elements
- Replace _offline.scss styles with atomic classes on template elements
- Keep selectors (id/class) as user customization hooks
- Delete assets/scss/pages/_404.scss and _offline.scss

* refactor(assets): simplify SCSS with UnoCSS atomic classes

- Replace _bilibili.scss with atomic classes (relative, aspect-video, inset-0)
- Replace _version.scss with atomic classes (whitespace-nowrap, align-text-bottom)
- Replace _noscript-warning.scss with atomic classes (bg-danger, fixed, z-200)
- Add semantic z-index shortcuts (z-hide, z-auto, z-base, z-loading, z-sticky, z-fixed)
- Add h1-h6 to UnoCSS blocklist to prevent false positives
- Use Source path for UnoCSS CSS loading to enable Hugo minify

* chore(assets): minor SCSS and template cleanup

* fix(assets): add secondary color to UnoCSS theme config

text-secondary was broken because the secondary color mapping was missing.

* feat(assets): add UnoCSS presetIcons support and z-index shortcuts

- Add presetIcons preset with empty collections (ready for custom icon sets)
- Add @iconify/json and @iconify/utils devDependencies
- Add semantic z-index shortcuts (z-hide, z-auto, z-base, z-loading, z-sticky, z-fixed)
- Add secondary color to UnoCSS theme config

* refactor(assets): replace SVG icons with UnoCSS presetIcons

- Add Lucide and Octicons icon collections to presetIcons config
- Replace arrow-up/down and enter-key SVGs with Lucide icons
- Replace alert icons (info, light-bulb, report, alert, stop) with Octicons
- Delete replaced SVG files from assets/images/icons/
- Keep custom SVGs (csdn, plume, rootme)

* refactor(layouts): redesign 404 and offline pages with UnoCSS

- Replace translate-y-[30vh] with self-stretch flex centering below header
- Remove arbitrary values (text-[3.6rem], text-[1.8rem], etc.)
- Restore @page print styles in _common.scss
- Simplify offline page layout (icon + title + text)
- Fix hardcoded #57606a → text-secondary
2026-06-27 06:27:12 +08:00

123 lines
4.6 KiB
HTML

{{- /*
Code block wrapper hook for highlight output.
- Applies wrapper UI features based on codeblock config.
- Supports classic/modern modes, copy button, expand button, and line-number states.
@param {Object} .Attributes code block attributes
@param {Object} .Options code fence options
@param {String} .Inner raw code content
@param {Object} .Page current page context
@param {String} .Type language/type for current block
*/ -}}
{{- $config := .Attributes | merge .Page.Params.codeblock | merge .Page.Site.Params.codeblock -}}
{{- $result := transform.HighlightCodeBlock . -}}
{{- $wrapper := $result.Wrapped -}}
{{- /* If wrapper is enabled, add code wrapper and more features */ -}}
{{- if $config.wrapper -}}
{{- $mode := $config.mode | default "classic" -}}
{{- $lines := cond .Inner (len (split .Inner "\n")) 0 -}}
{{- $maxShownLines := $config.maxshownlines -}}
{{- $lineNoStart := cond (ne .Options.linenostart nil) .Options.linenostart 1 -}}
{{- $lineNosDigit := strings.RuneCount (sub (add $lines $lineNoStart) 1) -}}
{{- $class := "highlight" -}}
{{- with $config.class -}}{{ $class = add $class " " . }}{{- end -}}
{{- $targetClass := add "code-block " $class -}}
{{- with $config.wrapperclass -}}{{ $targetClass = add $targetClass " " . }}{{- end -}}
{{- /* Add code wrapper around the table or pre */ -}}
{{- $REin := cond (strings.Contains $wrapper `<table class="lntable">`)
`(<table class="lntable">[\s\S]*?<\/table>)`
`(<pre tabindex="0" class="chroma">[\s\S]*?<\/pre>)` -}}
{{- $REout := printf `<div class="code-wrapper">$1</div>` -}}
{{- $wrapper = replaceRE $REin $REout $wrapper -}}
{{- /* Hide line numbers if linenos=false */ -}}
{{- if (not (strings.Contains $wrapper `class="lnt"`)) | and (not (strings.Contains $wrapper `class="ln"`)) -}}
{{- $targetClass = add $targetClass " line-nos-hidden" -}}
{{- end -}}
{{- /* Add code expand button */ -}}
{{- 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" -}}
{{- else -}}
{{- $wrapper = dict "Wrapper" $wrapper "Config" $config | partial "function/code-copy-btn.html" -}}
{{- end -}}
{{- /*
Add data attributes and class
Directly set CSS variables to ensure compatibility with non-Chromium-based browsers
See https://caniuse.com/css3-attr for attr() support status
*/ -}}
{{- 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 $config.shadow "never" -}}
{{- $wrapper =
replace $wrapper
(printf `class="%s"` $class)
(printf `class="%s" data-shadow="%s"` $class $config.shadow)
-}}
{{- end -}}
{{- if $config.group -}}
{{- $tabTitle := $config.name | default (strings.FirstUpper .Type) | default "Code" -}}
{{- $groupKey := printf "code-tab-group-first:%s" $config.group -}}
{{- $isFirst := not (.Page.Store.Get $groupKey) -}}
{{- if $isFirst -}}
{{- .Page.Store.Set $groupKey true -}}
{{- else -}}
{{- $targetClass = add $targetClass " hidden" -}}
{{- end -}}
{{- $wrapper =
replace $wrapper
(printf `class="%s"` $class)
(printf `class="%s" data-tab-title="%s"` $class $tabTitle)
-}}
{{- end -}}
{{- if ne .Options.linenostart nil -}}
{{- $wrapper =
replace $wrapper
`class="code-wrapper"`
(printf `class="code-wrapper" data-line-start="%v"` .Options.linenostart)
-}}
{{- end -}}
{{- $wrapperStyle := printf "--fi-max-shown-lines:%v;--fi-line-digit:%v;--fi-line-start:%v;" $maxShownLines $lineNosDigit $lineNoStart -}}
{{- $wrapper =
replace $wrapper
`class="code-wrapper"`
(printf `class="code-wrapper" style="%s"` $wrapperStyle)
-}}
{{- $wrapper =
replace $wrapper
`class="code-wrapper"`
(printf
`class="code-wrapper" data-max="%v" data-line-digit="%d"`
$maxShownLines
$lineNosDigit
)
-}}
{{- $wrapper =
replace $wrapper
(printf `class="%s"` $class)
(printf `class="%s" data-mode="%s"` $targetClass $mode)
-}}
{{- end -}}
{{- $wrapper | safeHTML -}}