🎨 When exporting Markdown, <br /> nodes in non-tables are replaced with \n text nodes https://github.com/siyuan-note/siyuan/issues/9509

This commit is contained in:
Daniel 2023-10-25 21:59:36 +08:00
parent e32c8f8c1c
commit b95980f4b5
No known key found for this signature in database
GPG key ID: 86211BA83DF03017

View file

@ -1525,6 +1525,25 @@ func exportMarkdownContent0(tree *parse.Tree, cloudAssetsBase string, assetsDest
})
}
// When exporting Markdown, `<br />` nodes in non-tables are replaced with `\n` text nodes https://github.com/siyuan-note/siyuan/issues/9509
var unlinks []*ast.Node
ast.Walk(tree.Root, func(n *ast.Node, entering bool) ast.WalkStatus {
if !entering {
return ast.WalkContinue
}
if ast.NodeBr == n.Type {
if !n.ParentIs(ast.NodeTableCell) {
n.InsertBefore(&ast.Node{Type: ast.NodeText, Tokens: []byte("\n")})
unlinks = append(unlinks, n)
}
}
return ast.WalkContinue
})
for _, unlink := range unlinks {
unlink.Unlink()
}
renderer := render.NewProtyleExportMdRenderer(tree, luteEngine.RenderOptions)
ret = gulu.Str.FromBytes(renderer.Render())
return