🎨 Improve markdown importing https://github.com/siyuan-note/siyuan/issues/13097 https://github.com/siyuan-note/siyuan/issues/13080
This commit is contained in:
parent
14f5570558
commit
a0491cd4ff
13 changed files with 21 additions and 18 deletions
|
@ -648,7 +648,7 @@ func dataBlockDOM(data string, luteEngine *lute.Lute) (ret string, err error) {
|
|||
ret, tree := luteEngine.Md2BlockDOMTree(data, true)
|
||||
if "" == ret {
|
||||
// 使用 API 插入空字符串出现错误 https://github.com/siyuan-note/siyuan/issues/3931
|
||||
blankParagraph := treenode.NewParagraph()
|
||||
blankParagraph := treenode.NewParagraph("")
|
||||
ret = luteEngine.RenderNodeBlockDOM(blankParagraph)
|
||||
}
|
||||
|
||||
|
|
|
@ -77,7 +77,7 @@ func html2BlockDOM(c *gin.Context) {
|
|||
}
|
||||
|
||||
if ast.NodeListItem == n.Type && nil == n.FirstChild {
|
||||
newNode := treenode.NewParagraph()
|
||||
newNode := treenode.NewParagraph("")
|
||||
n.AppendChild(newNode)
|
||||
n.SetIALAttr("updated", util.TimeFromID(newNode.ID))
|
||||
return ast.WalkSkipChildren
|
||||
|
@ -101,7 +101,7 @@ func html2BlockDOM(c *gin.Context) {
|
|||
row := head.FirstChild
|
||||
if nil != row.FirstChild && nil == row.FirstChild.Next {
|
||||
cell := row.FirstChild
|
||||
p := treenode.NewParagraph()
|
||||
p := treenode.NewParagraph("")
|
||||
var contents []*ast.Node
|
||||
for c := cell.FirstChild; nil != c; c = c.Next {
|
||||
contents = append(contents, c)
|
||||
|
|
|
@ -85,7 +85,7 @@ func ParseJSON(jsonData []byte, options *parse.Options) (ret *parse.Tree, needFi
|
|||
|
||||
if nil == ret.Root.FirstChild {
|
||||
// 如果是空文档的话挂一个空段落上去
|
||||
newP := treenode.NewParagraph()
|
||||
newP := treenode.NewParagraph("")
|
||||
ret.Root.AppendChild(newP)
|
||||
ret.Root.SetIALAttr("updated", newP.ID[:14])
|
||||
}
|
||||
|
|
|
@ -223,7 +223,7 @@ func prepareWriteTree(tree *parse.Tree) (data []byte, filePath string, err error
|
|||
luteEngine := util.NewLute() // 不关注用户的自定义解析渲染选项
|
||||
|
||||
if nil == tree.Root.FirstChild {
|
||||
newP := treenode.NewParagraph()
|
||||
newP := treenode.NewParagraph("")
|
||||
tree.Root.AppendChild(newP)
|
||||
tree.Root.SetIALAttr("updated", util.TimeFromID(newP.ID))
|
||||
treenode.UpsertBlockTree(tree)
|
||||
|
|
|
@ -395,7 +395,7 @@ func SwapBlockRef(refID, defID string, includeChildren bool) (err error) {
|
|||
refreshUpdated(defNode)
|
||||
refreshUpdated(refNode)
|
||||
|
||||
refPivot := treenode.NewParagraph()
|
||||
refPivot := treenode.NewParagraph("")
|
||||
refNode.InsertBefore(refPivot)
|
||||
|
||||
if ast.NodeListItem == defNode.Type {
|
||||
|
|
|
@ -496,7 +496,7 @@ func parseKTree(kramdown []byte) (ret *parse.Tree) {
|
|||
|
||||
func normalizeTree(tree *parse.Tree) (yfmRootID, yfmTitle, yfmUpdated string) {
|
||||
if nil == tree.Root.FirstChild {
|
||||
tree.Root.AppendChild(treenode.NewParagraph())
|
||||
tree.Root.AppendChild(treenode.NewParagraph(""))
|
||||
}
|
||||
|
||||
var unlinks []*ast.Node
|
||||
|
|
|
@ -46,7 +46,7 @@ func mergeSubDocs(rootTree *parse.Tree) (ret *parse.Tree, err error) {
|
|||
insertPoint = rootTree.Root.FirstChild
|
||||
if nil == insertPoint {
|
||||
// 如果文档为空,则创建一个空段落作为插入点
|
||||
insertPoint = treenode.NewParagraph()
|
||||
insertPoint = treenode.NewParagraph("")
|
||||
rootTree.Root.AppendChild(insertPoint)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1870,7 +1870,7 @@ func createDoc(boxID, p, title, dom string) (tree *parse.Tree, err error) {
|
|||
updated := util.TimeFromID(id)
|
||||
tree.Root.KramdownIAL = [][]string{{"id", id}, {"title", html.EscapeAttrVal(title)}, {"updated", updated}}
|
||||
if nil == tree.Root.FirstChild {
|
||||
tree.Root.AppendChild(treenode.NewParagraph())
|
||||
tree.Root.AppendChild(treenode.NewParagraph(""))
|
||||
}
|
||||
|
||||
// 如果段落块中仅包含一个 mp3/mp4 超链接,则将其转换为音视频块
|
||||
|
|
|
@ -195,7 +195,7 @@ func Doc2Heading(srcID, targetID string, after bool) (srcTreeBox, srcTreePath st
|
|||
if "" != tagIAL && 0 < len(tags) {
|
||||
// 带标签的文档块转换为标题块时将标签移动到标题块下方 https://github.com/siyuan-note/siyuan/issues/6550
|
||||
|
||||
tagPara := treenode.NewParagraph()
|
||||
tagPara := treenode.NewParagraph("")
|
||||
for i, tag := range tags {
|
||||
if "" == tag {
|
||||
continue
|
||||
|
@ -365,7 +365,7 @@ func Heading2Doc(srcHeadingID, targetBoxID, targetPath string) (srcRootBlockID,
|
|||
headingNode.Unlink()
|
||||
srcTree.Root.SetIALAttr("updated", util.CurrentTimeSecondsStr())
|
||||
if nil == srcTree.Root.FirstChild {
|
||||
srcTree.Root.AppendChild(treenode.NewParagraph())
|
||||
srcTree.Root.AppendChild(treenode.NewParagraph(""))
|
||||
}
|
||||
treenode.RemoveBlockTreesByRootID(srcTree.ID)
|
||||
if err = indexWriteTreeUpsertQueue(srcTree); err != nil {
|
||||
|
|
|
@ -1137,7 +1137,7 @@ func imgHtmlBlock2InlineImg(tree *parse.Tree) {
|
|||
alt := domAttrValue(htmlImg, "alt")
|
||||
title := domAttrValue(htmlImg, "title")
|
||||
|
||||
p := &ast.Node{Type: ast.NodeParagraph, ID: n.ID}
|
||||
p := treenode.NewParagraph(n.ID)
|
||||
img := &ast.Node{Type: ast.NodeImage}
|
||||
p.AppendChild(img)
|
||||
img.AppendChild(&ast.Node{Type: ast.NodeBang})
|
||||
|
|
|
@ -73,7 +73,7 @@ func ListItem2Doc(srcListItemID, targetBoxID, targetPath string) (srcRootBlockID
|
|||
children = append(children, c)
|
||||
}
|
||||
if 1 > len(children) {
|
||||
newNode := treenode.NewParagraph()
|
||||
newNode := treenode.NewParagraph("")
|
||||
children = append(children, newNode)
|
||||
}
|
||||
|
||||
|
@ -97,7 +97,7 @@ func ListItem2Doc(srcListItemID, targetBoxID, targetPath string) (srcRootBlockID
|
|||
}
|
||||
srcTree.Root.SetIALAttr("updated", util.CurrentTimeSecondsStr())
|
||||
if nil == srcTree.Root.FirstChild {
|
||||
srcTree.Root.AppendChild(treenode.NewParagraph())
|
||||
srcTree.Root.AppendChild(treenode.NewParagraph(""))
|
||||
}
|
||||
treenode.RemoveBlockTreesByRootID(srcTree.ID)
|
||||
if err = indexWriteTreeUpsertQueue(srcTree); err != nil {
|
||||
|
|
|
@ -341,9 +341,9 @@ func RenderTemplate(p, id string, preview bool) (tree *parse.Tree, dom string, e
|
|||
})
|
||||
for _, n := range nodesNeedAppendChild {
|
||||
if ast.NodeBlockquote == n.Type {
|
||||
n.FirstChild.InsertAfter(treenode.NewParagraph())
|
||||
n.FirstChild.InsertAfter(treenode.NewParagraph(""))
|
||||
} else {
|
||||
n.AppendChild(treenode.NewParagraph())
|
||||
n.AppendChild(treenode.NewParagraph(""))
|
||||
}
|
||||
}
|
||||
for _, n := range unlinks {
|
||||
|
|
|
@ -107,8 +107,11 @@ func RootChildIDs(rootID string) (ret []string) {
|
|||
return
|
||||
}
|
||||
|
||||
func NewParagraph() (ret *ast.Node) {
|
||||
newID := ast.NewNodeID()
|
||||
func NewParagraph(id string) (ret *ast.Node) {
|
||||
newID := id
|
||||
if "" == newID {
|
||||
newID = ast.NewNodeID()
|
||||
}
|
||||
ret = &ast.Node{ID: newID, Type: ast.NodeParagraph}
|
||||
ret.SetIALAttr("id", newID)
|
||||
ret.SetIALAttr("updated", newID[:14])
|
||||
|
|
Loading…
Add table
Reference in a new issue