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