mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-12-20 16:40:13 +01:00
🎨 桌面端支持搜索图片中的文本 Fix https://github.com/siyuan-note/siyuan/issues/3470
This commit is contained in:
parent
968bcd433e
commit
db810d6a4b
3 changed files with 122 additions and 1 deletions
|
|
@ -18,10 +18,11 @@ package treenode
|
|||
|
||||
import (
|
||||
"bytes"
|
||||
"github.com/88250/gulu"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"sync"
|
||||
|
||||
"github.com/88250/gulu"
|
||||
"github.com/88250/lute"
|
||||
"github.com/88250/lute/ast"
|
||||
"github.com/88250/lute/editor"
|
||||
|
|
@ -31,6 +32,7 @@ import (
|
|||
"github.com/88250/lute/render"
|
||||
"github.com/88250/lute/util"
|
||||
"github.com/siyuan-note/logging"
|
||||
util2 "github.com/siyuan-note/siyuan/kernel/util"
|
||||
)
|
||||
|
||||
func GetBlockRef(n *ast.Node) (blockRefID, blockRefText, blockRefSubtype string) {
|
||||
|
|
@ -107,6 +109,19 @@ func NodeStaticContent(node *ast.Node, excludeTypes []string) string {
|
|||
switch n.Type {
|
||||
case ast.NodeLinkText:
|
||||
buf.Write(n.Tokens)
|
||||
|
||||
if nil != n.Parent && ast.NodeImage == n.Parent.Type {
|
||||
destNode := n.Parent.ChildByType(ast.NodeLinkDest)
|
||||
if nil != destNode {
|
||||
// 桌面端支持搜索图片中的文本 https://github.com/siyuan-note/siyuan/issues/3470
|
||||
// 尝试 OCR 识别图片中的文字并作为图片的 alt
|
||||
if text := util2.Tesseract(filepath.Join(util2.DataDir, destNode.TokensStr())); "" != text {
|
||||
buf.WriteByte(' ')
|
||||
buf.WriteString(text)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
buf.WriteByte(' ')
|
||||
case ast.NodeLinkDest:
|
||||
buf.Write(n.Tokens)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue