Skip to content

Commit

Permalink
fix: math passthrough
Browse files Browse the repository at this point in the history
Closes #1434
  • Loading branch information
HEIGE-PCloud committed Feb 16, 2025
1 parent 404fcfc commit 8d7e8d1
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 10 deletions.
2 changes: 1 addition & 1 deletion exampleSite/config/_default/markup.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
# 是否在文档中直接使用 HTML 标签
unsafe = true
[goldmark.extensions.passthrough]
enable = false
enable = true
[goldmark.extensions.passthrough.delimiters]
block = [['\[', '\]'], ['$$', '$$']]
inline = [['\(', '\)']]
Expand Down
6 changes: 3 additions & 3 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

24 changes: 18 additions & 6 deletions layouts/_default/_markup/render-passthrough.html
Original file line number Diff line number Diff line change
@@ -1,8 +1,20 @@
{{- $params := .Page.Scratch.Get "params" -}}
{{- $blockLeftDelimiter := $params.math.blockLeftDelimiter | default "\\[" -}}
{{- $blockRightDelimiter := $params.math.blockRightDelimiter | default "\\]" -}}
{{- $inlineLeftDelimiter := $params.math.inlineLeftDelimiter | default "\\(" -}}
{{- $inlineRightDelimiter := $params.math.inlineRightDelimiter | default "\\)" -}}
{{- .Page.Scratch.Set "enableMath" true -}}
{{- if eq .Type "block" -}}
{{- $opts := dict "displayMode" true "output" "html" -}}
{{- transform.ToMath .Inner $opts -}}
{{- else -}}
{{- $opts := dict "displayMode" false "output" "html" -}}
{{- transform.ToMath .Inner $opts -}}
{{- $opts := dict "output" "htmlAndMathml" "displayMode" (eq $.Type "block") }}
{{- with try (transform.ToMath .Inner $opts) }}
{{- with .Err }}
{{/* {{ warnf "Unable to render mathematical markup to HTML using the transform.ToMath function. The KaTeX display engine threw the following error: %s: see %s." . $.Position }} */}}
{{/* Fallback to client side rendering. Mainly for mhchem support. */}}
{{- if eq $.Type "block" -}}
{{- $blockLeftDelimiter -}}{{- $.Inner -}}{{- $blockRightDelimiter -}}
{{- else -}}
{{- $inlineLeftDelimiter -}}{{- $.Inner -}}{{- $inlineRightDelimiter -}}
{{- end -}}
{{- else }}
{{- .Value }}
{{- end }}
{{- end -}}

0 comments on commit 8d7e8d1

Please sign in to comment.