mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-12-17 07:00:12 +01:00
🎨 支持通过界面设置代码片段 https://github.com/siyuan-note/siyuan/issues/6357
This commit is contained in:
parent
8f942aa631
commit
dd30521f72
2 changed files with 19 additions and 33 deletions
|
|
@ -23,6 +23,7 @@ import (
|
|||
"strings"
|
||||
|
||||
"github.com/88250/gulu"
|
||||
"github.com/88250/lute/ast"
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/siyuan-note/logging"
|
||||
"github.com/siyuan-note/siyuan/kernel/conf"
|
||||
|
|
@ -98,22 +99,29 @@ func setSnippet(c *gin.Context) {
|
|||
return
|
||||
}
|
||||
|
||||
id := gulu.Rand.String(12)
|
||||
idArg := arg["id"]
|
||||
if nil != idArg {
|
||||
id = idArg.(string)
|
||||
snippetsArg := arg["snippets"].([]interface{})
|
||||
var snippets []*conf.Snippet
|
||||
for _, s := range snippetsArg {
|
||||
m := s.(map[string]interface{})
|
||||
snippet := &conf.Snippet{
|
||||
ID: m["id"].(string),
|
||||
Name: m["name"].(string),
|
||||
Type: m["type"].(string),
|
||||
Content: m["content"].(string),
|
||||
Enabled: m["enabled"].(bool),
|
||||
}
|
||||
if "" == snippet.ID {
|
||||
snippet.ID = ast.NewNodeID()
|
||||
}
|
||||
snippets = append(snippets, snippet)
|
||||
}
|
||||
name := arg["name"].(string)
|
||||
typ := arg["type"].(string)
|
||||
content := arg["content"].(string)
|
||||
enabled := arg["enabled"].(bool)
|
||||
snippet, err := model.SetSnippet(id, name, typ, content, enabled)
|
||||
|
||||
err := model.SetSnippet(snippets)
|
||||
if nil != err {
|
||||
ret.Code = -1
|
||||
ret.Msg = "set snippet failed: " + err.Error()
|
||||
return
|
||||
}
|
||||
ret.Data = snippet
|
||||
}
|
||||
|
||||
func removeSnippet(c *gin.Context) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue