From a467a92d91d7c3755462542954020dafd5d68123 Mon Sep 17 00:00:00 2001 From: Liang Ding Date: Fri, 16 Sep 2022 20:21:41 +0800 Subject: [PATCH 1/2] =?UTF-8?q?:art:=20=E6=90=9C=E7=B4=A2=E9=BB=98?= =?UTF-8?q?=E8=AE=A4=E8=AE=BE=E7=BD=AE=E5=A4=A7=E5=B0=8F=E5=86=99=E6=95=8F?= =?UTF-8?q?=E6=84=9F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- kernel/conf/search.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kernel/conf/search.go b/kernel/conf/search.go index 54178d5b9..c85d368fa 100644 --- a/kernel/conf/search.go +++ b/kernel/conf/search.go @@ -71,7 +71,7 @@ func NewSearch() *Search { HTMLBlock: true, Limit: 64, - CaseSensitive: false, + CaseSensitive: true, Name: true, Alias: true, From 98eeab2b9c4d665095788cf0113acd9d5205dab3 Mon Sep 17 00:00:00 2001 From: Liang Ding Date: Fri, 16 Sep 2022 20:50:14 +0800 Subject: [PATCH 2/2] =?UTF-8?q?:sparkles:=20=E8=A1=8C=E7=BA=A7=E5=85=83?= =?UTF-8?q?=E7=B4=A0=E6=94=AF=E6=8C=81=E5=A4=9A=E9=87=8D=E6=A0=B7=E5=BC=8F?= =?UTF-8?q?=E7=B1=BB=E5=9E=8B=20https://github.com/siyuan-note/siyuan/issu?= =?UTF-8?q?es/2911?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- kernel/model/export.go | 30 ++++++++++++++++++++++++++---- kernel/model/transaction.go | 6 ++++++ 2 files changed, 32 insertions(+), 4 deletions(-) diff --git a/kernel/model/export.go b/kernel/model/export.go index 3d2df975c..3327d3b2b 100644 --- a/kernel/model/export.go +++ b/kernel/model/export.go @@ -926,11 +926,24 @@ func exportMarkdownContent(id string) (hPath, exportedMd string) { } func processKaTexMacros(n *ast.Node) { - if ast.NodeInlineMathContent != n.Type && ast.NodeMathBlockContent != n.Type { + if ast.NodeInlineMathContent != n.Type && ast.NodeMathBlockContent != n.Type && ast.NodeTextMark != n.Type { + return + } + if ast.NodeTextMark == n.Type && !n.IsTextMarkType("inline-math") { + return + } + + var mathContent string + if ast.NodeTextMark == n.Type { + mathContent = n.TextMarkInlineMathContent + } else { + mathContent = string(n.Tokens) + } + mathContent = strings.TrimSpace(mathContent) + if "" == mathContent { return } - mathContent := string(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) @@ -961,7 +974,11 @@ func processKaTexMacros(n *ast.Node) { mathContent = strings.ReplaceAll(mathContent, usedMacro, expanded) } mathContent = unescapeKaTexSupportedFunctions(mathContent) - n.Tokens = []byte(mathContent) + if ast.NodeTextMark == n.Type { + n.TextMarkInlineMathContent = mathContent + } else { + n.Tokens = []byte(mathContent) + } } func exportTree(tree *parse.Tree, wysiwyg, expandKaTexMacros bool) (ret *parse.Tree) { @@ -1062,6 +1079,11 @@ func exportTree(tree *parse.Tree, wysiwyg, expandKaTexMacros bool) (ret *parse.T case ast.NodeInlineMathContent, ast.NodeMathBlockContent: n.Tokens = bytes.TrimSpace(n.Tokens) // 导出 Markdown 时去除公式内容中的首尾空格 https://github.com/siyuan-note/siyuan/issues/4666 return ast.WalkContinue + case ast.NodeTextMark: + if n.IsTextMarkType("inline-math") { + n.TextMarkInlineMathContent = strings.TrimSpace(n.TextMarkInlineMathContent) + return ast.WalkContinue + } case ast.NodeFileAnnotationRef: refIDNode := n.ChildByType(ast.NodeFileAnnotationRefID) if nil == refIDNode { @@ -1211,7 +1233,7 @@ func exportTree(tree *parse.Tree, wysiwyg, expandKaTexMacros bool) (ret *parse.T } } - if expandKaTexMacros && (ast.NodeInlineMathContent == n.Type || ast.NodeMathBlockContent == n.Type) { + if expandKaTexMacros && (ast.NodeInlineMathContent == n.Type || ast.NodeMathBlockContent == n.Type || (ast.NodeTextMark == n.Type && n.IsTextMarkType("inline-math"))) { processKaTexMacros(n) } diff --git a/kernel/model/transaction.go b/kernel/model/transaction.go index d8f32aba8..382085395 100644 --- a/kernel/model/transaction.go +++ b/kernel/model/transaction.go @@ -883,6 +883,12 @@ func (tx *Transaction) doUpdate(operation *Operation) (ret *TxErr) { // 剔除空白的行级公式 unlinks = append(unlinks, n) } + } else if ast.NodeTextMark == n.Type { + if n.IsTextMarkType("inline-math") { + if "" == strings.TrimSpace(n.TextMarkInlineMathContent) { + unlinks = append(unlinks, n) + } + } } else if ast.NodeBlockRef == n.Type { sql.CacheRef(subTree, n) } else if ast.NodeTextMark == n.Type && n.IsTextMarkType("block-ref") {