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

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