Skip to content

Commit

Permalink
closes #152
Browse files Browse the repository at this point in the history
  • Loading branch information
seiyria committed Dec 20, 2024
1 parent 4a9ad61 commit 342ca49
Showing 1 changed file with 18 additions and 2 deletions.
20 changes: 18 additions & 2 deletions search/operators/_helpers.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,20 @@
import { get, isArray } from 'lodash';
import type * as parser from 'search-query-parser';

import { marked } from 'marked';
import { type ICard } from '../../interfaces';

function getMarkdownStripRenderer(): marked.Renderer {
const renderer = new marked.Renderer();

renderer.codespan = (text: string) => text;
renderer.paragraph = (text: string) => text;
renderer.strong = (text: string) => text;
renderer.em = (text: string) => text;

return renderer;
}

function getValueFromCard<T>(card: ICard, prop: keyof ICard): T {
return get(card, prop) as T;
}
Expand Down Expand Up @@ -201,6 +213,8 @@ export function partialWithOptionalExactTextOperator(
return cards;
}

const renderer = getMarkdownStripRenderer();

// map all of the aliases (the same alias is an OR)
return aliases
.map((alias) => {
Expand All @@ -222,11 +236,13 @@ export function partialWithOptionalExactTextOperator(

const val = getValueFromCard<string>(c, key) ?? '';

const strippedText = marked.parse(val.toString(), { renderer });

if (isExact) {
return val.toString().toLowerCase() === searchString;
return strippedText.toLowerCase() === searchString;
}

return val.toString().toLowerCase().includes(i);
return strippedText.toLowerCase().includes(i);
})
);
}
Expand Down

0 comments on commit 342ca49

Please sign in to comment.