🎨 Preview mode supports jumping through the outline panel https://github.com/siyuan-note/siyuan/issues/3059

This commit is contained in:
Daniel 2023-06-17 15:49:16 +08:00
parent 78ff4a0963
commit f4982d2cd6
No known key found for this signature in database
GPG key ID: 86211BA83DF03017
7 changed files with 28 additions and 14 deletions

View file

@ -498,9 +498,10 @@ func exportPreview(c *gin.Context) {
}
id := arg["id"].(string)
stdHTML := model.Preview(id)
stdHTML, outline := model.Preview(id)
ret.Data = map[string]interface{}{
"html": stdHTML,
"html": stdHTML,
"outline": outline,
}
}

View file

@ -6,7 +6,7 @@ require (
github.com/88250/clipboard v0.1.5
github.com/88250/css v0.1.2
github.com/88250/gulu v1.2.3-0.20230615033005-b519d6875346
github.com/88250/lute v1.7.6-0.20230608014232-e10343eb445d
github.com/88250/lute v1.7.6-0.20230617074457-ffab89d50887
github.com/88250/pdfcpu v0.3.14-0.20230401044135-c7369a99720c
github.com/88250/vitess-sqlparser v0.0.0-20210205111146-56a2ded2aba1
github.com/ClarkThan/ahocorasick v0.0.0-20230220142845-f237b6348b3e

View file

@ -8,8 +8,8 @@ github.com/88250/go-sqlite3 v1.14.13-0.20220714142610-fbbda1ee84f5 h1:8HdZozCsXS
github.com/88250/go-sqlite3 v1.14.13-0.20220714142610-fbbda1ee84f5/go.mod h1:NyWgC/yNuGj7Q9rpYnZvas74GogHl5/Z4A/KQRfk6bU=
github.com/88250/gulu v1.2.3-0.20230615033005-b519d6875346 h1:U0wZN6zuf+vUhzdHC6DbZE/bY5FUt3FuCwn/KgObV44=
github.com/88250/gulu v1.2.3-0.20230615033005-b519d6875346/go.mod h1:pTWnjt+6qUqNnP9xltswsJxgCBVu3C7eW09u48LWX0k=
github.com/88250/lute v1.7.6-0.20230608014232-e10343eb445d h1:D3HPp3lcibUYqq6hu/dPP6rx+To23VyE96eMBhwFoNg=
github.com/88250/lute v1.7.6-0.20230608014232-e10343eb445d/go.mod h1:+wUqx/1kdFDbWtxn9LYJlaCOAeol2pjSO6w+WJTVQsg=
github.com/88250/lute v1.7.6-0.20230617074457-ffab89d50887 h1:jIOA18lMo4DOdF3K66lu4DCOhgrfeHTNY710cXuPkL0=
github.com/88250/lute v1.7.6-0.20230617074457-ffab89d50887/go.mod h1:+wUqx/1kdFDbWtxn9LYJlaCOAeol2pjSO6w+WJTVQsg=
github.com/88250/pdfcpu v0.3.14-0.20230401044135-c7369a99720c h1:Dl/8S9iLyPMTElnWIBxmjaLiWrkI5P4a21ivwAn5pU0=
github.com/88250/pdfcpu v0.3.14-0.20230401044135-c7369a99720c/go.mod h1:S5YT38L/GCjVjmB4PB84PymA1qfopjEhfhTNQilLpv4=
github.com/88250/vitess-sqlparser v0.0.0-20210205111146-56a2ded2aba1 h1:48T899JQDwyyRu9yXHePYlPdHtpJfrJEUGBMH3SMBWY=

View file

@ -252,7 +252,7 @@ func GetBacklink2(id, keyword, mentionKeyword string, sortMode, mentionSortMode
refs = removeDuplicatedRefs(refs) // 同一个块中引用多个相同块时反链去重 https://github.com/siyuan-note/siyuan/issues/3317
linkRefs, linkRefsCount, excludeBacklinkIDs := buildLinkRefs(rootID, refs, keyword)
tmpBacklinks := toFlatTree(linkRefs, 0, "backlink")
tmpBacklinks := toFlatTree(linkRefs, 0, "backlink", nil)
for _, l := range tmpBacklinks {
l.Blocks = nil
@ -282,7 +282,7 @@ func GetBacklink2(id, keyword, mentionKeyword string, sortMode, mentionSortMode
})
mentionRefs, _ := buildTreeBackmention(sqlBlock, linkRefs, mentionKeyword, excludeBacklinkIDs, 12)
tmpBackmentions := toFlatTree(mentionRefs, 0, "backlink")
tmpBackmentions := toFlatTree(mentionRefs, 0, "backlink", nil)
for _, l := range tmpBackmentions {
l.Blocks = nil
backmentions = append(backmentions, l)
@ -442,7 +442,7 @@ func GetBacklink(id, keyword, mentionKeyword string, beforeLen int) (boxID strin
mentions, _ := buildTreeBackmention(sqlBlock, linkRefs, mentionKeyword, excludeBacklinkIDs, beforeLen)
mentionsCount = len(mentions)
mentionPaths = toFlatTree(mentions, 0, "backlink")
mentionPaths = toFlatTree(mentions, 0, "backlink", nil)
return
}

View file

@ -318,7 +318,7 @@ func exportData(exportFolder string) (zipPath string, err error) {
return
}
func Preview(id string) string {
func Preview(id string) (retStdHTML string, retOutline []*Path) {
tree, _ := loadTreeByBlockID(id)
tree = exportTree(tree, false, false, false,
Conf.Export.BlockRefMode, Conf.Export.BlockEmbedMode, Conf.Export.FileAnnotationRefMode,
@ -329,7 +329,13 @@ func Preview(id string) string {
luteEngine.SetFootnotes(true)
md := treenode.FormatNode(tree.Root, luteEngine)
tree = parse.Parse("", []byte(md), luteEngine.ParseOptions)
return luteEngine.ProtylePreview(tree, luteEngine.RenderOptions)
retStdHTML = luteEngine.ProtylePreview(tree, luteEngine.RenderOptions)
if footnotesDefBlock := tree.Root.ChildByType(ast.NodeFootnotesDefBlock); nil != footnotesDefBlock {
footnotesDefBlock.Unlink()
}
retOutline = outline(tree)
return
}
func ExportDocx(id, savePath string, removeAssets, merge bool) (err error) {

View file

@ -20,6 +20,7 @@ import (
"time"
"github.com/88250/lute/ast"
"github.com/88250/lute/parse"
"github.com/emirpasic/gods/stacks/linkedliststack"
"github.com/siyuan-note/siyuan/kernel/treenode"
"github.com/siyuan-note/siyuan/kernel/util"
@ -35,13 +36,18 @@ func Outline(rootID string) (ret []*Path, err error) {
return
}
ret = outline(tree)
return
}
func outline(tree *parse.Tree) (ret []*Path) {
luteEngine := NewLute()
var headings []*Block
ast.Walk(tree.Root, func(n *ast.Node, entering bool) ast.WalkStatus {
if entering && ast.NodeHeading == n.Type && !n.ParentIs(ast.NodeBlockquote) {
n.Box, n.Path = tree.Box, tree.Path
block := &Block{
RootID: rootID,
RootID: tree.Root.ID,
Depth: n.HeadingLevel,
Box: n.Box,
Path: n.Path,
@ -82,7 +88,7 @@ func Outline(rootID string) (ret []*Path, err error) {
}
}
ret = toFlatTree(blocks, 0, "outline")
ret = toFlatTree(blocks, 0, "outline", tree)
if 0 < len(ret) {
children := ret[0].Blocks
ret = nil

View file

@ -25,6 +25,7 @@ import (
"strings"
"github.com/88250/lute/ast"
"github.com/88250/lute/parse"
"github.com/siyuan-note/logging"
"github.com/siyuan-note/siyuan/kernel/search"
"github.com/siyuan-note/siyuan/kernel/sql"
@ -99,12 +100,12 @@ func createDocsByHPath(boxID, hPath, content, parentID string) (id string, exist
return
}
func toFlatTree(blocks []*Block, baseDepth int, typ string) (ret []*Path) {
func toFlatTree(blocks []*Block, baseDepth int, typ string, tree *parse.Tree) (ret []*Path) {
var blockRoots []*Block
for _, block := range blocks {
root := getBlockIn(blockRoots, block.RootID)
if nil == root {
root, _ = getBlock(block.RootID, nil)
root, _ = getBlock(block.RootID, tree)
blockRoots = append(blockRoots, root)
}
if nil == root {