Signed-off-by: Daniel <845765@qq.com>
This commit is contained in:
Daniel 2025-10-21 17:03:04 +08:00
parent ba4dd38206
commit b91f2cb3ad
No known key found for this signature in database
GPG key ID: 86211BA83DF03017

View file

@ -1008,15 +1008,15 @@ func prepareExportTree(bt *treenode.BlockTree) (ret *parse.Tree) {
func processIFrame(tree *parse.Tree) { func processIFrame(tree *parse.Tree) {
// 导出 PDF/Word 时 IFrame 块使用超链接 https://github.com/siyuan-note/siyuan/issues/4035 // 导出 PDF/Word 时 IFrame 块使用超链接 https://github.com/siyuan-note/siyuan/issues/4035
var unlinks []*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 { if !entering || ast.NodeIFrame != n.Type {
return ast.WalkContinue return ast.WalkContinue
} }
if ast.NodeIFrame == n.Type {
n.Type = ast.NodeParagraph
index := bytes.Index(n.Tokens, []byte("src=\"")) index := bytes.Index(n.Tokens, []byte("src=\""))
if 0 > index { if 0 > index {
n.InsertBefore(&ast.Node{Type: ast.NodeText, Tokens: n.Tokens}) n.AppendChild(&ast.Node{Type: ast.NodeText, Tokens: n.Tokens})
} else { } else {
src := n.Tokens[index+len("src=\""):] src := n.Tokens[index+len("src=\""):]
src = src[:bytes.Index(src, []byte("\""))] src = src[:bytes.Index(src, []byte("\""))]
@ -1028,15 +1028,10 @@ func processIFrame(tree *parse.Tree) {
link.AppendChild(&ast.Node{Type: ast.NodeOpenParen}) link.AppendChild(&ast.Node{Type: ast.NodeOpenParen})
link.AppendChild(&ast.Node{Type: ast.NodeLinkDest, Tokens: src}) link.AppendChild(&ast.Node{Type: ast.NodeLinkDest, Tokens: src})
link.AppendChild(&ast.Node{Type: ast.NodeCloseParen}) link.AppendChild(&ast.Node{Type: ast.NodeCloseParen})
n.InsertBefore(link) n.AppendChild(link)
}
unlinks = append(unlinks, n)
} }
return ast.WalkContinue return ast.WalkContinue
}) })
for _, n := range unlinks {
n.Unlink()
}
} }
func ProcessPDF(id, p string, merge, removeAssets, watermark bool) (err error) { func ProcessPDF(id, p string, merge, removeAssets, watermark bool) (err error) {