mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-12-18 15:40:12 +01:00
🎨 Improve kernel API /api/block/getBlockKramdown https://github.com/siyuan-note/siyuan/issues/13183
This commit is contained in:
parent
9f46e09f7f
commit
371c64c471
2 changed files with 23 additions and 3 deletions
|
|
@ -603,7 +603,20 @@ func getBlockKramdown(c *gin.Context) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
kramdown := model.GetBlockKramdown(id)
|
// md:Markdown 标记符模式,使用标记符导出
|
||||||
|
// textmark:文本标记模式,使用 span 标签导出
|
||||||
|
// https://github.com/siyuan-note/siyuan/issues/13183
|
||||||
|
mode := "md"
|
||||||
|
if modeArg := arg["mode"]; nil != modeArg {
|
||||||
|
mode = modeArg.(string)
|
||||||
|
if "md" != mode && "textmark" != mode {
|
||||||
|
ret.Code = -1
|
||||||
|
ret.Msg = "Invalid mode"
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
kramdown := model.GetBlockKramdown(id, mode)
|
||||||
ret.Data = map[string]string{
|
ret.Data = map[string]string{
|
||||||
"id": id,
|
"id": id,
|
||||||
"kramdown": kramdown,
|
"kramdown": kramdown,
|
||||||
|
|
|
||||||
|
|
@ -20,6 +20,7 @@ import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"github.com/88250/lute/render"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
@ -617,7 +618,7 @@ func GetBlockDOM(id string) (ret string) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetBlockKramdown(id string) (ret string) {
|
func GetBlockKramdown(id, mode string) (ret string) {
|
||||||
if "" == id {
|
if "" == id {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
@ -633,7 +634,13 @@ func GetBlockKramdown(id string) (ret string) {
|
||||||
root.AppendChild(node.Next) // IAL
|
root.AppendChild(node.Next) // IAL
|
||||||
root.PrependChild(node)
|
root.PrependChild(node)
|
||||||
luteEngine := NewLute()
|
luteEngine := NewLute()
|
||||||
ret = treenode.ExportNodeStdMd(root, luteEngine)
|
if "md" == mode {
|
||||||
|
ret = treenode.ExportNodeStdMd(root, luteEngine)
|
||||||
|
} else {
|
||||||
|
tree.Root = root
|
||||||
|
formatRenderer := render.NewFormatRenderer(tree, luteEngine.RenderOptions)
|
||||||
|
ret = string(formatRenderer.Render())
|
||||||
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue