mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-12-16 22:50:13 +01:00
Improve virtual reference keyword handling and support line breaks (#16298)
* 🎨 Improve virtual reference keyword handling and support line breaks https://ld246.com/article/1762474775795 * Update text
This commit is contained in:
parent
5ccb95ae4e
commit
f35761c1ab
18 changed files with 110 additions and 54 deletions
|
|
@ -1143,7 +1143,7 @@
|
|||
"md33": "المرجع الافتراضي",
|
||||
"md34": "بعد التمكين، سيحدد تلقائيا العلاقة المرجعية المحتملة وفقا للمعرف، الاسم المستعار ونص مرساة لمراجع الكتلة الموجودة",
|
||||
"md35": "قائمة استبعاد الكلمات المفتاحية المرجعية الافتراضية",
|
||||
"md36": "استخدم الفاصلة في وضع اللغة الإنجليزية <code class='fn__code'>,</code> للفصل، ويمكن إدراج الفاصلة نفسها باستخدام <code class='fn__code'>\\,</code>",
|
||||
"md36": "استخدم الفاصلة في وضع اللغة الإنجليزية <code class='fn__code'>,</code> أو فاصل سطر للفصل، ويمكن إدراج الفاصلة نفسها باستخدام <code class='fn__code'>\\,</code>",
|
||||
"md37": "الحد الأقصى لطول نص المرساة الديناميكي لمرجع الكتلة",
|
||||
"md38": "الحد الأقصى لطول نص المرساة الذي يتم تقديمه تلقائياً عند عدم تخصيص نص مرساة مرجع الكتلة، والافتراضي هو <code class='fn__code'>96</code> حرفاً",
|
||||
"md39": "عنوان خدمة PlantUML",
|
||||
|
|
|
|||
|
|
@ -1143,7 +1143,7 @@
|
|||
"md33": "Virtuelle Referenz",
|
||||
"md34": "Nach der Aktivierung wird sie automatisch mögliche Referenzbeziehungen nach Name, Alias und Ankertext des bestehenden Blockrefs erkennen.",
|
||||
"md35": "Virtuelle Referenz-Stichwort-Ausschlussliste",
|
||||
"md36": "Verwende das englische Komma <code class='fn__code'>,</code> zum Trennen, das Komma selbst kann mit <code class='fn__code'>\\,</code> escaped werden.",
|
||||
"md36": "Verwende das englische Komma <code class='fn__code'>,</code> oder Zeilenumbruch zum Trennen, das Komma selbst kann mit <code class='fn__code'>\\,</code> escaped werden.",
|
||||
"md37": "Die maximale Länge des dynamischen Ankertextes des Blockrefs",
|
||||
"md38": "Die maximale Länge des Ankertextes, die automatisch gerendert wird, wenn der Ankertext des Blockrefs nicht angepasst ist, beträgt standardmäßig <code class='fn__code'>96</code> Zeichen",
|
||||
"md39": "PlantUML-Serveradresse",
|
||||
|
|
|
|||
|
|
@ -1143,7 +1143,7 @@
|
|||
"md33": "Virtual Reference",
|
||||
"md34": "When enabled, it will automatically identify the possible reference relationship according to the name, alias and anchor text of the existing block ref",
|
||||
"md35": "Virtual Reference keyword exclusion list",
|
||||
"md36": "Use the English comma <code class='fn__code'>,</code> to separate, the comma itself can be escaped by <code class='fn__code'>\\,</code>",
|
||||
"md36": "Use the English comma <code class='fn__code'>,</code> or line break to separate, the comma itself can be escaped by <code class='fn__code'>\\,</code>",
|
||||
"md37": "The maximum length of block ref dynamic anchor text",
|
||||
"md38": "The maximum length of the anchor text that is automatically rendered when the block ref anchor text is not customized, the default is <code class='fn__code'>96</code> characters",
|
||||
"md39": "PlantUML Serve Address",
|
||||
|
|
|
|||
|
|
@ -1143,7 +1143,7 @@
|
|||
"md33": "Referencia virtual",
|
||||
"md34": "Una vez habilitado, identificará automáticamente la posible relación de referencia según el nombre, el alias y el texto de anclaje del bloque existente ref",
|
||||
"md35": "Lista de exclusión de palabras clave de referencia virtual",
|
||||
"md36": "Utilice la coma inglesa <code>,</code> para separar, la propia coma puede escaparse con <code class='fn__code'>\\,</code>",
|
||||
"md36": "Utilice la coma inglesa <code class='fn__code'>,</code> o salto de línea para separar, la propia coma puede escaparse con <code class='fn__code'>\\,</code>",
|
||||
"md37": "La longitud máxima del bloque de texto de anclaje dinámico",
|
||||
"md38": "La longitud máxima del texto de anclaje que se renderiza automáticamente cuando el texto de anclaje del bloque ref no está personalizado, el valor por defecto es <code class='fn__code'>96</code> caracteres",
|
||||
"md39": "Dirección de PlantUML Serve",
|
||||
|
|
|
|||
|
|
@ -1143,7 +1143,7 @@
|
|||
"md33": "Référence virtuelle",
|
||||
"md34": "Après ouverture, il identifiera automatiquement les relations de référence possibles en fonction du nom, de l'alias et du texte d'ancrage des guillemets de bloc existants",
|
||||
"md35": "Liste d'exclusion des mots-clés de la référence virtuelle",
|
||||
"md36": "Utiliser la virgule anglaise <code class='fn__code'>,</code> pour séparer, la virgule elle-même peut être échappée par <code class='fn__code'>\\,</code>",
|
||||
"md36": "Utiliser la virgule anglaise <code class='fn__code'>,</code> ou saut de ligne pour séparer, la virgule elle-même peut être échappée par <code class='fn__code'>\\,</code>",
|
||||
"md37": "La longueur maximale du texte d'ancrage dynamique de référence de bloc",
|
||||
"md38": "La longueur maximale du texte d'ancrage qui est automatiquement rendu lorsque le texte d'ancrage de la référence de bloc n'est pas personnalisé, la valeur par défaut est de <code class='fn__code'>96</code> caractères",
|
||||
"md39": "Adresse Servo PlantUML",
|
||||
|
|
|
|||
|
|
@ -1143,7 +1143,7 @@
|
|||
"md33": "הפניה וירטואלית",
|
||||
"md34": "לאחר הפעלת אפשרות זו, זה יזהה אוטומטית את הקשר ההפניה האפשרי לפי השם, הכינוי וטקסט העוגן של בלוק ההפניה הקיים",
|
||||
"md35": "סימני מילות מפתח של הפניה וירטואלית לא לכלול",
|
||||
"md36": "השתמש בסימן פסיק אנגלי <code class='fn__code'>,</code> להפריד, הפסיק עצמו יכול להתחמק על ידי <code class='fn__code'>\\,</code>",
|
||||
"md36": "השתמש בסימן פסיק אנגלי <code class='fn__code'>,</code> או מעבר שורה להפריד, הפסיק עצמו יכול להתחמק על ידי <code class='fn__code'>\\,</code>",
|
||||
"md37": "אורך מקסימלי של טקסט העוגן הדינמי של בלוק ההפניה",
|
||||
"md38": "אורך מקסימלי של טקסט העוגן שמוצג אוטומטית כאשר טקסט העוגן של בלוק ההפניה אינו מותאם אישית, ברירת המחדל היא <code class='fn__code'>96</code> תווים",
|
||||
"md39": "כתובת PlantUML Serve",
|
||||
|
|
|
|||
|
|
@ -1143,7 +1143,7 @@
|
|||
"md33": "Riferimento virtuale",
|
||||
"md34": "Dopo l'abilitazione, identificherà automaticamente la possibile relazione di riferimento in base al nome, alias e testo di ancoraggio del riferimento al blocco esistente",
|
||||
"md35": "Lista di esclusione delle parole chiave di riferimento virtuale",
|
||||
"md36": "Utilizzare la virgola inglese <code class='fn__code'>,</code> per separare, la virgola stessa può essere sfuggita con <code class='fn__code'>\\,</code>",
|
||||
"md36": "Utilizzare la virgola inglese <code class='fn__code'>,</code> o interruzione di riga per separare, la virgola stessa può essere sfuggita con <code class='fn__code'>\\,</code>",
|
||||
"md37": "Lunghezza massima del testo di ancoraggio dinamico del riferimento al blocco",
|
||||
"md38": "La lunghezza massima del testo di ancoraggio che viene automaticamente reso quando il testo di ancoraggio del riferimento al blocco non è personalizzato, il valore predefinito è <code class='fn__code'>96</code> caratteri",
|
||||
"md39": "Indirizzo del server PlantUML",
|
||||
|
|
|
|||
|
|
@ -1143,7 +1143,7 @@
|
|||
"md33": "仮想参照",
|
||||
"md34": "既存のブロック参照の名前、エイリアス、アンカーテキストに基づいて、考えられる参照関係を自動的に識別します",
|
||||
"md35": "仮想参照に含めないキーワードのリスト",
|
||||
"md36": "リストを区切るにはカンマ <code class='fn__code'>,</code> を使用します。カンマ自体は <code class='fn__code'>\\,</code> でエスケープできます",
|
||||
"md36": "リストを区切るにはカンマ <code class='fn__code'>,</code> または改行を使用します。カンマ自体は <code class='fn__code'>\\,</code> でエスケープできます",
|
||||
"md37": "ブロック参照の動的アンカーテキストの最大長",
|
||||
"md38": "ブロック参照のアンカーテキストをカスタマイズしていないときに自動的にレンダリングされるアンカーテキストの最大長。デフォルトは <code class='fn__code'>96</code> 文字です",
|
||||
"md39": "PlantUML サーバーアドレス",
|
||||
|
|
|
|||
|
|
@ -1143,7 +1143,7 @@
|
|||
"md33": "Wirtualna referencja",
|
||||
"md34": "Po włączeniu, automatycznie zidentyfikuje możliwą relację referencyjną według nazwy, aliasu i tekstu zakotwienia istniejącego odniesienia bloku",
|
||||
"md35": "Lista słów kluczowych wykluczenia referencji wirtualnych",
|
||||
"md36": "Używaj angielskiego przecinka <code class='fn__code'>,</code> jako separatora, przecinek sam w sobie można eskapować przez <code class='fn__code'>\\,</code>",
|
||||
"md36": "Używaj angielskiego przecinka <code class='fn__code'>,</code> lub znaku nowej linii jako separatora, przecinek sam w sobie można eskapować przez <code class='fn__code'>\\,</code>",
|
||||
"md37": "Maksymalna długość dynamicznego tekstu zakotwienia referencji bloku",
|
||||
"md38": "Maksymalna długość tekstu zakotwienia, która jest automatycznie renderowana, gdy tekst zakotwienia dla referencji bloku nie jest dostosowany, domyślnie <code class='fn__code'>96</code> znaków",
|
||||
"md39": "Adres serwera PlantUML",
|
||||
|
|
|
|||
|
|
@ -1143,7 +1143,7 @@
|
|||
"md33": "Referência Virtual",
|
||||
"md34": "Quando ativado, identificará automaticamente a possível relação de referência de acordo com o nome, apelido e texto âncora da referência de bloco existente",
|
||||
"md35": "Lista de exclusão de palavras-chave de Referência Virtual",
|
||||
"md36": "Use a vírgula inglesa <code class='fn__code'>,</code> para separar, a própria vírgula pode ser escapada por <code class='fn__code'>\\,</code>",
|
||||
"md36": "Use a vírgula inglesa <code class='fn__code'>,</code> ou quebra de linha para separar, a própria vírgula pode ser escapada por <code class='fn__code'>\\,</code>",
|
||||
"md37": "O comprimento máximo do texto âncora dinâmico da referência de bloco",
|
||||
"md38": "O comprimento máximo do texto âncora que é renderizado automaticamente quando o texto âncora da referência de bloco não é personalizado, o padrão é <code class='fn__code'>96</code> caracteres",
|
||||
"md39": "Endereço do Servidor PlantUML",
|
||||
|
|
|
|||
|
|
@ -1143,7 +1143,7 @@
|
|||
"md33": "Виртуальная ссылка",
|
||||
"md34": "После включения она автоматически определит возможные отношения ссылок по имени, псевдониму и тексту якоря существующих ссылок",
|
||||
"md35": "Список ключевых слов исключений виртуальной ссылки",
|
||||
"md36": "Используйте английскую запятую <code class='fn__code'>,</code> для разделения, сама запятая может быть экранирована <code class='fn__code'>\\,</code>",
|
||||
"md36": "Используйте английскую запятую <code class='fn__code'>,</code> или перенос строки для разделения, сама запятая может быть экранирована <code class='fn__code'>\\,</code>",
|
||||
"md37": "Максимальная длина динамического текста якоря ссылки блока",
|
||||
"md38": "Максимальная длина текста якоря, который автоматически отображается, когда текст якоря ссылки блока не настроен, по умолчанию <code class='fn__code'>96</code> символов",
|
||||
"md39": "Адрес сервера PlantUML",
|
||||
|
|
|
|||
|
|
@ -1143,7 +1143,7 @@
|
|||
"md33": "虛擬引用",
|
||||
"md34": "啟用後將自動根據已有塊引的命名、別名和錨文字來標識出可能存在的引用關係",
|
||||
"md35": "虛擬引用關鍵字排除列表",
|
||||
"md36": "使用英文狀態下的逗號 <code class='fn__code'>,</code> 進行分隔,逗號自身可通過 <code class='fn__code'>\\,</code> 轉義",
|
||||
"md36": "使用英文狀態下的逗號 <code class='fn__code'>,</code> 或換行符進行分隔,逗號自身可通過 <code class='fn__code'>\\,</code> 轉義",
|
||||
"md37": "塊引動態錨文字最大長度",
|
||||
"md38": "不自訂塊引錨文字時自動渲染錨文字的最大長度,預設為 <code class='fn__code'>96</code> 個字元",
|
||||
"md39": "PlantUML 伺服地址",
|
||||
|
|
|
|||
|
|
@ -1143,7 +1143,7 @@
|
|||
"md33": "虚拟引用",
|
||||
"md34": "启用后将自动根据已有块引的命名、别名和锚文本来标识出可能存在的引用关系",
|
||||
"md35": "虚拟引用关键字排除列表",
|
||||
"md36": "使用英文状态下的逗号 <code class='fn__code'>,</code> 进行分隔,逗号自身可通过 <code class='fn__code'>\\,</code> 转义",
|
||||
"md36": "使用英文状态下的逗号 <code class='fn__code'>,</code> 或换行符进行分隔,逗号自身可通过 <code class='fn__code'>\\,</code> 转义",
|
||||
"md37": "块引动态锚文本最大长度",
|
||||
"md38": "不自定义块引锚文本时自动渲染锚文本的最大长度,默认为 <code class='fn__code'>96</code> 个字符",
|
||||
"md39": "PlantUML 伺服地址",
|
||||
|
|
|
|||
|
|
@ -41,6 +41,10 @@
|
|||
margin-top: -16px;
|
||||
height: calc(100% + 16px);
|
||||
}
|
||||
|
||||
textarea.b3-text-field {
|
||||
resize: vertical;
|
||||
}
|
||||
}
|
||||
|
||||
&__panel > .b3-tab-bar {
|
||||
|
|
|
|||
|
|
@ -255,6 +255,10 @@
|
|||
padding: 0 8px;
|
||||
}
|
||||
}
|
||||
|
||||
.b3-label textarea.b3-text-field {
|
||||
resize: vertical;
|
||||
}
|
||||
}
|
||||
|
||||
#menu {
|
||||
|
|
|
|||
|
|
@ -145,22 +145,22 @@ 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>
|
||||
<div class="fn__flex b3-label config__item">
|
||||
<div class="fn__flex-1">
|
||||
<div class="b3-label">
|
||||
<div class="fn__block">
|
||||
${window.siyuan.languages.md9}
|
||||
<div class="b3-label__text">${window.siyuan.languages.md36}</div>
|
||||
<div class="fn__hr"></div>
|
||||
<textarea class="b3-text-field fn__block" id="virtualBlockRefInclude">${window.siyuan.config.editor.virtualBlockRefInclude}</textarea>
|
||||
</div>
|
||||
<span class="fn__space"></span>
|
||||
<input class="b3-text-field fn__flex-center fn__size200" id="virtualBlockRefInclude" value="${window.siyuan.config.editor.virtualBlockRefInclude}" />
|
||||
</div>
|
||||
<div class="fn__flex b3-label config__item">
|
||||
<div class="fn__flex-1">
|
||||
<div class="b3-label">
|
||||
<div class="fn__block">
|
||||
${window.siyuan.languages.md35}
|
||||
<div class="b3-label__text">${window.siyuan.languages.md36}</div>
|
||||
<div class="b3-label__text">${window.siyuan.languages.md41}</div>
|
||||
<div class="fn__hr"></div>
|
||||
<textarea class="b3-text-field fn__block" id="virtualBlockRefExclude">${window.siyuan.config.editor.virtualBlockRefExclude}</textarea>
|
||||
</div>
|
||||
<span class="fn__space"></span>
|
||||
<input class="b3-text-field fn__flex-center fn__size200" id="virtualBlockRefExclude" value="${window.siyuan.config.editor.virtualBlockRefExclude}" />
|
||||
</div>
|
||||
<div class="fn__flex b3-label config__item">
|
||||
<div class="fn__flex-1">
|
||||
|
|
@ -450,8 +450,8 @@ 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,
|
||||
virtualBlockRefInclude: (editor.element.querySelector("#virtualBlockRefInclude") as HTMLTextAreaElement).value,
|
||||
virtualBlockRefExclude: (editor.element.querySelector("#virtualBlockRefExclude") as HTMLTextAreaElement).value,
|
||||
blockRefDynamicAnchorTextMaxLen: parseInt((editor.element.querySelector("#blockRefDynamicAnchorTextMaxLen") as HTMLInputElement).value),
|
||||
backlinkExpandCount: parseInt((editor.element.querySelector("#backlinkExpandCount") as HTMLInputElement).value),
|
||||
backmentionExpandCount: parseInt((editor.element.querySelector("#backmentionExpandCount") as HTMLInputElement).value),
|
||||
|
|
|
|||
|
|
@ -42,8 +42,8 @@ const setEditor = (modelMainElement: Element) => {
|
|||
window.siyuan.config.editor.katexMacros = (modelMainElement.querySelector("#katexMacros") as HTMLTextAreaElement).value;
|
||||
window.siyuan.config.editor.codeLineWrap = (modelMainElement.querySelector("#codeLineWrap") as HTMLInputElement).checked;
|
||||
window.siyuan.config.editor.virtualBlockRef = (modelMainElement.querySelector("#virtualBlockRef") as HTMLInputElement).checked;
|
||||
window.siyuan.config.editor.virtualBlockRefInclude = (modelMainElement.querySelector("#virtualBlockRefInclude") as HTMLInputElement).value;
|
||||
window.siyuan.config.editor.virtualBlockRefExclude = (modelMainElement.querySelector("#virtualBlockRefExclude") as HTMLInputElement).value;
|
||||
window.siyuan.config.editor.virtualBlockRefInclude = (modelMainElement.querySelector("#virtualBlockRefInclude") as HTMLTextAreaElement).value;
|
||||
window.siyuan.config.editor.virtualBlockRefExclude = (modelMainElement.querySelector("#virtualBlockRefExclude") as HTMLTextAreaElement).value;
|
||||
window.siyuan.config.editor.blockRefDynamicAnchorTextMaxLen = parseInt((modelMainElement.querySelector("#blockRefDynamicAnchorTextMaxLen") as HTMLInputElement).value);
|
||||
window.siyuan.config.editor.backlinkExpandCount = parseInt((modelMainElement.querySelector("#backlinkExpandCount") as HTMLInputElement).value);
|
||||
window.siyuan.config.editor.backmentionExpandCount = parseInt((modelMainElement.querySelector("#backmentionExpandCount") as HTMLInputElement).value);
|
||||
|
|
@ -193,13 +193,13 @@ export const initEditor = () => {
|
|||
<div class="b3-label">
|
||||
${window.siyuan.languages.md9}
|
||||
<span class="fn__hr"></span>
|
||||
<input class="b3-text-field fn__block" id="virtualBlockRefInclude" value="${window.siyuan.config.editor.virtualBlockRefInclude}" />
|
||||
<textarea class="b3-text-field fn__block" id="virtualBlockRefInclude">${window.siyuan.config.editor.virtualBlockRefInclude}</textarea>
|
||||
<div class="b3-label__text">${window.siyuan.languages.md36}</div>
|
||||
</div>
|
||||
<div class="b3-label">
|
||||
${window.siyuan.languages.md35}
|
||||
<span class="fn__hr"></span>
|
||||
<input class="b3-text-field fn__block" id="virtualBlockRefExclude" value="${window.siyuan.config.editor.virtualBlockRefExclude}" />
|
||||
<textarea class="b3-text-field fn__block" id="virtualBlockRefExclude">${window.siyuan.config.editor.virtualBlockRefExclude}</textarea>
|
||||
<div class="b3-label__text">${window.siyuan.languages.md36}</div>
|
||||
<div class="b3-label__text">${window.siyuan.languages.md41}</div>
|
||||
</div>
|
||||
|
|
|
|||
|
|
@ -45,6 +45,9 @@ var virtualBlockRefCache, _ = ristretto.NewCache(&ristretto.Config{
|
|||
BufferItems: 64,
|
||||
})
|
||||
|
||||
// newlineRegexp 用于匹配连续或单个换行符的正则表达式
|
||||
var newlineRegexp = regexp.MustCompile(`[\r\n]+`)
|
||||
|
||||
func getBlockVirtualRefKeywords(root *ast.Node) (ret []string) {
|
||||
val, ok := virtualBlockRefCache.Get(root.ID)
|
||||
if !ok {
|
||||
|
|
@ -121,18 +124,54 @@ func ResetVirtualBlockRefCache() {
|
|||
virtualBlockRefCache.Set("virtual_ref", keywords, 1)
|
||||
}
|
||||
|
||||
// addNewKeywords 将新关键字添加到虚拟引用关键字列表中,如果不存在则追加,保留空白字符
|
||||
func addNewKeywords(keywordsStr string, newKeywords []string) string {
|
||||
keywordsStr = strings.TrimSpace(keywordsStr)
|
||||
if 0 == len(newKeywords) {
|
||||
return keywordsStr
|
||||
}
|
||||
|
||||
var builder strings.Builder
|
||||
if "" != keywordsStr {
|
||||
if !strings.HasSuffix(keywordsStr, "\\,") {
|
||||
keywordsStr = strings.TrimSuffix(keywordsStr, ",")
|
||||
}
|
||||
builder.WriteString(keywordsStr)
|
||||
builder.WriteString(",")
|
||||
}
|
||||
|
||||
keywords := gulu.Str.RemoveDuplicatedElem(parseKeywords(keywordsStr))
|
||||
newKeywords = gulu.Str.RemoveDuplicatedElem(newKeywords)
|
||||
allKeys := make(map[string]bool)
|
||||
|
||||
// 添加新关键字
|
||||
for _, keyword := range newKeywords {
|
||||
keywordTrimmed := strings.TrimSpace(keyword)
|
||||
if "" == keywordTrimmed {
|
||||
continue
|
||||
}
|
||||
if gulu.Str.Contains(keywordTrimmed, keywords) {
|
||||
// 剔除已存在的关键字
|
||||
continue
|
||||
}
|
||||
if _, value := allKeys[keywordTrimmed]; value {
|
||||
// 剔除重复的关键字
|
||||
continue
|
||||
}
|
||||
allKeys[keywordTrimmed] = true
|
||||
builder.WriteString(strings.ReplaceAll(keyword, ",", "\\,")) // 字符串切片转换为字符串,需要转义逗号
|
||||
builder.WriteString(",")
|
||||
}
|
||||
|
||||
return strings.TrimSuffix(builder.String(), ",")
|
||||
}
|
||||
|
||||
func AddVirtualBlockRefInclude(keyword []string) {
|
||||
if 1 > len(keyword) {
|
||||
return
|
||||
}
|
||||
|
||||
include := strings.ReplaceAll(Conf.Editor.VirtualBlockRefInclude, "\\,", "__comma@sep__")
|
||||
includes := strings.Split(include, ",")
|
||||
includes = append(includes, keyword...)
|
||||
includes = gulu.Str.RemoveDuplicatedElem(includes)
|
||||
Conf.Editor.VirtualBlockRefInclude = strings.Join(includes, ",")
|
||||
Conf.Editor.VirtualBlockRefInclude = addNewKeywords(Conf.Editor.VirtualBlockRefInclude, keyword)
|
||||
Conf.Save()
|
||||
|
||||
ResetVirtualBlockRefCache()
|
||||
}
|
||||
|
||||
|
|
@ -140,14 +179,8 @@ func AddVirtualBlockRefExclude(keyword []string) {
|
|||
if 1 > len(keyword) {
|
||||
return
|
||||
}
|
||||
|
||||
exclude := strings.ReplaceAll(Conf.Editor.VirtualBlockRefExclude, "\\,", "__comma@sep__")
|
||||
excludes := strings.Split(exclude, ",")
|
||||
excludes = append(excludes, keyword...)
|
||||
excludes = gulu.Str.RemoveDuplicatedElem(excludes)
|
||||
Conf.Editor.VirtualBlockRefExclude = strings.Join(excludes, ",")
|
||||
Conf.Editor.VirtualBlockRefExclude = addNewKeywords(Conf.Editor.VirtualBlockRefExclude, keyword)
|
||||
Conf.Save()
|
||||
|
||||
ResetVirtualBlockRefCache()
|
||||
}
|
||||
|
||||
|
|
@ -213,6 +246,30 @@ func processVirtualRef(n *ast.Node, unlinks *[]*ast.Node, virtualBlockRefKeyword
|
|||
return false
|
||||
}
|
||||
|
||||
// parseKeywords 将字符串转换为关键字切片,并剔除前后的空白字符
|
||||
func parseKeywords(keywordsStr string) (keywords []string) {
|
||||
keywords = []string{}
|
||||
keywordsStr = strings.TrimSpace(keywordsStr)
|
||||
if "" == keywordsStr {
|
||||
return
|
||||
}
|
||||
// 先处理转义的逗号
|
||||
keywordsStr = strings.ReplaceAll(keywordsStr, "\\,", "__comma@sep__")
|
||||
// 再将连续或单个换行符替换为一个逗号,避免把 `\\\n` 转换为 `\,`
|
||||
keywordsStr = newlineRegexp.ReplaceAllString(keywordsStr, ",")
|
||||
// 按逗号分隔
|
||||
for part := range strings.SplitSeq(keywordsStr, ",") {
|
||||
part = strings.TrimSpace(part) // 剔除前后的空白字符
|
||||
if "" == part {
|
||||
continue
|
||||
}
|
||||
// 恢复转义的逗号
|
||||
part = strings.ReplaceAll(part, "__comma@sep__", ",")
|
||||
keywords = append(keywords, part)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func getVirtualRefKeywords(root *ast.Node) (ret []string) {
|
||||
if !Conf.Editor.VirtualBlockRef {
|
||||
return
|
||||
|
|
@ -222,25 +279,16 @@ func getVirtualRefKeywords(root *ast.Node) (ret []string) {
|
|||
ret = val.([]string)
|
||||
}
|
||||
|
||||
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
|
||||
includes := parseKeywords(Conf.Editor.VirtualBlockRefInclude)
|
||||
if 0 < len(includes) {
|
||||
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, ",")
|
||||
excludes := parseKeywords(Conf.Editor.VirtualBlockRefExclude)
|
||||
if 0 < len(excludes) {
|
||||
var tmp, regexps []string
|
||||
for _, e := range excludes {
|
||||
e = strings.ReplaceAll(e, "__comma@sep__", ",")
|
||||
if strings.HasPrefix(e, "/") && strings.HasSuffix(e, "/") {
|
||||
regexps = append(regexps, e[1:len(e)-1])
|
||||
} else {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue