🐛 中西文间插入空格影响行级标记符 Fix https://github.com/siyuan-note/siyuan/issues/5308

This commit is contained in:
Liang Ding 2022-06-28 18:56:16 +08:00
parent 38a7d48eac
commit 1d10439bbb
No known key found for this signature in database
GPG key ID: 136F30F901A2231D
6 changed files with 37 additions and 33 deletions

View file

@ -95,8 +95,7 @@ func DocSaveAsTemplate(id string, overwrite bool) (code int, err error) {
return
}
// 添加 block ial后面格式化渲染需要
addBlockIALNodes(tree)
addBlockIALNodes(tree, true)
luteEngine := NewLute()
formatRenderer := render.NewFormatRenderer(tree, luteEngine.RenderOptions)
@ -259,7 +258,7 @@ func appendRefTextRenderResultForBlockRef(blockRef *ast.Node) {
blockRef.AppendChild(&ast.Node{Type: ast.NodeBlockRefDynamicText, Tokens: gulu.Str.ToBytes(text)})
}
func addBlockIALNodes(tree *parse.Tree) {
func addBlockIALNodes(tree *parse.Tree, removeUpdated bool) {
var blocks []*ast.Node
ast.Walk(tree.Root, func(n *ast.Node, entering bool) ast.WalkStatus {
if !entering || !n.IsBlock() {
@ -272,7 +271,7 @@ func addBlockIALNodes(tree *parse.Tree) {
}
} else if ast.NodeHTMLBlock == n.Type {
n.Tokens = bytes.TrimSpace(n.Tokens)
// 使用 <div> 包裹,否则后续解析模板时会识别为行级 HTML https://github.com/siyuan-note/siyuan/issues/4244
// 使用 <div> 包裹,否则后续解析时会识别为行级 HTML https://github.com/siyuan-note/siyuan/issues/4244
if !bytes.HasPrefix(n.Tokens, []byte("<div>")) {
n.Tokens = append([]byte("<div>\n"), n.Tokens...)
}
@ -281,7 +280,9 @@ func addBlockIALNodes(tree *parse.Tree) {
}
}
n.RemoveIALAttr("updated")
if removeUpdated {
n.RemoveIALAttr("updated")
}
if 0 < len(n.KramdownIAL) {
blocks = append(blocks, n)
}