mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-12-22 17:40:13 +01:00
🎨 表 blocks 新增 fmarkdown 字段 https://github.com/siyuan-note/siyuan/issues/5720
This commit is contained in:
parent
04e7a931f3
commit
8391638731
8 changed files with 103 additions and 96 deletions
|
|
@ -66,6 +66,7 @@ func InitDatabase(forceRebuild bool) (err error) {
|
|||
if util.DatabaseVer == getDatabaseVer() {
|
||||
return
|
||||
}
|
||||
logging.LogInfof("the database structure is changed, rebuilding database...")
|
||||
}
|
||||
|
||||
// 不存在库或者版本不一致都会走到这里
|
||||
|
|
@ -98,19 +99,19 @@ func initDBTables() {
|
|||
setDatabaseVer()
|
||||
|
||||
db.Exec("DROP TABLE blocks")
|
||||
_, err = db.Exec("CREATE TABLE blocks (id, parent_id, root_id, hash, box, path, hpath, name, alias, memo, tag, content, fcontent, markdown, length, type, subtype, ial, sort, created, updated)")
|
||||
_, err = db.Exec("CREATE TABLE blocks (id, parent_id, root_id, hash, box, path, hpath, name, alias, memo, tag, content, fcontent, markdown, fmarkdown, length, type, subtype, ial, sort, created, updated)")
|
||||
if nil != err {
|
||||
logging.LogFatalf("create table [blocks] failed: %s", err)
|
||||
}
|
||||
|
||||
db.Exec("DROP TABLE blocks_fts")
|
||||
_, err = db.Exec("CREATE VIRTUAL TABLE blocks_fts USING fts5(id UNINDEXED, parent_id UNINDEXED, root_id UNINDEXED, hash UNINDEXED, box UNINDEXED, path UNINDEXED, hpath, name, alias, memo, tag, content, fcontent, markdown UNINDEXED, length UNINDEXED, type UNINDEXED, subtype UNINDEXED, ial, sort UNINDEXED, created UNINDEXED, updated UNINDEXED, tokenize=\"siyuan\")")
|
||||
_, err = db.Exec("CREATE VIRTUAL TABLE blocks_fts USING fts5(id UNINDEXED, parent_id UNINDEXED, root_id UNINDEXED, hash UNINDEXED, box UNINDEXED, path UNINDEXED, hpath, name, alias, memo, tag, content, fcontent, markdown UNINDEXED, fmarkdown UNINDEXED, length UNINDEXED, type UNINDEXED, subtype UNINDEXED, ial, sort UNINDEXED, created UNINDEXED, updated UNINDEXED, tokenize=\"siyuan\")")
|
||||
if nil != err {
|
||||
logging.LogFatalf("create table [blocks_fts] failed: %s", err)
|
||||
}
|
||||
|
||||
db.Exec("DROP TABLE blocks_fts_case_insensitive")
|
||||
_, err = db.Exec("CREATE VIRTUAL TABLE blocks_fts_case_insensitive USING fts5(id UNINDEXED, parent_id UNINDEXED, root_id UNINDEXED, hash UNINDEXED, box UNINDEXED, path UNINDEXED, hpath, name, alias, memo, tag, content, fcontent, markdown UNINDEXED, length UNINDEXED, type UNINDEXED, subtype UNINDEXED, ial, sort UNINDEXED, created UNINDEXED, updated UNINDEXED, tokenize=\"siyuan case_insensitive\")")
|
||||
_, err = db.Exec("CREATE VIRTUAL TABLE blocks_fts_case_insensitive USING fts5(id UNINDEXED, parent_id UNINDEXED, root_id UNINDEXED, hash UNINDEXED, box UNINDEXED, path UNINDEXED, hpath, name, alias, memo, tag, content, fcontent, markdown UNINDEXED, fmarkdown UNINDEXED, length UNINDEXED, type UNINDEXED, subtype UNINDEXED, ial, sort UNINDEXED, created UNINDEXED, updated UNINDEXED, tokenize=\"siyuan case_insensitive\")")
|
||||
if nil != err {
|
||||
logging.LogFatalf("create table [blocks_fts_case_insensitive] failed: %s", err)
|
||||
}
|
||||
|
|
@ -711,18 +712,19 @@ func buildBlockFromNode(n *ast.Node, tree *parse.Tree) (block *Block, attributes
|
|||
memo := html.UnescapeString(n.IALAttr("memo"))
|
||||
tag := tagFromNode(n)
|
||||
|
||||
var content, fcontent, markdown, parentID string
|
||||
var content, fcontent, markdown, fmarkdown, parentID string
|
||||
ialContent := treenode.IALStr(n)
|
||||
hash := treenode.NodeHash(n, tree, luteEngine)
|
||||
var length int
|
||||
if ast.NodeDocument == n.Type {
|
||||
content = n.IALAttr("title")
|
||||
fcontent = content
|
||||
fmarkdown = content
|
||||
length = utf8.RuneCountInString(fcontent)
|
||||
} else if n.IsContainerBlock() {
|
||||
markdown, content = treenode.NodeStaticMdContent(n, luteEngine)
|
||||
fc := treenode.FirstLeafBlock(n)
|
||||
fcontent = treenode.NodeStaticContent(fc)
|
||||
fmarkdown, fcontent = treenode.NodeStaticMdContent(fc, luteEngine)
|
||||
parentID = n.Parent.ID
|
||||
// 将标题块作为父节点
|
||||
if h := heading(n); nil != h {
|
||||
|
|
@ -740,27 +742,28 @@ func buildBlockFromNode(n *ast.Node, tree *parse.Tree) (block *Block, attributes
|
|||
}
|
||||
|
||||
block = &Block{
|
||||
ID: n.ID,
|
||||
ParentID: parentID,
|
||||
RootID: rootID,
|
||||
Hash: hash,
|
||||
Box: boxID,
|
||||
Path: p,
|
||||
HPath: tree.HPath,
|
||||
Name: name,
|
||||
Alias: alias,
|
||||
Memo: memo,
|
||||
Tag: tag,
|
||||
Content: content,
|
||||
FContent: fcontent,
|
||||
Markdown: markdown,
|
||||
Length: length,
|
||||
Type: treenode.TypeAbbr(n.Type.String()),
|
||||
SubType: treenode.SubTypeAbbr(n),
|
||||
IAL: ialContent,
|
||||
Sort: nSort(n),
|
||||
Created: util.TimeFromID(n.ID),
|
||||
Updated: n.IALAttr("updated"),
|
||||
ID: n.ID,
|
||||
ParentID: parentID,
|
||||
RootID: rootID,
|
||||
Hash: hash,
|
||||
Box: boxID,
|
||||
Path: p,
|
||||
HPath: tree.HPath,
|
||||
Name: name,
|
||||
Alias: alias,
|
||||
Memo: memo,
|
||||
Tag: tag,
|
||||
Content: content,
|
||||
FContent: fcontent,
|
||||
Markdown: markdown,
|
||||
FMarkdown: fmarkdown,
|
||||
Length: length,
|
||||
Type: treenode.TypeAbbr(n.Type.String()),
|
||||
SubType: treenode.SubTypeAbbr(n),
|
||||
IAL: ialContent,
|
||||
Sort: nSort(n),
|
||||
Created: util.TimeFromID(n.ID),
|
||||
Updated: n.IALAttr("updated"),
|
||||
}
|
||||
|
||||
attrs := parse.IAL2Map(n.KramdownIAL)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue