mirror of
https://github.com/siyuan-note/siyuan.git
synced 2026-01-23 00:36:10 +01:00
🎨 Preview mode supports jumping through the outline panel https://github.com/siyuan-note/siyuan/issues/3059
This commit is contained in:
parent
78ff4a0963
commit
f4982d2cd6
7 changed files with 28 additions and 14 deletions
|
|
@ -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
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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) {
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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 {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue