This commit is contained in:
Daniel 2024-09-18 11:28:04 +08:00
parent 4f31068205
commit 827819ef67
No known key found for this signature in database
GPG key ID: 86211BA83DF03017
4 changed files with 29 additions and 7 deletions

View file

@ -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,
} }
} }

View file

@ -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()

View file

@ -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
} }

View file

@ -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
} }