mirror of
https://github.com/zadam/trilium.git
synced 2024-11-10 09:02:48 +08:00
fix searching fulltext with tags, closes #4661
This commit is contained in:
parent
1f95e88cfd
commit
2d19f073d9
1 changed files with 18 additions and 5 deletions
|
@ -111,11 +111,7 @@ class NoteContentFulltextExp extends Expression {
|
|||
|
||||
if (type === 'text' && mime === 'text/html') {
|
||||
if (!this.raw && content.length < 20000) { // striptags is slow for very large notes
|
||||
// allow link to preserve URLs: https://github.com/zadam/trilium/issues/2412
|
||||
content = striptags(content, ['a'], ' ');
|
||||
|
||||
// at least the closing tag can be easily stripped
|
||||
content = content.replace(/<\/a>/ig, "");
|
||||
content = this.stripTags(content);
|
||||
}
|
||||
|
||||
content = content.replace(/ /g, ' ');
|
||||
|
@ -123,6 +119,23 @@ class NoteContentFulltextExp extends Expression {
|
|||
|
||||
return content.trim();
|
||||
}
|
||||
|
||||
stripTags(content) {
|
||||
// we want to allow link to preserve URLs: https://github.com/zadam/trilium/issues/2412
|
||||
// we want to insert space in place of block tags (because they imply text separation)
|
||||
// but we don't want to insert text for typical formatting inline tags which can occur within one word
|
||||
const linkTag = 'a';
|
||||
const inlineFormattingTags = ['b', 'strong', 'em', 'i', 'span', 'big', 'small', 'font', 'sub', 'sup'];
|
||||
|
||||
// replace tags which imply text separation with a space
|
||||
content = striptags(content, [linkTag, ...inlineFormattingTags], ' ');
|
||||
|
||||
// replace the inline formatting tags (but not links) without a space
|
||||
content = striptags(content, [linkTag], '');
|
||||
|
||||
// at least the closing link tag can be easily stripped
|
||||
return content.replace(/<\/a>/ig, "");
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = NoteContentFulltextExp;
|
||||
|
|
Loading…
Reference in a new issue