|
@@ -534,7 +534,7 @@ func ExportResources(resourcePaths []string, mainName string) (exportFilePath st
|
|
|
|
|
|
func Preview(id string) (retStdHTML string, retOutline []*Path) {
|
|
|
tree, _ := LoadTreeByBlockID(id)
|
|
|
- tree = exportTree(tree, false, false, false,
|
|
|
+ tree = exportTree(tree, false, false,
|
|
|
Conf.Export.BlockRefMode, Conf.Export.BlockEmbedMode, Conf.Export.FileAnnotationRefMode,
|
|
|
Conf.Export.TagOpenMarker, Conf.Export.TagCloseMarker,
|
|
|
Conf.Export.BlockRefTextLeft, Conf.Export.BlockRefTextRight,
|
|
@@ -639,7 +639,7 @@ func ExportMarkdownHTML(id, savePath string, docx, merge bool) (name, dom string
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- tree = exportTree(tree, true, true, false,
|
|
|
+ tree = exportTree(tree, true, false,
|
|
|
Conf.Export.BlockRefMode, Conf.Export.BlockEmbedMode, Conf.Export.FileAnnotationRefMode,
|
|
|
Conf.Export.TagOpenMarker, Conf.Export.TagCloseMarker,
|
|
|
Conf.Export.BlockRefTextLeft, Conf.Export.BlockRefTextRight,
|
|
@@ -789,7 +789,7 @@ func ExportHTML(id, savePath string, pdf, image, keepFold, merge bool) (name, do
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- tree = exportTree(tree, true, true, keepFold,
|
|
|
+ tree = exportTree(tree, true, keepFold,
|
|
|
Conf.Export.BlockRefMode, Conf.Export.BlockEmbedMode, Conf.Export.FileAnnotationRefMode,
|
|
|
Conf.Export.TagOpenMarker, Conf.Export.TagCloseMarker,
|
|
|
Conf.Export.BlockRefTextLeft, Conf.Export.BlockRefTextRight,
|
|
@@ -1823,7 +1823,7 @@ func exportMarkdownContent0(tree *parse.Tree, cloudAssetsBase string, assetsDest
|
|
|
blockRefTextLeft, blockRefTextRight string,
|
|
|
addTitle bool,
|
|
|
defBlockIDs []string) (ret string) {
|
|
|
- tree = exportTree(tree, false, true, false,
|
|
|
+ tree = exportTree(tree, false, false,
|
|
|
blockRefMode, blockEmbedMode, fileAnnotationRefMode,
|
|
|
tagOpenMarker, tagCloseMarker,
|
|
|
blockRefTextLeft, blockRefTextRight,
|
|
@@ -1912,74 +1912,7 @@ func exportMarkdownContent0(tree *parse.Tree, cloudAssetsBase string, assetsDest
|
|
|
return
|
|
|
}
|
|
|
|
|
|
-func processKaTexMacros(n *ast.Node) {
|
|
|
- if 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
|
|
|
- }
|
|
|
-
|
|
|
- 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 strings.Contains(mathContent, k) {
|
|
|
- useMacro = true
|
|
|
- break
|
|
|
- }
|
|
|
- }
|
|
|
- if !useMacro {
|
|
|
- return
|
|
|
- }
|
|
|
- sort.Slice(keys, func(i, j int) bool { return len(keys[i]) > len(keys[j]) })
|
|
|
-
|
|
|
- mathContent = escapeKaTexSupportedFunctions(mathContent)
|
|
|
- usedMacros := extractUsedMacros(mathContent, &keys)
|
|
|
- for _, usedMacro := range usedMacros {
|
|
|
- depth := 1
|
|
|
- expanded := resolveKaTexMacro(usedMacro, ¯os, &keys, &depth)
|
|
|
- expanded = unescapeKaTexSupportedFunctions(expanded)
|
|
|
-
|
|
|
- idx := strings.Index(mathContent, usedMacro)
|
|
|
- if idx < 0 {
|
|
|
- continue
|
|
|
- }
|
|
|
-
|
|
|
- // 处理宏参数
|
|
|
- fillKaTexMacrosParams(usedMacro, &mathContent, &expanded)
|
|
|
-
|
|
|
- // 将宏展开替换到 mathContent 中
|
|
|
- mathContent = strings.ReplaceAll(mathContent, usedMacro, expanded)
|
|
|
- }
|
|
|
- mathContent = unescapeKaTexSupportedFunctions(mathContent)
|
|
|
- if ast.NodeTextMark == n.Type {
|
|
|
- n.TextMarkInlineMathContent = mathContent
|
|
|
- } else {
|
|
|
- n.Tokens = []byte(mathContent)
|
|
|
- }
|
|
|
-}
|
|
|
-
|
|
|
-func exportTree(tree *parse.Tree, wysiwyg, expandKaTexMacros, keepFold bool,
|
|
|
+func exportTree(tree *parse.Tree, wysiwyg, keepFold bool,
|
|
|
blockRefMode, blockEmbedMode, fileAnnotationRefMode int,
|
|
|
tagOpenMarker, tagCloseMarker string,
|
|
|
blockRefTextLeft, blockRefTextRight string,
|
|
@@ -2224,14 +2157,6 @@ func exportTree(tree *parse.Tree, wysiwyg, expandKaTexMacros, keepFold bool,
|
|
|
// 空的段落块需要补全文本展位,否则后续格式化后再解析树会语义不一致 https://github.com/siyuan-note/siyuan/issues/5806
|
|
|
emptyParagraphs = append(emptyParagraphs, n)
|
|
|
}
|
|
|
- case ast.NodeMathBlockContent:
|
|
|
- if expandKaTexMacros {
|
|
|
- processKaTexMacros(n)
|
|
|
- }
|
|
|
- case ast.NodeTextMark:
|
|
|
- if expandKaTexMacros && n.IsTextMarkType("inline-math") {
|
|
|
- processKaTexMacros(n)
|
|
|
- }
|
|
|
case ast.NodeWidget:
|
|
|
// 挂件块导出 https://github.com/siyuan-note/siyuan/issues/3834 https://github.com/siyuan-note/siyuan/issues/6188
|
|
|
|