refactor(keyword-highlighting): drop the HTML-string path left unused after rebase
This commit is contained in:
@@ -83,8 +83,6 @@ export function keywordTooltip(
|
||||
|
||||
const WORD_CHAR = '[\\w\\u00C0-\\u024F]';
|
||||
|
||||
export const KW_MARK_CLASS = 'kw-mark';
|
||||
|
||||
export interface KeywordSegment {
|
||||
text: string;
|
||||
match: KeywordColor | null;
|
||||
@@ -143,29 +141,6 @@ export function splitByKeywords(
|
||||
return segments;
|
||||
}
|
||||
|
||||
export function highlightKeywords(
|
||||
text: string,
|
||||
keywordColors: readonly KeywordColor[],
|
||||
): string {
|
||||
return splitByKeywords(text, keywordColors)
|
||||
.map(({ text: value, match }) => {
|
||||
if (!match) {
|
||||
return escapeHtml(value);
|
||||
}
|
||||
|
||||
const tooltip = escapeHtml(
|
||||
keywordTooltip(match.keyword, match.topicNames),
|
||||
);
|
||||
|
||||
return (
|
||||
`<mark class="${KW_MARK_CLASS}" style="--t:${match.color}"` +
|
||||
` data-kw="${escapeHtml(match.keyword)}" title="${tooltip}">` +
|
||||
`${escapeHtml(value)}</mark>`
|
||||
);
|
||||
})
|
||||
.join('');
|
||||
}
|
||||
|
||||
export interface SnippetSegment {
|
||||
text: string;
|
||||
isSearchMatch: boolean;
|
||||
@@ -227,14 +202,6 @@ export function decodeHtml(text: string): string {
|
||||
.replace(/&/g, '&');
|
||||
}
|
||||
|
||||
export function escapeHtml(text: string): string {
|
||||
return text
|
||||
.replace(/&/g, '&')
|
||||
.replace(/</g, '<')
|
||||
.replace(/>/g, '>')
|
||||
.replace(/"/g, '"');
|
||||
}
|
||||
|
||||
function escapeRegex(text: string): string {
|
||||
return text.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user