diff --git a/layouts/_partials/feed/rss.html b/layouts/_partials/feed/rss.html index 7e9bb4dd..3a3de18f 100644 --- a/layouts/_partials/feed/rss.html +++ b/layouts/_partials/feed/rss.html @@ -55,36 +55,7 @@ {{- end }} {{- if $fullText }} - {{- $content := dict "Content" .Content "Ruby" $params.ruby "Fraction" $params.fraction "Fontawesome" $params.fontawesome | partial "function/content.html" }} - {{- /* {{- $content | replaceRE `]*>.*` "" | replaceRE `]*( /)?>` "" | safeHTML -}} */ -}} - {{- /* Keep only the code content: remove highlight/chroma/lntable wrapper and line numbers */ -}} - {{- $content = $content | replaceRE `(?s)]*class="highlight"[^>]*>.*?]*class="chroma"[^>]*>.*?]*class="lntable"[^>]*>.*?(?:]*>\s*)?]*>\s*]*class="lntd"[^>]*>.*?\s*]*class="lntd"[^>]*>(.*?)\s*\s*(?:\s*)?.*?.*?\s*` "$1" | safeHTML }} - {{- /* Keep only the first
...
inside a diagram-container */ -}} - {{- $content = $content | replaceRE `(?s)]*class="diagram-container"[^>]*>.*?(]*class="mermaid"[^>]*>.*?).*?\s*(?:]*>.*?\s*)?` "$1" | safeHTML }} - {{- /* Remove echarts diagram containers entirely */ -}} - {{- $content = $content | replaceRE `(?s)]*class="diagram-container"[^>]*>.*?]*class="echarts"[^>]*>.*?\s*(?:]*>.*?\s*)?.*?` "" | safeHTML }} - {{- /* Replace json-viewer components with JSON code blocks */ -}} - {{- $matches := findRE `(?s)]*\bvalue="[^"]*"[^>]*>(?:)?` $content -}} - {{- if gt (len $matches) 0 -}} - {{- range $i, $m := $matches -}} - {{- /* extract the value="...": use replaceRE on the full match to get the captured group */ -}} - {{- $rawVal := $m | replaceRE `(?s).*value="([^"]*)".*` "$1" -}} - {{- /* decode HTML entities, strip outer quotes if present, unescape JSON-style escapes */ -}} - {{- $jsonStr := $rawVal | htmlUnescape | replaceRE `^"(.*)"$` "$1" | replaceRE `\\\\` `\` | replaceRE `\\\"` `"` | replaceRE `\\n` "\n" | replaceRE `\\r` "" | replaceRE `\\t` "\t" -}} - {{- /* try to unmarshal into object */ -}} - {{- $obj := transform.Unmarshal $jsonStr | default dict -}} - {{- /* serialize back to JSON */ -}} - {{- $pretty := $obj | jsonify (dict "indent" " ") -}} - {{- /* build replacement pre/code block */ -}} - {{- $replacement := printf "
%s
" $pretty -}} - {{- /* replace the full original match with the rendered block */ -}} - {{- $content = replace $content $m $replacement -}} - {{- end -}} - {{- end -}} - {{- with $image }} - {{- $content = add (printf "%q" . "featured image" "no-referrer") $content | safeHTML }} - {{- end }} - {{- $content | transform.XMLEscape | safeHTML -}} + {{- dict "Content" .Content "Ruby" $params.ruby "Fraction" $params.fraction "Fontawesome" $params.fontawesome "FeaturedImage" $image | partial "function/xml-content.html" -}}
{{- else }} {{ (.Summary | default .Description | default .Title) | transform.XMLEscape | safeHTML }} diff --git a/layouts/_partials/function/xml-content.html b/layouts/_partials/function/xml-content.html new file mode 100644 index 00000000..0c7c213f --- /dev/null +++ b/layouts/_partials/function/xml-content.html @@ -0,0 +1,70 @@ +{{- $content := .Content -}} + +{{- if $content -}} + + {{- $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)]*class="highlight"[^>]*>.*?]*class="chroma"[^>]*>.*?]*class="lntable"[^>]*>.*?(?:]*>\s*)?]*>\s*]*class="lntd"[^>]*>.*?\s*]*class="lntd"[^>]*>(.*?)\s*\s*(?:\s*)?.*?.*?\s*` "$1" -}} + {{- $codeBlocks := findRE `(?s)]*>.*?` $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
...
inside a diagram-container */ -}} + {{- $content = $content | replaceRE `(?s)]*class="diagram-container"[^>]*>.*?(]*class="mermaid"[^>]*>.*?).*?\s*(?:]*>.*?\s*)?` "$1" }} + {{- $mermaidMatches := findRE `(?s)]*class="mermaid"[^>]*>.*?` $content -}} + {{- if gt (len $mermaidMatches) 0 -}} + {{- range $i, $m := $mermaidMatches -}} + {{- $attrs := $m | replaceRE `(?s)]*)>.*?` "$1" -}} + {{- $inner := $m | replaceRE `(?s)]*>(.*?)` "$1" -}} + {{- $inner = replace $inner " " " " -}} + {{- $newPre := printf "%s" $attrs $inner -}} + {{- $content = replace $content $m $newPre -}} + {{- end -}} + {{- end -}} + + {{- /* Remove echarts diagram containers entirely */ -}} + {{- $content = $content | replaceRE `(?s)]*class="diagram-container"[^>]*>.*?]*class="echarts"[^>]*>.*?\s*(?:]*>.*?\s*)?.*?` "" -}} + + {{- /* Replace json-viewer components with JSON code blocks */ -}} + {{- $matches := findRE `(?s)]*\bvalue="[^"]*"[^>]*>(?:)?` $content -}} + {{- if gt (len $matches) 0 -}} + {{- range $i, $m := $matches -}} + {{- /* extract the value="...": use replaceRE on the full match to get the captured group */ -}} + {{- $rawVal := $m | replaceRE `(?s).*value="([^"]*)".*` "$1" -}} + {{- /* decode HTML entities, strip outer quotes if present, unescape JSON-style escapes */ -}} + {{- $jsonStr := $rawVal | htmlUnescape | replaceRE `^"(.*)"$` "$1" | replaceRE `\\\\` `\` | replaceRE `\\\"` `"` | replaceRE `\\n` "\n" | replaceRE `\\r` "" | replaceRE `\\t` "\t" -}} + {{- /* try to unmarshal into object */ -}} + {{- $obj := transform.Unmarshal $jsonStr | default dict -}} + {{- /* serialize back to JSON */ -}} + {{- $pretty := $obj | jsonify (dict "indent" "  ") -}} + {{- /* build replacement pre/code block */ -}} + {{- $replacement := printf "
%s
" $pretty -}} + {{- /* replace the full original match with the rendered block */ -}} + {{- $content = replace $content $m $replacement -}} + {{- end -}} + {{- end -}} + + {{- with .FeaturedImage }} + {{- $content = add (printf "%q" . "featured image" "no-referrer") $content }} + {{- end }} + + {{- $content = $content | transform.XMLEscape | safeHTML -}} + +{{- end }} + + +{{- return $content -}} diff --git a/layouts/_partials/init/index.html b/layouts/_partials/init/index.html index 90179c97..0b75dfae 100644 --- a/layouts/_partials/init/index.html +++ b/layouts/_partials/init/index.html @@ -1,4 +1,4 @@ -{{- hugo.Store.Set "version" "v0.4.0-alpha.2-20251022123721-f984fc6d" -}} +{{- hugo.Store.Set "version" "v0.4.0-alpha.2-20251023040336-063af2cd" -}} {{- .Store.Set "this" dict -}} {{- partial "init/detection-env.html" . -}}