🐛 数据解析时未区分超链接与图片 Fix https://github.com/siyuan-note/insider/issues/1073

This commit is contained in:
Liang Ding 2022-09-20 22:02:45 +08:00
parent 152665335e
commit ce39bd3a54
No known key found for this signature in database
GPG key ID: 136F30F901A2231D
5 changed files with 49 additions and 71 deletions

File diff suppressed because one or more lines are too long

View file

@ -7,7 +7,7 @@ require (
github.com/88250/css v0.1.2
github.com/88250/flock v0.8.2
github.com/88250/gulu v1.2.3-0.20220916075322-eb117059d70a
github.com/88250/lute v1.7.5-0.20220919070155-de3fd729795b
github.com/88250/lute v1.7.5-0.20220920135644-35e0aced3e2a
github.com/88250/pdfcpu v0.3.13
github.com/88250/vitess-sqlparser v0.0.0-20210205111146-56a2ded2aba1
github.com/ConradIrwin/font v0.0.0-20210318200717-ce8d41cc0732

View file

@ -19,16 +19,8 @@ github.com/88250/go-sqlite3 v1.14.13-0.20220714142610-fbbda1ee84f5 h1:8HdZozCsXS
github.com/88250/go-sqlite3 v1.14.13-0.20220714142610-fbbda1ee84f5/go.mod h1:NyWgC/yNuGj7Q9rpYnZvas74GogHl5/Z4A/KQRfk6bU=
github.com/88250/gulu v1.2.3-0.20220916075322-eb117059d70a h1:qQdnk8clbgA+MXtf5bXOTOby32iQYjqMOn6oBIMV/Tk=
github.com/88250/gulu v1.2.3-0.20220916075322-eb117059d70a/go.mod h1:I1qBzsksFL2ciGSuqDE7R3XW4BUMrfDgOvSXEk7FsAI=
github.com/88250/lute v1.7.5-0.20220918140805-18adc927144a h1:9nyjAkdNKIjQCJmNbtcqdMhG4bUHbf8QtUNGtFs/nJc=
github.com/88250/lute v1.7.5-0.20220918140805-18adc927144a/go.mod h1:cEoBGi0zArPqAsp0MdG9SKinvH/xxZZWXU7sRx8vHSA=
github.com/88250/lute v1.7.5-0.20220919014341-2efb181e3736 h1:uxHR5azRT/mNRiQzq/THSsES0MeJ3KDfxfKDN2zh9aI=
github.com/88250/lute v1.7.5-0.20220919014341-2efb181e3736/go.mod h1:cEoBGi0zArPqAsp0MdG9SKinvH/xxZZWXU7sRx8vHSA=
github.com/88250/lute v1.7.5-0.20220919015919-e05391a106b3 h1:F78DnfTxvC2ugvvt174mtampLS71w6+tqAYGa01DSVw=
github.com/88250/lute v1.7.5-0.20220919015919-e05391a106b3/go.mod h1:cEoBGi0zArPqAsp0MdG9SKinvH/xxZZWXU7sRx8vHSA=
github.com/88250/lute v1.7.5-0.20220919023317-f20f5cef5f56 h1:I3kvJm2iO9VhFTGChKaOASrRgMmnVhGgYrsUE0gXHyY=
github.com/88250/lute v1.7.5-0.20220919023317-f20f5cef5f56/go.mod h1:cEoBGi0zArPqAsp0MdG9SKinvH/xxZZWXU7sRx8vHSA=
github.com/88250/lute v1.7.5-0.20220919070155-de3fd729795b h1:dTuGmFlpbZ7SmdnkrBa9onRJBB68EUI2ARnVe4FveTM=
github.com/88250/lute v1.7.5-0.20220919070155-de3fd729795b/go.mod h1:cEoBGi0zArPqAsp0MdG9SKinvH/xxZZWXU7sRx8vHSA=
github.com/88250/lute v1.7.5-0.20220920135644-35e0aced3e2a h1:EdSXWsXh0fHHmx0czsvcHEai809EVtiD+4wLlQjLnC0=
github.com/88250/lute v1.7.5-0.20220920135644-35e0aced3e2a/go.mod h1:cEoBGi0zArPqAsp0MdG9SKinvH/xxZZWXU7sRx8vHSA=
github.com/88250/pdfcpu v0.3.13 h1:touMWMZkCGalMIbEg9bxYp7rETM+zwb9hXjwhqi4I7Q=
github.com/88250/pdfcpu v0.3.13/go.mod h1:S5YT38L/GCjVjmB4PB84PymA1qfopjEhfhTNQilLpv4=
github.com/88250/vitess-sqlparser v0.0.0-20210205111146-56a2ded2aba1 h1:48T899JQDwyyRu9yXHePYlPdHtpJfrJEUGBMH3SMBWY=

View file

@ -529,9 +529,9 @@ func buildSpanFromNode(n *ast.Node, tree *parse.Tree, rootID, boxID, p string) (
boxLocalPath := filepath.Join(util.DataDir, boxID)
docDirLocalPath := filepath.Join(boxLocalPath, p)
switch n.Type {
case ast.NodeLinkText:
case ast.NodeImage:
text := n.Text()
markdown := treenode.ExportNodeStdMd(n.Parent, luteEngine)
markdown := treenode.ExportNodeStdMd(n, luteEngine)
parentBlock := treenode.ParentBlock(n)
span := &Span{
ID: ast.NewNodeID(),
@ -545,7 +545,48 @@ func buildSpanFromNode(n *ast.Node, tree *parse.Tree, rootID, boxID, p string) (
IAL: treenode.IALStr(n),
}
spans = append(spans, span)
walkStatus = ast.WalkContinue
walkStatus = ast.WalkSkipChildren
destNode := n.ChildByType(ast.NodeLinkDest)
if nil == destNode {
return
}
// assetsLinkDestsInTree
if !IsAssetLinkDest(destNode.Tokens) {
return
}
dest := gulu.Str.FromBytes(destNode.Tokens)
var title string
if titleNode := n.ChildByType(ast.NodeLinkTitle); nil != titleNode {
title = gulu.Str.FromBytes(titleNode.Tokens)
}
var hash string
var hashErr error
if lp := assetLocalPath(dest, boxLocalPath, docDirLocalPath); "" != lp {
if !gulu.File.IsDir(lp) {
hash, hashErr = util.GetEtag(lp)
if nil != hashErr {
logging.LogErrorf("calc asset [%s] hash failed: %s", lp, hashErr)
}
}
}
name, _ := util.LastID(dest)
asset := &Asset{
ID: ast.NewNodeID(),
BlockID: parentBlock.ID,
RootID: rootID,
Box: boxID,
DocPath: p,
Path: dest,
Name: name,
Title: title,
Hash: hash,
}
assets = append(assets, asset)
return
case ast.NodeTag, ast.NodeInlineMath, ast.NodeCodeSpan, ast.NodeEmphasis, ast.NodeStrong, ast.NodeStrikethrough, ast.NodeMark, ast.NodeSup, ast.NodeSub, ast.NodeKbd, ast.NodeUnderline, ast.NodeTextMark:
typ := treenode.TypeAbbr(n.Type.String())
@ -578,62 +619,6 @@ func buildSpanFromNode(n *ast.Node, tree *parse.Tree, rootID, boxID, p string) (
spans = append(spans, span)
walkStatus = ast.WalkSkipChildren
return
case ast.NodeLinkDest:
text := n.TokensStr()
markdown := treenode.ExportNodeStdMd(n.Parent, luteEngine)
parentBlock := treenode.ParentBlock(n)
span := &Span{
ID: ast.NewNodeID(),
BlockID: parentBlock.ID,
RootID: rootID,
Box: boxID,
Path: p,
Content: text,
Markdown: markdown,
Type: treenode.TypeAbbr(n.Type.String()),
IAL: treenode.IALStr(n),
}
spans = append(spans, span)
// assetsLinkDestsInTree
if !IsAssetLinkDest(n.Tokens) {
walkStatus = ast.WalkContinue
return
}
dest := gulu.Str.FromBytes(n.Tokens)
parentBlock = treenode.ParentBlock(n)
var title string
if titleNode := n.Parent.ChildByType(ast.NodeLinkTitle); nil != titleNode {
title = gulu.Str.FromBytes(titleNode.Tokens)
}
var hash string
var hashErr error
if lp := assetLocalPath(dest, boxLocalPath, docDirLocalPath); "" != lp {
if !gulu.File.IsDir(lp) {
hash, hashErr = util.GetEtag(lp)
if nil != hashErr {
logging.LogErrorf("calc asset [%s] hash failed: %s", lp, hashErr)
}
}
}
name, _ := util.LastID(dest)
asset := &Asset{
ID: ast.NewNodeID(),
BlockID: parentBlock.ID,
RootID: rootID,
Box: boxID,
DocPath: p,
Path: dest,
Name: name,
Title: title,
Hash: hash,
}
assets = append(assets, asset)
walkStatus = ast.WalkSkipChildren
return
case ast.NodeDocument:
if asset := docTitleImgAsset(n); nil != asset {
assets = append(assets, asset)

View file

@ -275,6 +275,7 @@ var typeAbbrMap = map[string]string{
"NodeAudio": "audio",
// 行级元素
"NodeText": "text",
"NodeImage": "img",
"NodeLinkText": "link_text",
"NodeLinkDest": "link_dest",
"NodeTag": "tag",