Support code block highlighting template syntax and export code block templates as paragraphs (#15345)

*  feat: 优化模板编辑体验,支持使用代码块来存储模板语法

*  feat: 支持对template代码块进行高亮

- 渲染.action 块和{{}}块规则
- 渲染Markdown块
- 思源块属性设置语法

* Update third-languages.js

* Update third-languages.js

* Update third-languages.js

* Update third-languages.js

* Update third-languages.js:块属性支持高亮.action{}语法,调整relevance

* 支持渲染queryBlocks的sql语句和嵌入块sql语句

* Update third-languages.js

补充变量高亮:getHPathByID|getBlock|statBlock|runeCount|wordCount|toPrettyJson|

*  feat: 优化模板编辑体验,支持使用代码块来存储模板语法 #15345

导出时,增加识别`siyuan-template`代码块为模板

*  feat: 优化模板编辑体验,支持使用代码块来存储模板语法 #15345

代码块语言新增`siyuan-template`

* Update template.go

---------

Co-authored-by: D <845765@qq.com>
This commit is contained in:
Achuan-2 2025-07-29 21:36:34 +08:00 committed by GitHub
parent 2994969286
commit 009a68aa7e
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 256 additions and 1 deletions

View file

@ -206,6 +206,28 @@ func DocSaveAsTemplate(id, name string, overwrite bool) (code int, err error) {
return ast.WalkContinue
})
var unlinks []*ast.Node
ast.Walk(tree.Root, func(n *ast.Node, entering bool) ast.WalkStatus {
if !entering {
return ast.WalkContinue
}
if ast.NodeCodeBlockFenceInfoMarker == n.Type {
if lang := string(n.CodeBlockInfo); "siyuan-template" == lang || "template" == lang {
// 将模板代码转换为段落文本 https://github.com/siyuan-note/siyuan/pull/15345
unlinks = append(unlinks, n.Parent)
p := treenode.NewParagraph(n.Parent.ID)
// 代码块内可能会有多个空行,但是这里不需要分块处理,后面渲染一个文本节点即可
p.AppendChild(&ast.Node{Type: ast.NodeText, Tokens: n.Next.Tokens})
n.Parent.InsertBefore(p)
}
}
return ast.WalkContinue
})
for _, n := range unlinks {
n.Unlink()
}
luteEngine := NewLute()
formatRenderer := render.NewFormatRenderer(tree, luteEngine.RenderOptions)
md := formatRenderer.Render()