Skip to content

Commit 8ddc2a5

Browse files
authored
✨ feat: 优化模板编辑体验,支持使用代码块来存储模板语法
1 parent a2a678c commit 8ddc2a5

1 file changed

Lines changed: 5 additions & 0 deletions

File tree

kernel/model/template.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import (
2323
"io/fs"
2424
"os"
2525
"path/filepath"
26+
"regexp"
2627
"sort"
2728
"strings"
2829
"text/template"
@@ -219,6 +220,10 @@ func DocSaveAsTemplate(id, name string, overwrite bool) (code int, err error) {
219220
md = append(md, parse.IAL2Tokens(tree.Root.KramdownIAL)...)
220221
}
221222

223+
// 处理 template 代码块:转换为普通文本并移除 id
224+
templateCodeBlockRegex := regexp.MustCompile(`‍?` + "`" + `{3}template\n([\s\S]*?)\n‍?` + "`" + `{3}\s*\{: id="[^"]*"\}`)
225+
md = templateCodeBlockRegex.ReplaceAll(md, []byte("$1"))
226+
222227
name = util.FilterFileName(name) + ".md"
223228
name = util.TruncateLenFileName(name)
224229
savePath := filepath.Join(util.DataDir, "templates", name)

0 commit comments

Comments
 (0)