mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-12-17 07:00:12 +01:00
🎨 Code content in templates is not properly escaped https://github.com/siyuan-note/siyuan/issues/9649
This commit is contained in:
parent
9dc68a28e4
commit
ea2a2bbf03
1 changed files with 21 additions and 2 deletions
|
|
@ -20,7 +20,6 @@ import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/siyuan-note/siyuan/kernel/av"
|
|
||||||
"io/fs"
|
"io/fs"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
|
@ -33,10 +32,11 @@ import (
|
||||||
"github.com/88250/lute/ast"
|
"github.com/88250/lute/ast"
|
||||||
"github.com/88250/lute/parse"
|
"github.com/88250/lute/parse"
|
||||||
"github.com/88250/lute/render"
|
"github.com/88250/lute/render"
|
||||||
sprig "github.com/Masterminds/sprig/v3"
|
"github.com/Masterminds/sprig/v3"
|
||||||
"github.com/araddon/dateparse"
|
"github.com/araddon/dateparse"
|
||||||
"github.com/siyuan-note/filelock"
|
"github.com/siyuan-note/filelock"
|
||||||
"github.com/siyuan-note/logging"
|
"github.com/siyuan-note/logging"
|
||||||
|
"github.com/siyuan-note/siyuan/kernel/av"
|
||||||
"github.com/siyuan-note/siyuan/kernel/search"
|
"github.com/siyuan-note/siyuan/kernel/search"
|
||||||
"github.com/siyuan-note/siyuan/kernel/sql"
|
"github.com/siyuan-note/siyuan/kernel/sql"
|
||||||
"github.com/siyuan-note/siyuan/kernel/treenode"
|
"github.com/siyuan-note/siyuan/kernel/treenode"
|
||||||
|
|
@ -147,6 +147,25 @@ func DocSaveAsTemplate(id, name string, overwrite bool) (code int, err error) {
|
||||||
tree := prepareExportTree(bt)
|
tree := prepareExportTree(bt)
|
||||||
addBlockIALNodes(tree, true)
|
addBlockIALNodes(tree, true)
|
||||||
|
|
||||||
|
ast.Walk(tree.Root, func(n *ast.Node, entering bool) ast.WalkStatus {
|
||||||
|
if !entering {
|
||||||
|
return ast.WalkContinue
|
||||||
|
}
|
||||||
|
|
||||||
|
// Code content in templates is not properly escaped https://github.com/siyuan-note/siyuan/issues/9649
|
||||||
|
switch n.Type {
|
||||||
|
case ast.NodeCodeBlockCode:
|
||||||
|
n.Tokens = bytes.ReplaceAll(n.Tokens, []byte("""), []byte("\""))
|
||||||
|
case ast.NodeCodeSpanContent:
|
||||||
|
n.Tokens = bytes.ReplaceAll(n.Tokens, []byte("""), []byte("\""))
|
||||||
|
case ast.NodeTextMark:
|
||||||
|
if n.IsTextMarkType("code") {
|
||||||
|
n.TextMarkTextContent = strings.ReplaceAll(n.TextMarkTextContent, """, "\"")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return ast.WalkContinue
|
||||||
|
})
|
||||||
|
|
||||||
luteEngine := NewLute()
|
luteEngine := NewLute()
|
||||||
formatRenderer := render.NewFormatRenderer(tree, luteEngine.RenderOptions)
|
formatRenderer := render.NewFormatRenderer(tree, luteEngine.RenderOptions)
|
||||||
md := formatRenderer.Render()
|
md := formatRenderer.Render()
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue