mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-12-17 07:00:12 +01:00
🐛 中西文间插入空格影响行级标记符 Fix https://github.com/siyuan-note/siyuan/issues/5308
This commit is contained in:
parent
38a7d48eac
commit
1d10439bbb
6 changed files with 37 additions and 33 deletions
2
app/stage/protyle/js/lute/lute.min.js
vendored
2
app/stage/protyle/js/lute/lute.min.js
vendored
File diff suppressed because one or more lines are too long
|
|
@ -7,7 +7,7 @@ require (
|
||||||
github.com/88250/css v0.1.2
|
github.com/88250/css v0.1.2
|
||||||
github.com/88250/flock v0.8.2
|
github.com/88250/flock v0.8.2
|
||||||
github.com/88250/gulu v1.2.3-0.20220623112232-c502d9016360
|
github.com/88250/gulu v1.2.3-0.20220623112232-c502d9016360
|
||||||
github.com/88250/lute v1.7.4-0.20220624073109-a79c7a5c9c9d
|
github.com/88250/lute v1.7.4-0.20220628102902-e32443650b1c
|
||||||
github.com/88250/melody v0.0.0-20201115062536-c0b3394adcd1
|
github.com/88250/melody v0.0.0-20201115062536-c0b3394adcd1
|
||||||
github.com/88250/pdfcpu v0.3.13
|
github.com/88250/pdfcpu v0.3.13
|
||||||
github.com/88250/protyle v0.0.0-20220519012506-0a2c8dc24397
|
github.com/88250/protyle v0.0.0-20220519012506-0a2c8dc24397
|
||||||
|
|
|
||||||
|
|
@ -51,8 +51,8 @@ github.com/88250/gulu v1.2.0/go.mod h1:ZhEJ98UjR2y7j2toGj4/b+1rRELcZFQAPq/Yjyin2
|
||||||
github.com/88250/gulu v1.2.3-0.20220623112232-c502d9016360 h1:afQ0cjIA/tzwvIDFy9Jf0jFCb1FvWwKuG1QidEMMi4M=
|
github.com/88250/gulu v1.2.3-0.20220623112232-c502d9016360 h1:afQ0cjIA/tzwvIDFy9Jf0jFCb1FvWwKuG1QidEMMi4M=
|
||||||
github.com/88250/gulu v1.2.3-0.20220623112232-c502d9016360/go.mod h1:I1qBzsksFL2ciGSuqDE7R3XW4BUMrfDgOvSXEk7FsAI=
|
github.com/88250/gulu v1.2.3-0.20220623112232-c502d9016360/go.mod h1:I1qBzsksFL2ciGSuqDE7R3XW4BUMrfDgOvSXEk7FsAI=
|
||||||
github.com/88250/lute v1.7.4-0.20220426011157-34c9bfa2e148/go.mod h1:Bdu9LRNjQhtL3TftbtpjIWTwDVAXoS7AD8QsZQPk7zo=
|
github.com/88250/lute v1.7.4-0.20220426011157-34c9bfa2e148/go.mod h1:Bdu9LRNjQhtL3TftbtpjIWTwDVAXoS7AD8QsZQPk7zo=
|
||||||
github.com/88250/lute v1.7.4-0.20220624073109-a79c7a5c9c9d h1:nGN2jBHT5fMnzCBrUsXqTDA+hAsCudvxvXdNbf1sZDc=
|
github.com/88250/lute v1.7.4-0.20220628102902-e32443650b1c h1:lM3ChAFl8eNrW08JNwKOWnsFjqiX9sl+y7B2rfdDynE=
|
||||||
github.com/88250/lute v1.7.4-0.20220624073109-a79c7a5c9c9d/go.mod h1:Bdu9LRNjQhtL3TftbtpjIWTwDVAXoS7AD8QsZQPk7zo=
|
github.com/88250/lute v1.7.4-0.20220628102902-e32443650b1c/go.mod h1:Bdu9LRNjQhtL3TftbtpjIWTwDVAXoS7AD8QsZQPk7zo=
|
||||||
github.com/88250/melody v0.0.0-20201115062536-c0b3394adcd1 h1:9Cb+iN639vUI2OcIBc+4oGwml9/0J6bL6dWNb8Al+1s=
|
github.com/88250/melody v0.0.0-20201115062536-c0b3394adcd1 h1:9Cb+iN639vUI2OcIBc+4oGwml9/0J6bL6dWNb8Al+1s=
|
||||||
github.com/88250/melody v0.0.0-20201115062536-c0b3394adcd1/go.mod h1:jH6MMPr8G7AMzaVmWHXZQiB1DKO3giWbcWZ7UoJ1teI=
|
github.com/88250/melody v0.0.0-20201115062536-c0b3394adcd1/go.mod h1:jH6MMPr8G7AMzaVmWHXZQiB1DKO3giWbcWZ7UoJ1teI=
|
||||||
github.com/88250/pdfcpu v0.3.13 h1:touMWMZkCGalMIbEg9bxYp7rETM+zwb9hXjwhqi4I7Q=
|
github.com/88250/pdfcpu v0.3.13 h1:touMWMZkCGalMIbEg9bxYp7rETM+zwb9hXjwhqi4I7Q=
|
||||||
|
|
|
||||||
|
|
@ -110,7 +110,7 @@ func GetBlockKramdown(id string) (ret string) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
addBlockIALNodes(tree)
|
addBlockIALNodes(tree, false)
|
||||||
node := treenode.GetNodeInTree(tree, id)
|
node := treenode.GetNodeInTree(tree, id)
|
||||||
luteEngine := NewLute()
|
luteEngine := NewLute()
|
||||||
ret, _ = lute.FormatNodeSync(node, luteEngine.ParseOptions, luteEngine.RenderOptions)
|
ret, _ = lute.FormatNodeSync(node, luteEngine.ParseOptions, luteEngine.RenderOptions)
|
||||||
|
|
|
||||||
|
|
@ -17,7 +17,6 @@
|
||||||
package model
|
package model
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
|
||||||
|
|
@ -41,35 +40,39 @@ func AutoSpace(rootID string) (err error) {
|
||||||
|
|
||||||
generateFormatHistory(tree)
|
generateFormatHistory(tree)
|
||||||
|
|
||||||
var blocks []*ast.Node
|
luteEngine := NewLute()
|
||||||
var rootIAL [][]string
|
// 合并相邻的同类行级节点
|
||||||
// 添加 block ial,后面格式化渲染需要
|
|
||||||
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 || !n.IsBlock() {
|
if entering {
|
||||||
return ast.WalkContinue
|
switch n.Type {
|
||||||
}
|
case ast.NodeStrong, ast.NodeEmphasis, ast.NodeStrikethrough, ast.NodeUnderline:
|
||||||
|
luteEngine.MergeSameSpan(n, n.Type)
|
||||||
if ast.NodeDocument == n.Type {
|
|
||||||
rootIAL = n.KramdownIAL
|
|
||||||
return ast.WalkContinue
|
|
||||||
}
|
|
||||||
|
|
||||||
if ast.NodeBlockQueryEmbed == n.Type {
|
|
||||||
if script := n.ChildByType(ast.NodeBlockQueryEmbedScript); nil != script {
|
|
||||||
script.Tokens = bytes.ReplaceAll(script.Tokens, []byte("\n"), []byte(" "))
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if 0 < len(n.KramdownIAL) {
|
|
||||||
blocks = append(blocks, n)
|
|
||||||
}
|
|
||||||
return ast.WalkContinue
|
return ast.WalkContinue
|
||||||
})
|
})
|
||||||
for _, block := range blocks {
|
|
||||||
block.InsertAfter(&ast.Node{Type: ast.NodeKramdownBlockIAL, Tokens: parse.IAL2Tokens(block.KramdownIAL)})
|
// 合并相邻的文本节点
|
||||||
|
for {
|
||||||
|
var unlinks []*ast.Node
|
||||||
|
ast.Walk(tree.Root, func(n *ast.Node, entering bool) ast.WalkStatus {
|
||||||
|
if entering && ast.NodeText == n.Type && nil != n.Next && ast.NodeText == n.Next.Type {
|
||||||
|
n.Tokens = append(n.Tokens, n.Next.Tokens...)
|
||||||
|
unlinks = append(unlinks, n.Next)
|
||||||
|
}
|
||||||
|
return ast.WalkContinue
|
||||||
|
})
|
||||||
|
for _, n := range unlinks {
|
||||||
|
n.Unlink()
|
||||||
|
}
|
||||||
|
if 1 > len(unlinks) {
|
||||||
|
break
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
luteEngine := NewLute()
|
rootIAL := tree.Root.KramdownIAL
|
||||||
|
addBlockIALNodes(tree, false)
|
||||||
|
|
||||||
luteEngine.SetAutoSpace(true)
|
luteEngine.SetAutoSpace(true)
|
||||||
formatRenderer := render.NewFormatRenderer(tree, luteEngine.RenderOptions)
|
formatRenderer := render.NewFormatRenderer(tree, luteEngine.RenderOptions)
|
||||||
md := formatRenderer.Render()
|
md := formatRenderer.Render()
|
||||||
|
|
|
||||||
|
|
@ -95,8 +95,7 @@ func DocSaveAsTemplate(id string, overwrite bool) (code int, err error) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// 添加 block ial,后面格式化渲染需要
|
addBlockIALNodes(tree, true)
|
||||||
addBlockIALNodes(tree)
|
|
||||||
|
|
||||||
luteEngine := NewLute()
|
luteEngine := NewLute()
|
||||||
formatRenderer := render.NewFormatRenderer(tree, luteEngine.RenderOptions)
|
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)})
|
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
|
var blocks []*ast.Node
|
||||||
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 || !n.IsBlock() {
|
if !entering || !n.IsBlock() {
|
||||||
|
|
@ -272,7 +271,7 @@ func addBlockIALNodes(tree *parse.Tree) {
|
||||||
}
|
}
|
||||||
} else if ast.NodeHTMLBlock == n.Type {
|
} else if ast.NodeHTMLBlock == n.Type {
|
||||||
n.Tokens = bytes.TrimSpace(n.Tokens)
|
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>")) {
|
if !bytes.HasPrefix(n.Tokens, []byte("<div>")) {
|
||||||
n.Tokens = append([]byte("<div>\n"), n.Tokens...)
|
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) {
|
if 0 < len(n.KramdownIAL) {
|
||||||
blocks = append(blocks, n)
|
blocks = append(blocks, n)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue