mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-05-19 02:21:38 +08:00
Merge remote-tracking branch 'origin/dev' into dev
This commit is contained in:
commit
12792471b3
2
app/stage/protyle/js/lute/lute.min.js
vendored
2
app/stage/protyle/js/lute/lute.min.js
vendored
File diff suppressed because one or more lines are too long
@ -8,7 +8,7 @@ require (
|
|||||||
github.com/88250/epub v0.0.0-20230830085737-c19055cd1f48
|
github.com/88250/epub v0.0.0-20230830085737-c19055cd1f48
|
||||||
github.com/88250/go-humanize v0.0.0-20240424102817-4f78fac47ea7
|
github.com/88250/go-humanize v0.0.0-20240424102817-4f78fac47ea7
|
||||||
github.com/88250/gulu v1.2.3-0.20240505150113-bc43bd50f866
|
github.com/88250/gulu v1.2.3-0.20240505150113-bc43bd50f866
|
||||||
github.com/88250/lute v1.7.7-0.20240516160236-5b37ee0d7d34
|
github.com/88250/lute v1.7.7-0.20240518021146-7847ee928e31
|
||||||
github.com/88250/pdfcpu v0.3.14-0.20230401044135-c7369a99720c
|
github.com/88250/pdfcpu v0.3.14-0.20230401044135-c7369a99720c
|
||||||
github.com/88250/vitess-sqlparser v0.0.0-20210205111146-56a2ded2aba1
|
github.com/88250/vitess-sqlparser v0.0.0-20210205111146-56a2ded2aba1
|
||||||
github.com/ClarkThan/ahocorasick v0.0.0-20231011042242-30d1ef1347f4
|
github.com/ClarkThan/ahocorasick v0.0.0-20231011042242-30d1ef1347f4
|
||||||
|
@ -12,8 +12,8 @@ github.com/88250/go-sqlite3 v1.14.13-0.20231214121541-e7f54c482950 h1:Pa5hMiBceT
|
|||||||
github.com/88250/go-sqlite3 v1.14.13-0.20231214121541-e7f54c482950/go.mod h1:NyWgC/yNuGj7Q9rpYnZvas74GogHl5/Z4A/KQRfk6bU=
|
github.com/88250/go-sqlite3 v1.14.13-0.20231214121541-e7f54c482950/go.mod h1:NyWgC/yNuGj7Q9rpYnZvas74GogHl5/Z4A/KQRfk6bU=
|
||||||
github.com/88250/gulu v1.2.3-0.20240505150113-bc43bd50f866 h1:RFfNFS0hv6TbOuwET6xZAfGlV4hNlXiWTnfbLN1eF6k=
|
github.com/88250/gulu v1.2.3-0.20240505150113-bc43bd50f866 h1:RFfNFS0hv6TbOuwET6xZAfGlV4hNlXiWTnfbLN1eF6k=
|
||||||
github.com/88250/gulu v1.2.3-0.20240505150113-bc43bd50f866/go.mod h1:MUfzyfmbPrRDZLqxc7aPrVYveatTHRfoUa5TynPS0i8=
|
github.com/88250/gulu v1.2.3-0.20240505150113-bc43bd50f866/go.mod h1:MUfzyfmbPrRDZLqxc7aPrVYveatTHRfoUa5TynPS0i8=
|
||||||
github.com/88250/lute v1.7.7-0.20240516160236-5b37ee0d7d34 h1:GFQwT/644WDTkeSA0AMuCiZleyNusR6AdLX3faxBRJA=
|
github.com/88250/lute v1.7.7-0.20240518021146-7847ee928e31 h1:fndkUMfcXELViXxEuqS92N3xZhNcSssnhHOvei3zjZc=
|
||||||
github.com/88250/lute v1.7.7-0.20240516160236-5b37ee0d7d34/go.mod h1:VDAzL8b+oCh+e3NAlmwwLzC53ten0rZlS8NboB7ljtk=
|
github.com/88250/lute v1.7.7-0.20240518021146-7847ee928e31/go.mod h1:VDAzL8b+oCh+e3NAlmwwLzC53ten0rZlS8NboB7ljtk=
|
||||||
github.com/88250/pdfcpu v0.3.14-0.20230401044135-c7369a99720c h1:Dl/8S9iLyPMTElnWIBxmjaLiWrkI5P4a21ivwAn5pU0=
|
github.com/88250/pdfcpu v0.3.14-0.20230401044135-c7369a99720c h1:Dl/8S9iLyPMTElnWIBxmjaLiWrkI5P4a21ivwAn5pU0=
|
||||||
github.com/88250/pdfcpu v0.3.14-0.20230401044135-c7369a99720c/go.mod h1:S5YT38L/GCjVjmB4PB84PymA1qfopjEhfhTNQilLpv4=
|
github.com/88250/pdfcpu v0.3.14-0.20230401044135-c7369a99720c/go.mod h1:S5YT38L/GCjVjmB4PB84PymA1qfopjEhfhTNQilLpv4=
|
||||||
github.com/88250/vitess-sqlparser v0.0.0-20210205111146-56a2ded2aba1 h1:48T899JQDwyyRu9yXHePYlPdHtpJfrJEUGBMH3SMBWY=
|
github.com/88250/vitess-sqlparser v0.0.0-20210205111146-56a2ded2aba1 h1:48T899JQDwyyRu9yXHePYlPdHtpJfrJEUGBMH3SMBWY=
|
||||||
|
@ -1962,6 +1962,16 @@ func processKaTexMacros(n *ast.Node) {
|
|||||||
depth := 1
|
depth := 1
|
||||||
expanded := resolveKaTexMacro(usedMacro, ¯os, &keys, &depth)
|
expanded := resolveKaTexMacro(usedMacro, ¯os, &keys, &depth)
|
||||||
expanded = unescapeKaTexSupportedFunctions(expanded)
|
expanded = unescapeKaTexSupportedFunctions(expanded)
|
||||||
|
|
||||||
|
idx := strings.Index(mathContent, usedMacro)
|
||||||
|
if idx < 0 {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
// 处理宏参数
|
||||||
|
fillKaTexMacrosParams(usedMacro, &mathContent, &expanded)
|
||||||
|
|
||||||
|
// 将宏展开替换到 mathContent 中
|
||||||
mathContent = strings.ReplaceAll(mathContent, usedMacro, expanded)
|
mathContent = strings.ReplaceAll(mathContent, usedMacro, expanded)
|
||||||
}
|
}
|
||||||
mathContent = unescapeKaTexSupportedFunctions(mathContent)
|
mathContent = unescapeKaTexSupportedFunctions(mathContent)
|
||||||
|
@ -18,7 +18,10 @@ package model
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"sort"
|
"sort"
|
||||||
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
"github.com/88250/gulu"
|
||||||
)
|
)
|
||||||
|
|
||||||
func extractUsedMacros(mathContent string, macrosKeys *[]string) (ret []string) {
|
func extractUsedMacros(mathContent string, macrosKeys *[]string) (ret []string) {
|
||||||
@ -952,3 +955,35 @@ func unescapeKaTexSupportedFunctions(macroVal string) string {
|
|||||||
}
|
}
|
||||||
return macroVal
|
return macroVal
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func fillKaTexMacrosParams(macro string, mathContent, expanded *string) {
|
||||||
|
// Support KaTex macro parameters https://github.com/siyuan-note/siyuan/issues/11448
|
||||||
|
|
||||||
|
idx := strings.Index(*mathContent, macro)
|
||||||
|
if idx < 0 {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// 提取 mathContent 中 {} 包裹的实参,这里可能会提取到其他多余的参数,但是后面仅替换宏中的 #1, #2, ...,所以不影响
|
||||||
|
tmp := (*mathContent)[idx:]
|
||||||
|
args := map[int]string{}
|
||||||
|
for i, arg := range gulu.Str.SubstringsBetween(tmp, "{", "}") {
|
||||||
|
args[i+1] = arg
|
||||||
|
}
|
||||||
|
|
||||||
|
// 将宏展开中的 #1, #2, ... 替换为实参
|
||||||
|
// Macros accept up to nine arguments: #1, #2, etc. https://katex.org/docs/supported#macros
|
||||||
|
paramsCount := 0
|
||||||
|
for i := 0; i < len(args); i++ {
|
||||||
|
if strings.Contains(*expanded, "#"+strconv.Itoa(i+1)) {
|
||||||
|
paramsCount++
|
||||||
|
*expanded = strings.ReplaceAll(*expanded, "#"+strconv.Itoa(i+1), args[i+1])
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 根据参数个数将 mathContent 中的实参替换为空
|
||||||
|
for i := 1; i <= paramsCount; i++ {
|
||||||
|
tmp = strings.ReplaceAll(tmp, "{"+args[i]+"}", "")
|
||||||
|
*mathContent = (*mathContent)[:idx] + tmp
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -110,15 +110,16 @@ func ImportSY(zipPath, boxID, toPath string) (err error) {
|
|||||||
return nil
|
return nil
|
||||||
})
|
})
|
||||||
|
|
||||||
unzipRootPaths, err := filepath.Glob(unzipPath + "/*")
|
entries, err := os.ReadDir(unzipPath)
|
||||||
if nil != err {
|
if nil != err {
|
||||||
|
logging.LogErrorf("read unzip dir [%s] failed: %s", unzipPath, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if 1 != len(unzipRootPaths) {
|
if 1 != len(entries) {
|
||||||
logging.LogErrorf("invalid .sy.zip [%v]", unzipRootPaths)
|
logging.LogErrorf("invalid .sy.zip [%v]", entries)
|
||||||
return errors.New(Conf.Language(199))
|
return errors.New(Conf.Language(199))
|
||||||
}
|
}
|
||||||
unzipRootPath := unzipRootPaths[0]
|
unzipRootPath := filepath.Join(unzipPath, entries[0].Name())
|
||||||
name := filepath.Base(unzipRootPath)
|
name := filepath.Base(unzipRootPath)
|
||||||
if strings.HasPrefix(name, "data-20") && len("data-20230321175442") == len(name) {
|
if strings.HasPrefix(name, "data-20") && len("data-20230321175442") == len(name) {
|
||||||
logging.LogErrorf("invalid .sy.zip [unzipRootPath=%s, baseName=%s]", unzipRootPath, name)
|
logging.LogErrorf("invalid .sy.zip [unzipRootPath=%s, baseName=%s]", unzipRootPath, name)
|
||||||
|
Loading…
Reference in New Issue
Block a user