Skip to content

Commit 2d19f07

Browse files
committed
fix searching fulltext with tags, closes #4661
1 parent 1f95e88 commit 2d19f07

File tree

1 file changed

+18
-5
lines changed

1 file changed

+18
-5
lines changed

src/services/search/expressions/note_content_fulltext.js

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -111,18 +111,31 @@ class NoteContentFulltextExp extends Expression {
111111

112112
if (type === 'text' && mime === 'text/html') {
113113
if (!this.raw && content.length < 20000) { // striptags is slow for very large notes
114-
// allow link to preserve URLs: https://github.com/zadam/trilium/issues/2412
115-
content = striptags(content, ['a'], ' ');
116-
117-
// at least the closing tag can be easily stripped
118-
content = content.replace(/<\/a>/ig, "");
114+
content = this.stripTags(content);
119115
}
120116

121117
content = content.replace(/&nbsp;/g, ' ');
122118
}
123119

124120
return content.trim();
125121
}
122+
123+
stripTags(content) {
124+
// we want to allow link to preserve URLs: https://github.com/zadam/trilium/issues/2412
125+
// we want to insert space in place of block tags (because they imply text separation)
126+
// but we don't want to insert text for typical formatting inline tags which can occur within one word
127+
const linkTag = 'a';
128+
const inlineFormattingTags = ['b', 'strong', 'em', 'i', 'span', 'big', 'small', 'font', 'sub', 'sup'];
129+
130+
// replace tags which imply text separation with a space
131+
content = striptags(content, [linkTag, ...inlineFormattingTags], ' ');
132+
133+
// replace the inline formatting tags (but not links) without a space
134+
content = striptags(content, [linkTag], '');
135+
136+
// at least the closing link tag can be easily stripped
137+
return content.replace(/<\/a>/ig, "");
138+
}
126139
}
127140

128141
module.exports = NoteContentFulltextExp;

0 commit comments

Comments
 (0)