Merge remote-tracking branch 'origin/dev' into dev

This commit is contained in:
Vanessa 2026-01-20 12:23:40 +08:00
commit 862d8280ad
8 changed files with 41 additions and 34 deletions

View file

@ -165,12 +165,11 @@ export const exportConfig = {
<span class="fn__space"></span>
<button class="b3-button b3-button--outline fn__flex-center fn__size200" id="pandocBin"><svg><use xlink:href="#iconSettings"></use></svg>${window.siyuan.languages.config}</button>
</div>
<div class="fn__flex b3-label config__item">
<div class="fn__flex-1">
${window.siyuan.languages.export25}
<div class="b3-label__text">${window.siyuan.languages.export26}</div>
</div>
<input class="b3-text-field fn__flex-center fn__size200" id="pandocParams">
<div class="b3-label config__item">
${window.siyuan.languages.export25}
<div class="b3-label__text">${window.siyuan.languages.export26}</div>
<div class="fn__hr"></div>
<textarea class="b3-text-field fn__block" id="pandocParams"></textarea>
</div>
<div class="fn__flex b3-label config__item">
<div class="fn__flex-1 fn__flex-center">

View file

@ -379,6 +379,7 @@ func setExport(c *gin.Context) {
}
}
export.PandocParams = util.ReplaceNewline(export.PandocParams, " ")
model.Conf.Export = export
model.Conf.Save()

View file

@ -1272,7 +1272,9 @@ func subscribeConfEvents() {
params += " \"" + util.PandocTemplatePath + "\""
Conf.Export.PandocParams = strings.TrimSpace(params)
}
logging.LogInfof("pandoc params set to [%s]", Conf.Export.PandocParams)
logging.LogInfof("pandoc template [%s], color filter [%s]", util.PandocTemplatePath, util.PandocColorFilterPath)
Conf.Save()
})
}

View file

@ -1282,6 +1282,11 @@ func processBase64Img(n *ast.Node, dest string, assetDirPath string) {
case "image/png":
img, decodeErr = png.Decode(dataReader)
ext = ".png"
if nil != decodeErr {
dataReader.Seek(0, 0)
img, decodeErr = jpeg.Decode(dataReader)
ext = ".jpg"
}
case "image/jpeg":
img, decodeErr = jpeg.Decode(dataReader)
ext = ".jpg"

View file

@ -138,7 +138,10 @@ func refreshDocInfoWithSize(tree *parse.Tree, size uint64) {
}
refreshDocInfo0(tree, size)
refreshParentDocInfo(tree)
go func() {
time.Sleep(128 * time.Millisecond)
refreshParentDocInfo(tree)
}()
}
func refreshParentDocInfo(tree *parse.Tree) {

View file

@ -45,9 +45,6 @@ var virtualBlockRefCache, _ = ristretto.NewCache(&ristretto.Config{
BufferItems: 64,
})
// newlineRegexp 用于匹配连续或单个换行符的正则表达式
var newlineRegexp = regexp.MustCompile(`[\r\n]+`)
func getBlockVirtualRefKeywords(root *ast.Node) (ret []string) {
val, ok := virtualBlockRefCache.Get(root.ID)
if !ok {
@ -256,7 +253,7 @@ func parseKeywords(keywordsStr string) (keywords []string) {
// 先处理转义的逗号
keywordsStr = strings.ReplaceAll(keywordsStr, "\\,", "__comma@sep__")
// 再将连续或单个换行符替换为一个逗号,避免把 `\\\n` 转换为 `\,`
keywordsStr = newlineRegexp.ReplaceAllString(keywordsStr, ",")
keywordsStr = util.ReplaceNewline(keywordsStr, ",")
// 按逗号分隔
for part := range strings.SplitSeq(keywordsStr, ",") {
part = strings.TrimSpace(part) // 剔除前后的空白字符

View file

@ -111,7 +111,7 @@ func InitPandoc() {
return
}
pandocDir := filepath.Join(TempDir, "pandoc")
tempPandocDir := filepath.Join(TempDir, "pandoc")
if confPath := filepath.Join(ConfDir, "conf.json"); gulu.File.IsExist(confPath) {
// Workspace built-in Pandoc is no longer initialized after customizing Pandoc path https://github.com/siyuan-note/siyuan/issues/8377
@ -119,7 +119,7 @@ func InitPandoc() {
conf := map[string]interface{}{}
if err = gulu.JSON.UnmarshalJSON(data, &conf); err == nil && nil != conf["export"] {
export := conf["export"].(map[string]interface{})
if customPandocBinPath := export["pandocBin"].(string); !strings.HasPrefix(customPandocBinPath, pandocDir) {
if customPandocBinPath := export["pandocBin"].(string); !strings.HasPrefix(customPandocBinPath, tempPandocDir) {
if pandocVer := getPandocVer(customPandocBinPath); "" != pandocVer {
PandocBinPath = customPandocBinPath
logging.LogInfof("custom pandoc [ver=%s, bin=%s]", pandocVer, PandocBinPath)
@ -130,24 +130,18 @@ func InitPandoc() {
}
}
PandocTemplatePath = filepath.Join(pandocDir, "pandoc-resources", "pandoc-template.docx")
PandocTemplatePath = filepath.Join(WorkingDir, "pandoc-resources", "pandoc-template.docx")
if !gulu.File.IsExist(PandocTemplatePath) {
PandocTemplatePath = filepath.Join(WorkingDir, "pandoc-resources", "pandoc-template.docx")
if "dev" == Mode || !gulu.File.IsExist(PandocTemplatePath) {
PandocTemplatePath = filepath.Join(WorkingDir, "pandoc", "pandoc-resources", "pandoc-template.docx")
}
PandocTemplatePath = filepath.Join(WorkingDir, "pandoc", "pandoc-resources", "pandoc-template.docx")
}
if !gulu.File.IsExist(PandocTemplatePath) {
PandocTemplatePath = ""
logging.LogWarnf("pandoc template file [%s] not found", PandocTemplatePath)
}
PandocColorFilterPath = filepath.Join(pandocDir, "pandoc-resources", "pandoc_color_filter.lua")
PandocColorFilterPath = filepath.Join(WorkingDir, "pandoc-resources", "pandoc_color_filter.lua")
if !gulu.File.IsExist(PandocColorFilterPath) {
PandocColorFilterPath = filepath.Join(WorkingDir, "pandoc-resources", "pandoc_color_filter.lua")
if "dev" == Mode || !gulu.File.IsExist(PandocColorFilterPath) {
PandocColorFilterPath = filepath.Join(WorkingDir, "pandoc", "pandoc-resources", "pandoc_color_filter.lua")
}
PandocColorFilterPath = filepath.Join(WorkingDir, "pandoc", "pandoc-resources", "pandoc_color_filter.lua")
}
if !gulu.File.IsExist(PandocColorFilterPath) {
PandocColorFilterPath = ""
@ -158,13 +152,13 @@ func InitPandoc() {
if gulu.OS.IsWindows() {
if "amd64" == runtime.GOARCH {
PandocBinPath = filepath.Join(pandocDir, "bin", "pandoc.exe")
PandocBinPath = filepath.Join(tempPandocDir, "bin", "pandoc.exe")
}
} else if gulu.OS.IsDarwin() {
PandocBinPath = filepath.Join(pandocDir, "bin", "pandoc")
PandocBinPath = filepath.Join(tempPandocDir, "bin", "pandoc")
} else if gulu.OS.IsLinux() {
if "amd64" == runtime.GOARCH {
PandocBinPath = filepath.Join(pandocDir, "bin", "pandoc")
PandocBinPath = filepath.Join(tempPandocDir, "bin", "pandoc")
}
}
pandocVer := getPandocVer(PandocBinPath)
@ -174,22 +168,22 @@ func InitPandoc() {
}
pandocZip := filepath.Join(WorkingDir, "pandoc.zip")
if "dev" == Mode || !gulu.File.IsExist(pandocZip) {
if !gulu.File.IsExist(pandocZip) {
if gulu.OS.IsWindows() {
if "amd64" == runtime.GOARCH {
pandocZip = filepath.Join(WorkingDir, "pandoc/pandoc-windows-amd64.zip")
pandocZip = filepath.Join(WorkingDir, "pandoc", "pandoc-windows-amd64.zip")
}
} else if gulu.OS.IsDarwin() {
if "amd64" == runtime.GOARCH {
pandocZip = filepath.Join(WorkingDir, "pandoc/pandoc-darwin-amd64.zip")
pandocZip = filepath.Join(WorkingDir, "pandoc", "pandoc-darwin-amd64.zip")
} else if "arm64" == runtime.GOARCH {
pandocZip = filepath.Join(WorkingDir, "pandoc/pandoc-darwin-arm64.zip")
pandocZip = filepath.Join(WorkingDir, "pandoc", "pandoc-darwin-arm64.zip")
}
} else if gulu.OS.IsLinux() {
if "amd64" == runtime.GOARCH {
pandocZip = filepath.Join(WorkingDir, "pandoc/pandoc-linux-amd64.zip")
pandocZip = filepath.Join(WorkingDir, "pandoc", "pandoc-linux-amd64.zip")
} else if "arm64" == runtime.GOARCH {
pandocZip = filepath.Join(WorkingDir, "pandoc/pandoc-linux-arm64.zip")
pandocZip = filepath.Join(WorkingDir, "pandoc", "pandoc-linux-arm64.zip")
}
}
}
@ -200,7 +194,7 @@ func InitPandoc() {
return
}
if err := gulu.Zip.Unzip(pandocZip, pandocDir); err != nil {
if err := gulu.Zip.Unzip(pandocZip, tempPandocDir); err != nil {
logging.LogErrorf("unzip pandoc failed: %s", err)
return
}

View file

@ -27,6 +27,12 @@ import (
"github.com/siyuan-note/logging"
)
var newlinesRegex = regexp.MustCompile(`[\r\n]+`)
func ReplaceNewline(text, replaceWith string) string {
return newlinesRegex.ReplaceAllString(text, replaceWith)
}
func ContainsCJK(text string) bool {
for _, r := range text {
ret := unicode.Is(unicode.Han, r) || unicode.Is(unicode.Lm, r) ||