mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-12-18 07:30:12 +01:00
🎨 Improve export preview mode https://github.com/siyuan-note/siyuan/issues/11981
This commit is contained in:
parent
4f31068205
commit
827819ef67
4 changed files with 29 additions and 7 deletions
|
|
@ -580,10 +580,9 @@ func exportPreview(c *gin.Context) {
|
||||||
}
|
}
|
||||||
|
|
||||||
id := arg["id"].(string)
|
id := arg["id"].(string)
|
||||||
stdHTML, outline := model.Preview(id)
|
stdHTML := model.Preview(id)
|
||||||
ret.Data = map[string]interface{}{
|
ret.Data = map[string]interface{}{
|
||||||
"html": stdHTML,
|
"html": stdHTML,
|
||||||
"outline": outline,
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -38,8 +38,13 @@ func getDocOutline(c *gin.Context) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
preview := false
|
||||||
|
if previewArg := arg["preview"]; nil != previewArg {
|
||||||
|
preview = previewArg.(bool)
|
||||||
|
}
|
||||||
|
|
||||||
rootID := arg["id"].(string)
|
rootID := arg["id"].(string)
|
||||||
headings, err := model.Outline(rootID)
|
headings, err := model.Outline(rootID, preview)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ret.Code = 1
|
ret.Code = 1
|
||||||
ret.Msg = err.Error()
|
ret.Msg = err.Error()
|
||||||
|
|
|
||||||
|
|
@ -567,7 +567,7 @@ func ExportResources(resourcePaths []string, mainName string) (exportFilePath st
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func Preview(id string) (retStdHTML string, retOutline []*Path) {
|
func Preview(id string) (retStdHTML string) {
|
||||||
tree, _ := LoadTreeByBlockID(id)
|
tree, _ := LoadTreeByBlockID(id)
|
||||||
tree = exportTree(tree, false, false, true,
|
tree = exportTree(tree, false, false, true,
|
||||||
Conf.Export.BlockRefMode, Conf.Export.BlockEmbedMode, Conf.Export.FileAnnotationRefMode,
|
Conf.Export.BlockRefMode, Conf.Export.BlockEmbedMode, Conf.Export.FileAnnotationRefMode,
|
||||||
|
|
@ -586,7 +586,6 @@ func Preview(id string) (retStdHTML string, retOutline []*Path) {
|
||||||
if footnotesDefBlock := tree.Root.ChildByType(ast.NodeFootnotesDefBlock); nil != footnotesDefBlock {
|
if footnotesDefBlock := tree.Root.ChildByType(ast.NodeFootnotesDefBlock); nil != footnotesDefBlock {
|
||||||
footnotesDefBlock.Unlink()
|
footnotesDefBlock.Unlink()
|
||||||
}
|
}
|
||||||
retOutline = outline(tree)
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -17,6 +17,7 @@
|
||||||
package model
|
package model
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"github.com/88250/lute/html"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/88250/lute/ast"
|
"github.com/88250/lute/ast"
|
||||||
|
|
@ -207,7 +208,7 @@ func (tx *Transaction) doMoveOutlineHeading(operation *Operation) (ret *TxErr) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func Outline(rootID string) (ret []*Path, err error) {
|
func Outline(rootID string, preview bool) (ret []*Path, err error) {
|
||||||
time.Sleep(util.FrontendQueueInterval)
|
time.Sleep(util.FrontendQueueInterval)
|
||||||
WaitForWritingFiles()
|
WaitForWritingFiles()
|
||||||
|
|
||||||
|
|
@ -217,6 +218,24 @@ func Outline(rootID string) (ret []*Path, err error) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if preview && Conf.Export.AddTitle {
|
||||||
|
if root, _ := getBlock(tree.ID, tree); nil != root {
|
||||||
|
root.IAL["type"] = "doc"
|
||||||
|
title := &ast.Node{Type: ast.NodeHeading, HeadingLevel: 1}
|
||||||
|
for k, v := range root.IAL {
|
||||||
|
if "type" == k {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
title.SetIALAttr(k, v)
|
||||||
|
}
|
||||||
|
title.InsertAfter(&ast.Node{Type: ast.NodeKramdownBlockIAL, Tokens: parse.IAL2Tokens(title.KramdownIAL)})
|
||||||
|
|
||||||
|
content := html.UnescapeString(root.Content)
|
||||||
|
title.AppendChild(&ast.Node{Type: ast.NodeText, Tokens: []byte(content)})
|
||||||
|
tree.Root.PrependChild(title)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
ret = outline(tree)
|
ret = outline(tree)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue