Merge remote-tracking branch 'origin/dev' into dev
This commit is contained in:
commit
4743cd97f2
2 changed files with 10 additions and 3 deletions
|
@ -1933,7 +1933,8 @@ func processKaTexMacros(n *ast.Node) {
|
|||
mathContent = escapeKaTexSupportedFunctions(mathContent)
|
||||
usedMacros := extractUsedMacros(mathContent, &keys)
|
||||
for _, usedMacro := range usedMacros {
|
||||
expanded := resolveKaTexMacro(usedMacro, ¯os, &keys)
|
||||
depth := 1
|
||||
expanded := resolveKaTexMacro(usedMacro, ¯os, &keys, &depth)
|
||||
expanded = unescapeKaTexSupportedFunctions(expanded)
|
||||
mathContent = strings.ReplaceAll(mathContent, usedMacro, expanded)
|
||||
}
|
||||
|
|
|
@ -908,13 +908,19 @@ func init() {
|
|||
sort.Slice(katexSupportedFunctions, func(i, j int) bool { return len(katexSupportedFunctions[i]) > len(katexSupportedFunctions[j]) })
|
||||
}
|
||||
|
||||
func resolveKaTexMacro(macroName string, macros *map[string]string, keys *[]string) string {
|
||||
func resolveKaTexMacro(macroName string, macros *map[string]string, keys *[]string, depth *int) string {
|
||||
v := (*macros)[macroName]
|
||||
if *depth > 16 {
|
||||
// Limit KaTex macro maximum recursive parsing depth is 16 https://github.com/siyuan-note/siyuan/issues/10484
|
||||
return v
|
||||
}
|
||||
|
||||
sort.Slice(*keys, func(i, j int) bool { return len((*keys)[i]) > len((*keys)[j]) })
|
||||
*depth++
|
||||
for _, k := range *keys {
|
||||
escaped := escapeKaTexSupportedFunctions(v)
|
||||
if strings.Contains(escaped, k) {
|
||||
escaped = strings.ReplaceAll(escaped, k, resolveKaTexMacro(k, macros, keys))
|
||||
escaped = strings.ReplaceAll(escaped, k, resolveKaTexMacro(k, macros, keys, depth))
|
||||
v = unescapeKaTexSupportedFunctions(escaped)
|
||||
(*macros)[macroName] = v
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue