Forráskód Böngészése

Fix the index task of the embedded block (#11154)

* :bug: Fix query embed block javascript

* Update index.go

* Update index.go
Yingyi / 颖逸 1 éve
szülő
commit
e2c14eb11f
1 módosított fájl, 13 hozzáadás és 4 törlés
  1. 13 4
      kernel/model/index.go

+ 13 - 4
kernel/model/index.go

@@ -30,6 +30,7 @@ import (
 	"github.com/88250/go-humanize"
 	"github.com/88250/gulu"
 	"github.com/88250/lute/ast"
+	"github.com/88250/lute/editor"
 	"github.com/88250/lute/html"
 	"github.com/88250/lute/parse"
 	"github.com/panjf2000/ants/v2"
@@ -289,14 +290,22 @@ func IndexEmbedBlockJob() {
 
 func autoIndexEmbedBlock(embedBlocks []*sql.Block) {
 	for i, embedBlock := range embedBlocks {
-		md := strings.TrimSpace(embedBlock.Markdown)
-		if strings.Contains(md, "//js") {
+		markdown := strings.TrimSpace(embedBlock.Markdown)
+		markdown = strings.TrimPrefix(markdown, "{{")
+		stmt := strings.TrimSuffix(markdown, "}}")
+
+		// 嵌入块的 Markdown 内容需要反转义
+		stmt = html.UnescapeString(stmt)
+		stmt = strings.ReplaceAll(stmt, editor.IALValEscNewLine, "\n")
+
+		// 需要移除首尾的空白字符以判断是否具有 //!js 标记
+		stmt = strings.TrimSpace(stmt)
+		if strings.HasPrefix(stmt, "//!js") {
+			// https://github.com/siyuan-note/siyuan/issues/9648
 			// js 嵌入块不支持自动索引,由前端主动调用 /api/search/updateEmbedBlock 接口更新内容 https://github.com/siyuan-note/siyuan/issues/9736
 			continue
 		}
 
-		stmt := strings.TrimPrefix(md, "{{")
-		stmt = strings.TrimSuffix(stmt, "}}")
 		if !strings.Contains(strings.ToLower(stmt), "select") {
 			continue
 		}