mirror of
https://github.com/hugo-fixit/FixIt.git
synced 2026-08-24 15:28:57 +00:00
feat: add code block render hook for RSS page (#651)
This commit is contained in:
@@ -1168,7 +1168,7 @@ twemoji = false
|
||||
# set to true, images in the content will be shown as the gallery if the image has a title, e.g. 
|
||||
# set to "force", images in the content will be forced to shown as the gallery regardless of the image has a title or not, e.g. 
|
||||
# TODO change gallery engine in the future
|
||||
lightgallery = true
|
||||
lightgallery = false
|
||||
# whether to enable the ruby extended syntax
|
||||
ruby = true
|
||||
# whether to enable the fraction extended syntax
|
||||
|
||||
@@ -0,0 +1,3 @@
|
||||
{{- $result := transform.HighlightCodeBlock . -}}
|
||||
<pre><code>{{ $result.Inner }}</code></pre>
|
||||
{{- /* EOF */ -}}
|
||||
@@ -1,7 +1,7 @@
|
||||
{{- /* Code header for classic mode code blocks */ -}}
|
||||
{{- $config := .Config -}}
|
||||
{{- $wrapper := .Wrapper -}}
|
||||
{{- $type := lower .Type | default "fallback" -}}
|
||||
{{- $lang := cond (transform.CanHighlight .Type) (lower .Type) "fallback" -}}
|
||||
{{- $name := $config.name -}}
|
||||
{{- $lineNosBtn := "" -}}
|
||||
{{- $lineWrapBtn := "" -}}
|
||||
@@ -33,7 +33,7 @@
|
||||
{{- 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 -}}
|
||||
{{- $codeHeader := printf `<div class="code-header language-%s">%s%s%s%s%s%s</div>` $lang $titleEl $ellipsisBtn $lineNosBtn $lineWrapBtn $editBtn $copyBtn -}}
|
||||
{{- $wrapper = replaceRE `(<div class="code-wrapper">)` (printf "%s$1" $codeHeader) $wrapper -}}
|
||||
|
||||
{{- return $wrapper -}}
|
||||
|
||||
@@ -4,25 +4,6 @@
|
||||
|
||||
{{- $content = dict "Content" .Content "Ruby" .Ruby "Fraction" .Fraction "Fontawesome" .Fontawesome | partial "function/content.html" }}
|
||||
|
||||
{{- /* Keep only the code content: remove highlight/chroma/lntable wrapper and line numbers */ -}}
|
||||
{{- $content = $content | replaceRE `(?s)<div[^>]*class="highlight"[^>]*>.*?<div[^>]*class="chroma"[^>]*>.*?<table[^>]*class="lntable"[^>]*>.*?(?:<tbody[^>]*>\s*)?<tr[^>]*>\s*<td[^>]*class="lntd"[^>]*>.*?</td>\s*<td[^>]*class="lntd"[^>]*>(.*?)</td>\s*</tr>\s*(?:</tbody>\s*)?.*?</table>.*?</div>\s*</div>` "$1" -}}
|
||||
{{- $codeBlocks := findRE `(?s)<code[^>]*>.*?</code>` $content -}}
|
||||
{{- if gt (len $codeBlocks) 0 -}}
|
||||
{{- range $i, $block := $codeBlocks -}}
|
||||
{{- $newBlock := $block -}}
|
||||
{{- $textMatches := findRE `>([^<]+)<` $block -}}
|
||||
{{- if gt (len $textMatches) 0 -}}
|
||||
{{- range $j, $m := $textMatches -}}
|
||||
{{- $inner := $m | replaceRE `^>([^<]+)<$` "$1" -}}
|
||||
{{- $newInner := replace $inner " " " " -}}
|
||||
{{- $newMatch := printf ">%s<" $newInner -}}
|
||||
{{- $newBlock = replace $newBlock $m $newMatch -}}
|
||||
{{- end -}}
|
||||
{{- end -}}
|
||||
{{- $content = replace $content $block $newBlock -}}
|
||||
{{- end -}}
|
||||
{{- end -}}
|
||||
|
||||
{{- /* Keep only the first <pre class="mermaid">...</pre> inside a diagram-container */ -}}
|
||||
{{- $content = $content | replaceRE `(?s)<div[^>]*class="diagram-container"[^>]*>.*?(<pre[^>]*class="mermaid"[^>]*>.*?</pre>).*?</div>\s*(?:<template[^>]*>.*?</template>\s*)?` "$1" }}
|
||||
{{- $mermaidMatches := findRE `(?s)<pre[^>]*class="mermaid"[^>]*>.*?</pre>` $content -}}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
{{- hugo.Store.Set "version" "v0.4.0-alpha.3-20251219061028-5dcb107d" -}}
|
||||
{{- hugo.Store.Set "version" "v0.4.0-alpha.3-20251219073856-c35dce56" -}}
|
||||
{{- .Store.Set "this" dict -}}
|
||||
|
||||
{{- partial "init/detection-env.html" . -}}
|
||||
|
||||
Reference in New Issue
Block a user