mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-12-16 14:40:12 +01:00
🎨 Improve IFrame handling for exporting HTML/PDF/Image https://github.com/siyuan-note/siyuan/issues/16158 https://github.com/siyuan-note/siyuan/issues/4035
Signed-off-by: Daniel <845765@qq.com>
This commit is contained in:
parent
ba4dd38206
commit
b91f2cb3ad
1 changed files with 18 additions and 23 deletions
|
|
@ -1008,35 +1008,30 @@ 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 {
|
|
||||||
index := bytes.Index(n.Tokens, []byte("src=\""))
|
n.Type = ast.NodeParagraph
|
||||||
if 0 > index {
|
index := bytes.Index(n.Tokens, []byte("src=\""))
|
||||||
n.InsertBefore(&ast.Node{Type: ast.NodeText, Tokens: n.Tokens})
|
if 0 > index {
|
||||||
} else {
|
n.AppendChild(&ast.Node{Type: ast.NodeText, Tokens: n.Tokens})
|
||||||
src := n.Tokens[index+len("src=\""):]
|
} else {
|
||||||
src = src[:bytes.Index(src, []byte("\""))]
|
src := n.Tokens[index+len("src=\""):]
|
||||||
src = html.UnescapeHTML(src)
|
src = src[:bytes.Index(src, []byte("\""))]
|
||||||
link := &ast.Node{Type: ast.NodeLink}
|
src = html.UnescapeHTML(src)
|
||||||
link.AppendChild(&ast.Node{Type: ast.NodeOpenBracket})
|
link := &ast.Node{Type: ast.NodeLink}
|
||||||
link.AppendChild(&ast.Node{Type: ast.NodeText, Tokens: src})
|
link.AppendChild(&ast.Node{Type: ast.NodeOpenBracket})
|
||||||
link.AppendChild(&ast.Node{Type: ast.NodeCloseBracket})
|
link.AppendChild(&ast.Node{Type: ast.NodeText, Tokens: src})
|
||||||
link.AppendChild(&ast.Node{Type: ast.NodeOpenParen})
|
link.AppendChild(&ast.Node{Type: ast.NodeCloseBracket})
|
||||||
link.AppendChild(&ast.Node{Type: ast.NodeLinkDest, Tokens: src})
|
link.AppendChild(&ast.Node{Type: ast.NodeOpenParen})
|
||||||
link.AppendChild(&ast.Node{Type: ast.NodeCloseParen})
|
link.AppendChild(&ast.Node{Type: ast.NodeLinkDest, Tokens: src})
|
||||||
n.InsertBefore(link)
|
link.AppendChild(&ast.Node{Type: ast.NodeCloseParen})
|
||||||
}
|
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) {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue