From c8033c44b0c98e5ea2446c0c665db88062174ac8 Mon Sep 17 00:00:00 2001 From: Daniel <845765@qq.com> Date: Fri, 21 Nov 2025 20:21:28 +0800 Subject: [PATCH] :art: Improve HTML svg clipping https://github.com/siyuan-note/siyuan/issues/16413 Signed-off-by: Daniel <845765@qq.com> --- kernel/model/import.go | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/kernel/model/import.go b/kernel/model/import.go index 0b4983ffd..8563f05d2 100644 --- a/kernel/model/import.go +++ b/kernel/model/import.go @@ -78,6 +78,27 @@ func HTML2Tree(htmlStr string, luteEngine *lute.Lute) (tree *parse.Tree, withMat return ast.WalkContinue } + if ast.NodeHTMLBlock == n.Type { + if bytes.HasPrefix(n.Tokens, []byte("
")) && bytes.Contains(n.Tokens, []byte("data:image/svg+xml;base64")) {
+ matches := regexp.MustCompile(`(?sU)]*>(.*)
`).FindSubmatch(n.Tokens)
+ if len(matches) >= 2 {
+ n.Tokens = matches[1]
+ }
+ subTree := parse.Inline("", n.Tokens, luteEngine.ParseOptions)
+ if nil != subTree && nil != subTree.Root && nil != subTree.Root.FirstChild {
+ n.Type = ast.NodeParagraph
+ var children []*ast.Node
+ for c := subTree.Root.FirstChild.FirstChild; nil != c; c = c.Next {
+ children = append(children, c)
+ }
+ for _, c := range children {
+ n.AppendChild(c)
+ }
+ }
+ }
+ return ast.WalkContinue
+ }
+
if ast.NodeText == n.Type {
if n.ParentIs(ast.NodeTableCell) {
n.Tokens = bytes.ReplaceAll(n.Tokens, []byte("\\|"), []byte("|"))