Skip to content

An open-source, privacy-first, self-hosted knowledge workspace where humans and AI agents work together 开源、隐私优先、自托管的知识工作空间,让人与智能体在此协作

:art: 支持设置 `虚拟引用关键字包含列表` https://github.com/siyuan-note/siyuan/issues/6354

Liang Dingfe7b98d1a903
diff --git a/app/appearance/langs/en_US.json b/app/appearance/langs/en_US.json
index 8d42bb2047..e255de83de 100644
--- a/app/appearance/langs/en_US.json
+++ b/app/appearance/langs/en_US.json
@@ -573,6 +573,7 @@
"md4": "Automatically indent the beginning of paragraphs to conform to traditional Chinese typesetting habits",
"md7": "Whether to display the network picture corner mark",
"md8": "After enabling, if the picture is a web file (non-local asset file), it will display a corner mark",
+ "md9": "Virtual Reference keyword inclusion list",
"md12": "Whether to display bookmark, name, alias, memo and reference count",
"md16": "After enabling, if there is such information, it will be displayed on the upper right side of the block",
"md27": "The code block shows the line number",
diff --git a/app/appearance/langs/es_ES.json b/app/appearance/langs/es_ES.json
index 8d85f4f6b0..62c9cacce0 100644
--- a/app/appearance/langs/es_ES.json
+++ b/app/appearance/langs/es_ES.json
@@ -573,6 +573,7 @@
"md4": "Sangria automáticamente el comienzo de los párrafos para ajustarse a los hábitos tipográficos tradicionales chinos",
"md7": "Mostrar la marca de esquina de la imagen de red",
"md8": "Después de habilitarlo, si la imagen es un archivo de red (archivo de activos no locales), mostrará una marca de esquina",
+ "md9": "Lista de inclusión de palabras clave de referencia virtual",
"md12": "Mostrar el marcador, el nombre, el alias, el memo y el recuento de referencias",
"md16": "Una vez habilitado, si existe dicha información, se mostrará en la parte superior derecha del bloque",
"md27": "El bloque de código muestra el número de línea",
diff --git a/app/appearance/langs/fr_FR.json b/app/appearance/langs/fr_FR.json
index 57a31ffadc..ce7d1b0be9 100644
--- a/app/appearance/langs/fr_FR.json
+++ b/app/appearance/langs/fr_FR.json
@@ -573,6 +573,7 @@
"md4": "indenter automatiquement le début des paragraphes pour se conformer aux habitudes de composition traditionnelles chinoises.",
"md7": "Affichage ou non de la marque d'angle de l'image réseau",
"md8": "Après l'activation, si l'image est un fichier web (fichier d'actif non local), une marque d'angle apparaîtra.",
+ "md9": "Liste d'inclusion de mots-clés de référence virtuelle",
"md12": "Affichage ou non du nombre de signets, de noms, d'alias, de mémos et de références.",
"md16": "Après l'activation, si de telles informations existent, elles seront affichées dans la partie haute à droite du bloc.",
"md27": "Le bloc de code indique le numéro de ligne",
diff --git a/app/appearance/langs/zh_CHT.json b/app/appearance/langs/zh_CHT.json
index 418a62d038..568a7a7979 100644
--- a/app/appearance/langs/zh_CHT.json
+++ b/app/appearance/langs/zh_CHT.json
@@ -573,6 +573,7 @@
"md4": "自動進行段首縮進,以符合傳統中文排版習慣",
"md7": "是否顯示網路圖片角標",
"md8": "啟用後如果圖片是網路檔(非本地資源檔)則會顯示角標",
+ "md9": "虛擬引用關鍵字包含列表",
"md12": "是否顯示書簽、命名、別名、備註和引用計數",
"md16": "啟用後如果存在這些資訊則將在塊的右上側進行顯示",
"md27": "代碼塊顯示行號",
diff --git a/app/appearance/langs/zh_CN.json b/app/appearance/langs/zh_CN.json
index aa1fcf6985..0c0c1ed090 100644
--- a/app/appearance/langs/zh_CN.json
+++ b/app/appearance/langs/zh_CN.json
@@ -573,6 +573,7 @@
"md4": "自动进行段首缩进,以符合传统中文排版习惯",
"md7": "是否显示网络图片角标",
"md8": "启用后如果图片是网络文件(非本地资源文件)则会显示角标",
+ "md9": "虚拟引用关键字包含列表",
"md12": "是否显示书签、命名、别名、备注和引用计数",
"md16": "启用后如果存在这些信息则将在块的右上侧进行显示",
"md27": "代码块显示行号",
diff --git a/app/src/config/editor.ts b/app/src/config/editor.ts
index 8dc5b6a910..761d3a5e68 100644
--- a/app/src/config/editor.ts
+++ b/app/src/config/editor.ts
@@ -140,6 +140,14 @@ export const editor = {
<span class="fn__space"></span>
<input class="b3-switch fn__flex-center" id="virtualBlockRef" type="checkbox"${window.siyuan.config.editor.virtualBlockRef ? " checked" : ""}/>
</label>
+<label class="fn__flex b3-label">
+ <div class="fn__flex-1">
+ ${window.siyuan.languages.md9}
+ <div class="b3-label__text">${window.siyuan.languages.md36}</div>
+ </div>
+ <span class="fn__space"></span>
+ <input class="b3-text-field fn__flex-center fn__size200" id="virtualBlockRefInclude" value="${window.siyuan.config.editor.virtualBlockRefInclude}" />
+</label>
<label class="fn__flex b3-label">
<div class="fn__flex-1">
${window.siyuan.languages.md35}
@@ -248,6 +256,7 @@ export const editor = {
katexMacros: (editor.element.querySelector("#katexMacros") as HTMLTextAreaElement).value,
codeLineWrap: (editor.element.querySelector("#codeLineWrap") as HTMLInputElement).checked,
virtualBlockRef: (editor.element.querySelector("#virtualBlockRef") as HTMLInputElement).checked,
+ virtualBlockRefInclude: (editor.element.querySelector("#virtualBlockRefInclude") as HTMLInputElement).value,
virtualBlockRefExclude: (editor.element.querySelector("#virtualBlockRefExclude") as HTMLInputElement).value,
blockRefDynamicAnchorTextMaxLen: parseInt((editor.element.querySelector("#blockRefDynamicAnchorTextMaxLen") as HTMLInputElement).value),
codeLigatures: (editor.element.querySelector("#codeLigatures") as HTMLInputElement).checked,
diff --git a/app/src/types/index.d.ts b/app/src/types/index.d.ts
index 766a5726d8..b9e8e3ae5d 100644
--- a/app/src/types/index.d.ts
+++ b/app/src/types/index.d.ts
@@ -249,6 +249,7 @@ declare interface IEditor {
fontFamily: string;
virtualBlockRef: string;
virtualBlockRefExclude: string;
+ virtualBlockRefInclude: string;
blockRefDynamicAnchorTextMaxLen: number;
emoji: string[];
diff --git a/kernel/conf/editor.go b/kernel/conf/editor.go
index 8517617a73..fe64c87aaf 100644
--- a/kernel/conf/editor.go
+++ b/kernel/conf/editor.go
@@ -30,6 +30,7 @@ type Editor struct {
Emoji []string `json:"emoji"` // 常用表情
VirtualBlockRef bool `json:"virtualBlockRef"` // 是否启用虚拟引用
VirtualBlockRefExclude string `json:"virtualBlockRefExclude"` // 虚拟引用关键字排除列表
+ VirtualBlockRefInclude string `json:"virtualBlockRefInclude"` // 虚拟引用关键字包含列表
BlockRefDynamicAnchorTextMaxLen int `json:"blockRefDynamicAnchorTextMaxLen"` // 块引动态锚文本最大长度
PlantUMLServePath string `json:"plantUMLServePath"` // PlantUML 伺服地址
FullWidth bool `json:"fullWidth"` // 是否使用最大宽度
diff --git a/kernel/model/file.go b/kernel/model/file.go
index da6bd4c202..bf4f6ae83f 100644
--- a/kernel/model/file.go
+++ b/kernel/model/file.go
@@ -602,19 +602,7 @@ func GetDoc(startID, endID, id string, index int, keyword string, mode int, size
var virtualBlockRefKeywords []string
if Conf.Editor.VirtualBlockRef {
- virtualBlockRefKeywords = sql.QueryVirtualRefKeywords(Conf.Search.VirtualRefName, Conf.Search.VirtualRefAlias, Conf.Search.VirtualRefAnchor, Conf.Search.VirtualRefDoc)
- if "" != strings.TrimSpace(Conf.Editor.VirtualBlockRefExclude) {
- exclude := strings.ReplaceAll(Conf.Editor.VirtualBlockRefExclude, "\\,", "__comma@sep__")
- excludes := strings.Split(exclude, ",")
- var tmp []string
- for _, e := range excludes {
- e = strings.ReplaceAll(e, "__comma@sep__", ",")
- tmp = append(tmp, e)
- }
- excludes = tmp
- virtualBlockRefKeywords = gulu.Str.ExcludeElem(virtualBlockRefKeywords, excludes)
- }
-
+ virtualBlockRefKeywords = getVirtualRefKeywords()
// 虚拟引用排除当前文档名 https://github.com/siyuan-note/siyuan/issues/4537
virtualBlockRefKeywords = gulu.Str.ExcludeElem(virtualBlockRefKeywords, []string{tree.Root.IALAttr("title")})
virtualBlockRefKeywords = prepareMarkKeywords(virtualBlockRefKeywords)
diff --git a/kernel/model/virutalref.go b/kernel/model/virutalref.go
new file mode 100644
index 0000000000..43f9058edb
--- /dev/null
+++ b/kernel/model/virutalref.go
@@ -0,0 +1,53 @@
+// SiYuan - Build Your Eternal Digital Garden
+// Copyright (c) 2020-present, b3log.org
+//
+// This program is free software: you can redistribute it and/or modify
+// it under the terms of the GNU Affero General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU Affero General Public License for more details.
+//
+// You should have received a copy of the GNU Affero General Public License
+// along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+package model
+
+import (
+ "strings"
+
+ "github.com/88250/gulu"
+ "github.com/siyuan-note/siyuan/kernel/sql"
+)
+
+func getVirtualRefKeywords() (ret []string) {
+ ret = sql.QueryVirtualRefKeywords(Conf.Search.VirtualRefName, Conf.Search.VirtualRefAlias, Conf.Search.VirtualRefAnchor, Conf.Search.VirtualRefDoc)
+ if "" != strings.TrimSpace(Conf.Editor.VirtualBlockRefInclude) {
+ include := strings.ReplaceAll(Conf.Editor.VirtualBlockRefInclude, "\\,", "__comma@sep__")
+ includes := strings.Split(include, ",")
+ var tmp []string
+ for _, e := range includes {
+ e = strings.ReplaceAll(e, "__comma@sep__", ",")
+ tmp = append(tmp, e)
+ }
+ includes = tmp
+ ret = append(ret, includes...)
+ ret = gulu.Str.RemoveDuplicatedElem(ret)
+ }
+
+ if "" != strings.TrimSpace(Conf.Editor.VirtualBlockRefExclude) {
+ exclude := strings.ReplaceAll(Conf.Editor.VirtualBlockRefExclude, "\\,", "__comma@sep__")
+ excludes := strings.Split(exclude, ",")
+ var tmp []string
+ for _, e := range excludes {
+ e = strings.ReplaceAll(e, "__comma@sep__", ",")
+ tmp = append(tmp, e)
+ }
+ excludes = tmp
+ ret = gulu.Str.ExcludeElem(ret, excludes)
+ }
+ return
+}