mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-12-17 23:20:13 +01:00
🎨 数据历史文档支持只读可视化预览 https://github.com/siyuan-note/siyuan/issues/5735
This commit is contained in:
parent
a9b0bf5065
commit
9acfd1fb58
2 changed files with 2 additions and 33 deletions
|
|
@ -154,7 +154,8 @@ func GetDocHistoryContent(historyPath string) (content string, err error) {
|
||||||
os.RemoveAll(historyPath)
|
os.RemoveAll(historyPath)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
content = renderBlockMarkdown(historyTree.Root)
|
|
||||||
|
content = luteEngine.Tree2BlockDOM(historyTree, luteEngine.RenderOptions)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -202,35 +202,3 @@ func renderBlockMarkdownR0(id string, rendered *[]string) (ret []*ast.Node) {
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func renderBlockMarkdown(node *ast.Node) string {
|
|
||||||
var nodes []*ast.Node
|
|
||||||
ast.Walk(node, func(n *ast.Node, entering bool) ast.WalkStatus {
|
|
||||||
if entering {
|
|
||||||
nodes = append(nodes, n)
|
|
||||||
if ast.NodeHeading == node.Type {
|
|
||||||
// 支持“标题块”引用
|
|
||||||
children := treenode.HeadingChildren(n)
|
|
||||||
nodes = append(nodes, children...)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return ast.WalkSkipChildren
|
|
||||||
})
|
|
||||||
|
|
||||||
root := &ast.Node{Type: ast.NodeDocument}
|
|
||||||
luteEngine := NewLute()
|
|
||||||
luteEngine.SetKramdownIAL(false)
|
|
||||||
luteEngine.SetSuperBlock(false)
|
|
||||||
tree := &parse.Tree{Root: root, Context: &parse.Context{ParseOption: luteEngine.ParseOptions}}
|
|
||||||
renderer := render.NewFormatRenderer(tree, luteEngine.RenderOptions)
|
|
||||||
renderer.Writer = &bytes.Buffer{}
|
|
||||||
renderer.Writer.Grow(4096)
|
|
||||||
renderer.NodeWriterStack = append(renderer.NodeWriterStack, renderer.Writer) // 因为有可能不是从 root 开始渲染,所以需要初始化
|
|
||||||
for _, node := range nodes {
|
|
||||||
ast.Walk(node, func(n *ast.Node, entering bool) ast.WalkStatus {
|
|
||||||
rendererFunc := renderer.RendererFuncs[n.Type]
|
|
||||||
return rendererFunc(n, entering)
|
|
||||||
})
|
|
||||||
}
|
|
||||||
return strings.TrimSpace(renderer.Writer.String())
|
|
||||||
}
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue