♻️ 移除旧版中的行级元素实现代码 https://github.com/siyuan-note/siyuan/issues/6819

This commit is contained in:
Liang Ding 2022-12-08 20:19:35 +08:00
parent bc850b331a
commit c69983c56c
No known key found for this signature in database
GPG key ID: 136F30F901A2231D
8 changed files with 20 additions and 51 deletions

View file

@ -943,7 +943,7 @@ func exportMarkdownContent(id string) (hPath, exportedMd string) {
} }
func processKaTexMacros(n *ast.Node) { func processKaTexMacros(n *ast.Node) {
if ast.NodeInlineMathContent != n.Type && ast.NodeMathBlockContent != n.Type && ast.NodeTextMark != n.Type { if ast.NodeMathBlockContent != n.Type && ast.NodeTextMark != n.Type {
return return
} }
if ast.NodeTextMark == n.Type && !n.IsTextMarkType("inline-math") { if ast.NodeTextMark == n.Type && !n.IsTextMarkType("inline-math") {
@ -1081,7 +1081,7 @@ func exportTree(tree *parse.Tree, wysiwyg, expandKaTexMacros, keepFold bool) (re
case ast.NodeHeading: case ast.NodeHeading:
n.HeadingNormalizedID = n.IALAttr("id") n.HeadingNormalizedID = n.IALAttr("id")
n.ID = n.HeadingNormalizedID n.ID = n.HeadingNormalizedID
case ast.NodeInlineMathContent, ast.NodeMathBlockContent: case ast.NodeMathBlockContent:
n.Tokens = bytes.TrimSpace(n.Tokens) // 导出 Markdown 时去除公式内容中的首尾空格 https://github.com/siyuan-note/siyuan/issues/4666 n.Tokens = bytes.TrimSpace(n.Tokens) // 导出 Markdown 时去除公式内容中的首尾空格 https://github.com/siyuan-note/siyuan/issues/4666
return ast.WalkContinue return ast.WalkContinue
case ast.NodeTextMark: case ast.NodeTextMark:
@ -1216,7 +1216,7 @@ func exportTree(tree *parse.Tree, wysiwyg, expandKaTexMacros, keepFold bool) (re
// 空的段落块需要补全文本展位,否则后续格式化后再解析树会语义不一致 https://github.com/siyuan-note/siyuan/issues/5806 // 空的段落块需要补全文本展位,否则后续格式化后再解析树会语义不一致 https://github.com/siyuan-note/siyuan/issues/5806
emptyParagraphs = append(emptyParagraphs, n) emptyParagraphs = append(emptyParagraphs, n)
} }
case ast.NodeInlineMathContent, ast.NodeMathBlockContent: case ast.NodeMathBlockContent:
if expandKaTexMacros { if expandKaTexMacros {
processKaTexMacros(n) processKaTexMacros(n)
} }

View file

@ -46,8 +46,6 @@ func AutoSpace(rootID string) (err error) {
ast.Walk(tree.Root, func(n *ast.Node, entering bool) ast.WalkStatus { ast.Walk(tree.Root, func(n *ast.Node, entering bool) ast.WalkStatus {
if entering { if entering {
switch n.Type { switch n.Type {
case ast.NodeStrong, ast.NodeEmphasis, ast.NodeStrikethrough, ast.NodeUnderline:
luteEngine.MergeSameSpan(n)
case ast.NodeTextMark: case ast.NodeTextMark:
luteEngine.MergeSameTextMark(n) luteEngine.MergeSameTextMark(n)
} }

View file

@ -55,7 +55,7 @@ func renderOutline(node *ast.Node, luteEngine *lute.Lute) (ret string) {
buf.Write(tokens) buf.Write(tokens)
case ast.NodeBackslashContent: case ast.NodeBackslashContent:
buf.Write(n.Tokens) buf.Write(n.Tokens)
case ast.NodeInlineMath, ast.NodeStrong, ast.NodeEmphasis, ast.NodeCodeSpan, ast.NodeTextMark, ast.NodeMark: case ast.NodeTextMark:
dom := lute.RenderNodeBlockDOM(n, luteEngine.ParseOptions, luteEngine.RenderOptions) dom := lute.RenderNodeBlockDOM(n, luteEngine.ParseOptions, luteEngine.RenderOptions)
buf.WriteString(dom) buf.WriteString(dom)
return ast.WalkSkipChildren return ast.WalkSkipChildren

View file

@ -215,7 +215,7 @@ func FindReplace(keyword, replacement string, ids []string, method int) (err err
renameRoots = append(renameRoots, n) renameRoots = append(renameRoots, n)
} }
} }
case ast.NodeText, ast.NodeLinkDest, ast.NodeLinkText, ast.NodeLinkTitle, ast.NodeCodeSpanContent, ast.NodeCodeBlockCode, ast.NodeInlineMathContent, ast.NodeMathBlockContent: case ast.NodeText, ast.NodeLinkDest, ast.NodeLinkText, ast.NodeLinkTitle, ast.NodeCodeBlockCode, ast.NodeMathBlockContent:
if 0 == method { if 0 == method {
if bytes.Contains(n.Tokens, []byte(keyword)) { if bytes.Contains(n.Tokens, []byte(keyword)) {
n.Tokens = bytes.ReplaceAll(n.Tokens, []byte(keyword), []byte(replacement)) n.Tokens = bytes.ReplaceAll(n.Tokens, []byte(keyword), []byte(replacement))

View file

@ -892,15 +892,10 @@ func (tx *Transaction) doUpdate(operation *Operation) (ret *TxErr) {
return ast.WalkContinue return ast.WalkContinue
} }
if ast.NodeInlineMath == n.Type { if ast.NodeTextMark == n.Type {
content := n.ChildByType(ast.NodeInlineMathContent)
if nil == content || 1 > len(content.Tokens) {
// 剔除空白的行级公式
unlinks = append(unlinks, n)
}
} else if ast.NodeTextMark == n.Type {
if n.IsTextMarkType("inline-math") { if n.IsTextMarkType("inline-math") {
if "" == strings.TrimSpace(n.TextMarkInlineMathContent) { if "" == strings.TrimSpace(n.TextMarkInlineMathContent) {
// 剔除空白的行级公式
unlinks = append(unlinks, n) unlinks = append(unlinks, n)
} }
} else if n.IsTextMarkType("block-ref") { } else if n.IsTextMarkType("block-ref") {

View file

@ -657,7 +657,7 @@ func GetContainerText(container *ast.Node) string {
} }
switch n.Type { switch n.Type {
case ast.NodeText, ast.NodeLinkText, ast.NodeFileAnnotationRefText, ast.NodeFootnotesRef, case ast.NodeText, ast.NodeLinkText, ast.NodeFileAnnotationRefText, ast.NodeFootnotesRef,
ast.NodeCodeSpanContent, ast.NodeInlineMathContent, ast.NodeCodeBlockCode, ast.NodeMathBlockContent: ast.NodeCodeBlockCode, ast.NodeMathBlockContent:
buf.Write(n.Tokens) buf.Write(n.Tokens)
case ast.NodeTextMark: case ast.NodeTextMark:
buf.WriteString(n.Content()) buf.WriteString(n.Content())

View file

@ -429,7 +429,7 @@ func resolveRefContent0(node *ast.Node, anchors *map[string]string, depth *int,
buf.WriteString(n.IALAttr("title")) buf.WriteString(n.IALAttr("title"))
return ast.WalkStop return ast.WalkStop
case ast.NodeText, ast.NodeLinkText, ast.NodeLinkTitle, ast.NodeFileAnnotationRefText, ast.NodeFootnotesRef, case ast.NodeText, ast.NodeLinkText, ast.NodeLinkTitle, ast.NodeFileAnnotationRefText, ast.NodeFootnotesRef,
ast.NodeCodeSpanContent, ast.NodeInlineMathContent, ast.NodeCodeBlockCode, ast.NodeMathBlockContent: ast.NodeCodeBlockCode, ast.NodeMathBlockContent:
buf.Write(n.Tokens) buf.Write(n.Tokens)
case ast.NodeTextMark: case ast.NodeTextMark:
if n.IsTextMarkType("tag") { if n.IsTextMarkType("tag") {
@ -618,21 +618,9 @@ func buildSpanFromNode(n *ast.Node, tree *parse.Tree, rootID, boxID, p string) (
} }
assets = append(assets, asset) assets = append(assets, asset)
return return
case ast.NodeInlineMath, ast.NodeCodeSpan, ast.NodeEmphasis, ast.NodeStrong, ast.NodeStrikethrough, ast.NodeMark, ast.NodeSup, ast.NodeSub, ast.NodeKbd, ast.NodeUnderline, ast.NodeTextMark: case ast.NodeTextMark:
typ := treenode.TypeAbbr(n.Type.String()) typ := treenode.TypeAbbr(n.Type.String()) + " " + n.TextMarkType
var text string text := n.Content()
switch n.Type {
case ast.NodeEmphasis, ast.NodeStrong, ast.NodeStrikethrough, ast.NodeMark, ast.NodeSup, ast.NodeSub, ast.NodeKbd, ast.NodeUnderline:
text = n.Text()
case ast.NodeInlineMath:
text = n.ChildByType(ast.NodeInlineMathContent).TokensStr()
case ast.NodeCodeSpan:
text = n.ChildByType(ast.NodeCodeSpanContent).TokensStr()
case ast.NodeTextMark:
text = n.Content()
typ = typ + " " + n.TextMarkType
}
markdown := treenode.ExportNodeStdMd(n, luteEngine) markdown := treenode.ExportNodeStdMd(n, luteEngine)
parentBlock := treenode.ParentBlock(n) parentBlock := treenode.ParentBlock(n)
span := &Span{ span := &Span{

View file

@ -138,8 +138,7 @@ func NodeStaticContent(node *ast.Node) string {
buf.WriteByte(' ') buf.WriteByte(' ')
case ast.NodeLinkTitle: case ast.NodeLinkTitle:
buf.Write(n.Tokens) buf.Write(n.Tokens)
case ast.NodeText, ast.NodeFileAnnotationRefText, ast.NodeFootnotesRef, case ast.NodeText, ast.NodeFileAnnotationRefText, ast.NodeFootnotesRef, ast.NodeCodeBlockCode, ast.NodeMathBlockContent, ast.NodeHTMLBlock:
ast.NodeCodeSpanContent, ast.NodeInlineMathContent, ast.NodeCodeBlockCode, ast.NodeMathBlockContent, ast.NodeHTMLBlock:
tokens := n.Tokens tokens := n.Tokens
if IsChartCodeBlockCode(n) { if IsChartCodeBlockCode(n) {
// 图表块的内容在数据库 `blocks` 表 `content` 字段中被转义 https://github.com/siyuan-note/siyuan/issues/6326 // 图表块的内容在数据库 `blocks` 表 `content` 字段中被转义 https://github.com/siyuan-note/siyuan/issues/6326
@ -284,24 +283,13 @@ var typeAbbrMap = map[string]string{
"NodeThematicBreak": "tb", "NodeThematicBreak": "tb",
"NodeVideo": "video", "NodeVideo": "video",
"NodeAudio": "audio", "NodeAudio": "audio",
// 行级元素 // 行级元素 TODO: 移除旧版中的行级元素实现代码 https://github.com/siyuan-note/siyuan/issues/6819
"NodeText": "text", "NodeText": "text",
"NodeImage": "img", "NodeImage": "img",
"NodeLinkText": "link_text", "NodeLinkText": "link_text",
"NodeLinkDest": "link_dest", "NodeLinkDest": "link_dest",
"NodeTag": "tag", "NodeBlockRefID": "ref_id",
"NodeCodeSpan": "code_span", "NodeTextMark": "textmark",
"NodeInlineMath": "inline_math",
"NodeBlockRefID": "ref_id",
"NodeEmphasis": "em",
"NodeStrong": "strong",
"NodeStrikethrough": "strikethrough",
"NodeMark": "mark",
"NodeSup": "sup",
"NodeSub": "sub",
"NodeKbd": "kbd",
"NodeUnderline": "underline",
"NodeTextMark": "textmark",
} }
var abbrTypeMap = map[string]string{} var abbrTypeMap = map[string]string{}