🎨 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)
|
||||
stdHTML, outline := model.Preview(id)
|
||||
stdHTML := model.Preview(id)
|
||||
ret.Data = map[string]interface{}{
|
||||
"html": stdHTML,
|
||||
"outline": outline,
|
||||
"html": stdHTML,
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -38,8 +38,13 @@ func getDocOutline(c *gin.Context) {
|
|||
return
|
||||
}
|
||||
|
||||
preview := false
|
||||
if previewArg := arg["preview"]; nil != previewArg {
|
||||
preview = previewArg.(bool)
|
||||
}
|
||||
|
||||
rootID := arg["id"].(string)
|
||||
headings, err := model.Outline(rootID)
|
||||
headings, err := model.Outline(rootID, preview)
|
||||
if err != nil {
|
||||
ret.Code = 1
|
||||
ret.Msg = err.Error()
|
||||
|
|
|
@ -567,7 +567,7 @@ func ExportResources(resourcePaths []string, mainName string) (exportFilePath st
|
|||
return
|
||||
}
|
||||
|
||||
func Preview(id string) (retStdHTML string, retOutline []*Path) {
|
||||
func Preview(id string) (retStdHTML string) {
|
||||
tree, _ := LoadTreeByBlockID(id)
|
||||
tree = exportTree(tree, false, false, true,
|
||||
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 {
|
||||
footnotesDefBlock.Unlink()
|
||||
}
|
||||
retOutline = outline(tree)
|
||||
return
|
||||
}
|
||||
|
||||
|
|
|
@ -17,6 +17,7 @@
|
|||
package model
|
||||
|
||||
import (
|
||||
"github.com/88250/lute/html"
|
||||
"time"
|
||||
|
||||
"github.com/88250/lute/ast"
|
||||
|
@ -207,7 +208,7 @@ func (tx *Transaction) doMoveOutlineHeading(operation *Operation) (ret *TxErr) {
|
|||
return
|
||||
}
|
||||
|
||||
func Outline(rootID string) (ret []*Path, err error) {
|
||||
func Outline(rootID string, preview bool) (ret []*Path, err error) {
|
||||
time.Sleep(util.FrontendQueueInterval)
|
||||
WaitForWritingFiles()
|
||||
|
||||
|
@ -217,6 +218,24 @@ func Outline(rootID string) (ret []*Path, err error) {
|
|||
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)
|
||||
return
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue