1
0
Fork 0

Remove unused highlight pipe

This commit is contained in:
Chocobozzz 2024-04-04 14:12:44 +02:00
parent a93217d2da
commit 1c33c6a388
No known key found for this signature in database
GPG key ID: 583A612D890159BE
3 changed files with 4 additions and 58 deletions

View file

@ -11,7 +11,6 @@ import { AppComponent } from './app.component'
import { CoreModule, PluginService, RedirectService, ServerService } from './core' import { CoreModule, PluginService, RedirectService, ServerService } from './core'
import { EmptyComponent } from './empty.component' import { EmptyComponent } from './empty.component'
import { HeaderComponent, SearchTypeaheadComponent, SuggestionComponent } from './header' import { HeaderComponent, SearchTypeaheadComponent, SuggestionComponent } from './header'
import { HighlightPipe } from './header/highlight.pipe'
import { polyfillICU } from './helpers' import { polyfillICU } from './helpers'
import { LanguageChooserComponent, MenuComponent, NotificationComponent } from './menu' import { LanguageChooserComponent, MenuComponent, NotificationComponent } from './menu'
import { AccountSetupWarningModalComponent } from './modal/account-setup-warning-modal.component' import { AccountSetupWarningModalComponent } from './modal/account-setup-warning-modal.component'
@ -58,7 +57,6 @@ export function loadConfigFactory (server: ServerService, pluginService: PluginS
HeaderComponent, HeaderComponent,
SearchTypeaheadComponent, SearchTypeaheadComponent,
SuggestionComponent, SuggestionComponent,
HighlightPipe,
AccountSetupWarningModalComponent, AccountSetupWarningModalComponent,
CustomModalComponent, CustomModalComponent,

View file

@ -1,54 +0,0 @@
import { PipeTransform, Pipe } from '@angular/core'
import { SafeHtml } from '@angular/platform-browser'
// Thanks https://gist.github.com/adamrecsko/0f28f474eca63e0279455476cc11eca7#gistcomment-2917369
@Pipe({ name: 'highlight' })
export class HighlightPipe implements PipeTransform {
/* use this for single match search */
static SINGLE_MATCH = 'Single-Match'
/* use this for single match search with a restriction that target should start with search string */
static SINGLE_AND_STARTS_WITH_MATCH = 'Single-And-StartsWith-Match'
/* use this for global search */
static MULTI_MATCH = 'Multi-Match'
transform (
contentString: string = null,
stringToHighlight: string = null,
option = 'Single-And-StartsWith-Match',
caseSensitive = false,
highlightStyleName = 'search-highlight'
): SafeHtml {
if (stringToHighlight && contentString && option) {
let regex: any = ''
const caseFlag: string = !caseSensitive ? 'i' : ''
switch (option) {
case 'Single-Match': {
regex = new RegExp(stringToHighlight, caseFlag)
break
}
case 'Single-And-StartsWith-Match': {
regex = new RegExp('^' + stringToHighlight, caseFlag)
break
}
case 'Multi-Match': {
regex = new RegExp(stringToHighlight, 'g' + caseFlag)
break
}
default: {
// default will be a global case-insensitive match
regex = new RegExp(stringToHighlight, 'gi')
}
}
const replaced = contentString.replace(
regex,
(match) => `<span class="${highlightStyleName}">${match}</span>`
)
return replaced
} else {
return contentString
}
}
}

View file

@ -7,8 +7,10 @@
<div <div
class="flex-auto overflow-hidden text-start no-wrap css-truncate css-truncate-target" class="flex-auto overflow-hidden text-start no-wrap css-truncate css-truncate-target"
[attr.aria-label]="result.text" [innerHTML]="result.text | highlight : highlight" [attr.aria-label]="result.text"
></div> >
{{ result.text }}
</div>
<div class="border rounded flex-shrink-0 px-1 bg-gray text-gray-light ms-1 f6"> <div class="border rounded flex-shrink-0 px-1 bg-gray text-gray-light ms-1 f6">
<span *ngIf="result.type === 'search-instance'" i18n>In this instance's network</span> <span *ngIf="result.type === 'search-instance'" i18n>In this instance's network</span>