diff --git a/app/src/config/exportConfig.ts b/app/src/config/exportConfig.ts index 324c4aa42..f76ce993f 100644 --- a/app/src/config/exportConfig.ts +++ b/app/src/config/exportConfig.ts @@ -165,12 +165,11 @@ export const exportConfig = { -
-
- ${window.siyuan.languages.export25} -
${window.siyuan.languages.export26}
-
- +
+ ${window.siyuan.languages.export25} +
${window.siyuan.languages.export26}
+
+
diff --git a/kernel/api/setting.go b/kernel/api/setting.go index 029b6e4b7..b03a17efb 100644 --- a/kernel/api/setting.go +++ b/kernel/api/setting.go @@ -379,6 +379,7 @@ func setExport(c *gin.Context) { } } + export.PandocParams = util.ReplaceNewline(export.PandocParams, " ") model.Conf.Export = export model.Conf.Save() diff --git a/kernel/model/conf.go b/kernel/model/conf.go index edb5cafa1..0493e333e 100644 --- a/kernel/model/conf.go +++ b/kernel/model/conf.go @@ -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() }) } diff --git a/kernel/model/import.go b/kernel/model/import.go index 45053ba55..cf64c9cb1 100644 --- a/kernel/model/import.go +++ b/kernel/model/import.go @@ -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" diff --git a/kernel/model/push_reload.go b/kernel/model/push_reload.go index d0ba464ca..168d5291c 100644 --- a/kernel/model/push_reload.go +++ b/kernel/model/push_reload.go @@ -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) { diff --git a/kernel/model/virutalref.go b/kernel/model/virutalref.go index a3923806e..5bb65de18 100644 --- a/kernel/model/virutalref.go +++ b/kernel/model/virutalref.go @@ -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) // 剔除前后的空白字符 diff --git a/kernel/util/pandoc.go b/kernel/util/pandoc.go index c6831bf4a..1cf80595b 100644 --- a/kernel/util/pandoc.go +++ b/kernel/util/pandoc.go @@ -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 } diff --git a/kernel/util/rune.go b/kernel/util/rune.go index 9e58df926..1617a3b39 100644 --- a/kernel/util/rune.go +++ b/kernel/util/rune.go @@ -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) ||