From 5422d0fb148b11d599b0fb88cc26b604f20ace11 Mon Sep 17 00:00:00 2001 From: Liang Ding Date: Mon, 5 Sep 2022 00:03:14 +0800 Subject: [PATCH 1/3] =?UTF-8?q?:art:=20=E5=85=AC=E5=BC=8F=E5=AF=BC?= =?UTF-8?q?=E5=87=BA=E6=97=B6=E5=B0=86=E5=AE=8F=E5=AE=9A=E4=B9=89=E4=BD=BF?= =?UTF-8?q?=E7=94=A8=20`\newcommand`=20=E6=8F=92=E5=85=A5=20Fix=20https://?= =?UTF-8?q?github.com/siyuan-note/siyuan/issues/5818?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- kernel/model/export.go | 75 ++++++++++++++++++++++++++++++++++++++---- 1 file changed, 69 insertions(+), 6 deletions(-) diff --git a/kernel/model/export.go b/kernel/model/export.go index 3c659d57e..75da2873b 100644 --- a/kernel/model/export.go +++ b/kernel/model/export.go @@ -196,7 +196,7 @@ func exportData(exportFolder string) (err error) { func Preview(id string) string { tree, _ := loadTreeByBlockID(id) - tree = exportTree(tree, false) + tree = exportTree(tree, false, false) luteEngine := NewLute() luteEngine.SetFootnotes(true) md := treenode.FormatNode(tree.Root, luteEngine) @@ -250,7 +250,7 @@ func ExportDocx(id, savePath string, removeAssets bool) (err error) { func ExportMarkdownHTML(id, savePath string, docx bool) (name, dom string) { tree, _ := loadTreeByBlockID(id) - tree = exportTree(tree, true) + tree = exportTree(tree, true, true) name = path.Base(tree.HPath) name = util.FilterFileName(name) // 导出 PDF、HTML 和 Word 时未移除不支持的文件名符号 https://github.com/siyuan-note/siyuan/issues/5614 @@ -362,7 +362,7 @@ func ExportHTML(id, savePath string, pdf bool) (name, dom string) { } } - tree = exportTree(tree, true) + tree = exportTree(tree, true, true) //if pdf { // TODO: 导出 PDF 时块引转换脚注使用书签跳转 https://github.com/siyuan-note/siyuan/issues/5761 // var footnotesDefs []*ast.Node // ast.Walk(tree.Root, func(n *ast.Node, entering bool) ast.WalkStatus { @@ -590,7 +590,7 @@ func AddPDFOutline(id, p string) (err error) { func CopyStdMarkdown(id string) string { tree, _ := loadTreeByBlockID(id) - tree = exportTree(tree, false) + tree = exportTree(tree, false, false) luteEngine := NewLute() luteEngine.SetFootnotes(true) luteEngine.SetKramdownIAL(false) @@ -914,7 +914,7 @@ func ExportMarkdownContent(id string) (hPath, exportedMd string) { func exportMarkdownContent(id string) (hPath, exportedMd string) { tree, _ := loadTreeByBlockID(id) hPath = tree.HPath - tree = exportTree(tree, false) + tree = exportTree(tree, false, true) luteEngine := NewLute() luteEngine.SetFootnotes(true) luteEngine.SetKramdownIAL(false) @@ -980,6 +980,65 @@ func renderExportMdInlineMathContent(r *render.FormatRenderer, node *ast.Node, e return ast.WalkContinue } +func processKaTexMacros(n *ast.Node) { + if ast.NodeInlineMathContent != n.Type && ast.NodeMathBlockContent != n.Type { + return + } + + mathContent := n.Tokens + macros := map[string]string{} + if err := gulu.JSON.UnmarshalJSON([]byte(Conf.Editor.KaTexMacros), ¯os); nil != err { + logging.LogWarnf("parse katex macros failed: %s", err) + return + } + + var keys []string + for k, _ := range macros { + keys = append(keys, k) + } + + useMacro := false + for k, _ := range macros { + if bytes.Contains(mathContent, []byte(k)) { + useMacro = true + break + } + } + if !useMacro { + return + } + + usedMacros := extractUsedMacros(mathContent, macros) + newcommandBuf := bytes.Buffer{} + for _, usedMacro := range usedMacros { + expanded := resolveKaTexMacro(usedMacro, ¯os, &keys) + newcommandBuf.WriteString("\\newcommand" + usedMacro + "{" + expanded + "}\n") + } + newcommandBuf.WriteString("\n") + mathContent = append(newcommandBuf.Bytes(), mathContent...) + n.Tokens = mathContent +} + +func extractUsedMacros(mathContent []byte, macros map[string]string) (ret []string) { + for macro, _ := range macros { + if bytes.Contains(mathContent, []byte(macro)) { + ret = append(ret, macro) + } + } + return +} + +func resolveKaTexMacro(macroName string, macros *map[string]string, keys *[]string) string { + v := (*macros)[macroName] + for _, k := range *keys { + if strings.Contains(v, k) { + v = strings.ReplaceAll(v, k, resolveKaTexMacro(k, macros, keys)) + (*macros)[macroName] = v + } + } + return v +} + func renderExportMdParagraph(r *render.FormatRenderer, node *ast.Node, entering bool) ast.WalkStatus { if entering { if r.Options.ChineseParagraphBeginningSpace && ast.NodeDocument == node.Parent.Type { @@ -1034,7 +1093,7 @@ func withoutKramdownBlockIAL(r *render.FormatRenderer, node *ast.Node) bool { return !r.Options.KramdownBlockIAL || 0 == len(node.KramdownIAL) } -func exportTree(tree *parse.Tree, wysiwyg bool) (ret *parse.Tree) { +func exportTree(tree *parse.Tree, wysiwyg, expandKaTexMacros bool) (ret *parse.Tree) { luteEngine := NewLute() ret = tree id := tree.Root.ID @@ -1286,6 +1345,10 @@ func exportTree(tree *parse.Tree, wysiwyg bool) (ret *parse.Tree) { } } + if expandKaTexMacros && (ast.NodeInlineMathContent == n.Type || ast.NodeMathBlockContent == n.Type) { + processKaTexMacros(n) + } + if ast.NodeWidget == n.Type { // 挂件块导出 https://github.com/siyuan-note/siyuan/issues/3834 exportMdVal := n.IALAttr("data-export-md") From b5011a8755ef3dfafe9d1a3b7231bd25f3bb9387 Mon Sep 17 00:00:00 2001 From: Liang Ding Date: Mon, 5 Sep 2022 00:17:17 +0800 Subject: [PATCH 2/3] =?UTF-8?q?:art:=20=E7=B4=AF=E8=AE=A1=E6=94=AF?= =?UTF-8?q?=E4=BB=98=E6=96=87=E6=A1=88=E4=BF=AE=E6=94=B9=20https://ld246.c?= =?UTF-8?q?om/article/1662303399926?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/appearance/langs/en_US.json | 2 +- app/appearance/langs/es_ES.json | 2 +- app/appearance/langs/fr_FR.json | 2 +- app/appearance/langs/zh_CHT.json | 2 +- app/appearance/langs/zh_CN.json | 2 +- app/src/config/account.ts | 2 +- 6 files changed, 6 insertions(+), 6 deletions(-) diff --git a/app/appearance/langs/en_US.json b/app/appearance/langs/en_US.json index 5351bb15c..a96fb7ca6 100644 --- a/app/appearance/langs/en_US.json +++ b/app/appearance/langs/en_US.json @@ -491,7 +491,7 @@ "sync": "Sync", "syncNow": "Sync now", "cloudBook": "Cloud Notebook", - "payment": "Payment", + "paymentSum": "Cumulatively paid", "refresh": "Refresh", "accountManage": "Account Manage", "logout": "Logout", diff --git a/app/appearance/langs/es_ES.json b/app/appearance/langs/es_ES.json index 2de0a1e0d..58bc50bcc 100644 --- a/app/appearance/langs/es_ES.json +++ b/app/appearance/langs/es_ES.json @@ -491,7 +491,7 @@ "sync": "Sincronización", "syncNow": "Sincronizar ahora", "cloudBook": "Cuaderno de notas en la nube", - "payment": "Pago", + "paymentSum": "Pagado acumulativamente", "refresh": "Actualizar", "accountManage": "Gestión de la cuenta", "logout": "Cierre de sesión", diff --git a/app/appearance/langs/fr_FR.json b/app/appearance/langs/fr_FR.json index 4341373d5..38c40bf85 100644 --- a/app/appearance/langs/fr_FR.json +++ b/app/appearance/langs/fr_FR.json @@ -491,7 +491,7 @@ "sync": "Synchro", "syncNow": "Synchro maintenant", "cloudBook": "Carnet de notes du Cloud", - "payment": "Paiement", + "paymentSum": "Cumulativement payé", "refresh": "Rafraîchir", "accountManage": "Gestion des comptes", "logout": "Se déconnecter", diff --git a/app/appearance/langs/zh_CHT.json b/app/appearance/langs/zh_CHT.json index 77dd74c44..dba8420f9 100644 --- a/app/appearance/langs/zh_CHT.json +++ b/app/appearance/langs/zh_CHT.json @@ -491,7 +491,7 @@ "sync": "同步", "syncNow": "立即同步", "cloudBook": "雲端筆記本", - "payment": "支付", + "payment": "累計已支付", "refresh": "重新整理", "accountManage": "帳號管理", "logout": "登出", diff --git a/app/appearance/langs/zh_CN.json b/app/appearance/langs/zh_CN.json index 5072ac245..39c486736 100644 --- a/app/appearance/langs/zh_CN.json +++ b/app/appearance/langs/zh_CN.json @@ -491,7 +491,7 @@ "sync": "同步", "syncNow": "立即同步", "cloudBook": "云端笔记本", - "payment": "支付", + "paymentSum": "累计已支付", "refresh": "刷新", "accountManage": "账号管理", "logout": "登出", diff --git a/app/src/config/account.ts b/app/src/config/account.ts index 76e245c3b..adb9eec90 100644 --- a/app/src/config/account.ts +++ b/app/src/config/account.ts @@ -112,7 +112,7 @@ ${window.siyuan.languages.account8}`;
- ${window.siyuan.languages.payment} + ${window.siyuan.languages.paymentSum} ${window.siyuan.user.userPaymentSum} RMB
From 3edafdd21f43305d3c75fce882757e7f96d4aa1d Mon Sep 17 00:00:00 2001 From: Liang Ding Date: Mon, 5 Sep 2022 11:59:22 +0800 Subject: [PATCH 3/3] =?UTF-8?q?:bug:=20=E6=8C=82=E4=BB=B6=E7=A7=BB?= =?UTF-8?q?=E5=8A=A8=E6=88=96=E8=AE=BE=E7=BD=AE=E5=A4=A7=E5=B0=8F=E5=90=8E?= =?UTF-8?q?=E5=B1=9E=E6=80=A7=E4=B8=A2=E5=A4=B1=20Fix=20https://github.com?= =?UTF-8?q?/siyuan-note/siyuan/issues/4885?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- kernel/model/transaction.go | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/kernel/model/transaction.go b/kernel/model/transaction.go index 54e182a8d..8bc11b866 100644 --- a/kernel/model/transaction.go +++ b/kernel/model/transaction.go @@ -904,6 +904,17 @@ func (tx *Transaction) doUpdate(operation *Operation) (ret *TxErr) { treenode.MoveFoldHeading(updatedNode, oldNode) } + // 挂件移动或设置大小后属性丢失 https://github.com/siyuan-note/siyuan/issues/4885 + // 这里需要把旧节点的属性复制到新节点上,避免属性丢失 + oldIAL := parse.IAL2Map(oldNode.KramdownIAL) + newIAL := parse.IAL2Map(updatedNode.KramdownIAL) + for oldIALKey, oldIALVal := range oldIAL { + if strings.HasPrefix(oldIALKey, "custom-") { + newIAL[oldIALKey] = oldIALVal + } + } + updatedNode.KramdownIAL = parse.Map2IAL(newIAL) + cache.PutBlockIAL(updatedNode.ID, parse.IAL2Map(updatedNode.KramdownIAL)) // 替换为新节点