Skip to content

Commit

Permalink
chore: add dompurify
Browse files Browse the repository at this point in the history
  • Loading branch information
splincode committed Nov 13, 2023
1 parent dd5a53a commit 8cc3592
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 3 deletions.
7 changes: 6 additions & 1 deletion apps/demo/src/app/app.config.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import {ApplicationConfig, importProvidersFrom} from '@angular/core';
import {ApplicationConfig, importProvidersFrom, Sanitizer} from '@angular/core';
import {provideClientHydration} from '@angular/platform-browser';
import {provideAnimations} from '@angular/platform-browser/animations';
import {provideRouter} from '@angular/router';
import {TuiDialogModule, TuiRootModule} from '@taiga-ui/core';
import {TuiPushModule} from '@taiga-ui/kit';
import {NgDompurifySanitizer} from '@tinkoff/ng-dompurify';

import {routes} from './app.routes';

Expand All @@ -13,5 +14,9 @@ export const appConfig: ApplicationConfig = {
provideRouter(routes),
provideClientHydration(),
importProvidersFrom(TuiRootModule, TuiDialogModule, TuiPushModule),
{
provide: Sanitizer,
useClass: NgDompurifySanitizer,
},
],
};
7 changes: 6 additions & 1 deletion apps/demo/src/app/home/home.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,16 @@ <h2 class="title">
components
</h2>
<tui-input-tag
tuiHintContent="Customizable for any use case"
class="tui-space_vertical-10"
[tuiHintContent]="hint"
[tuiTextfieldLabelOutside]="true"
[(ngModel)]="tags"
></tui-input-tag>

<ng-template #hint>
<span [innerHtml]="purify('Customizable for <b>any use</b> case')"></span>
</ng-template>

<div class="flex">
<div class="date">
<tui-input-date
Expand Down
8 changes: 7 additions & 1 deletion apps/demo/src/app/home/home.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {
ChangeDetectorRef,
Component,
inject,
SecurityContext,
TemplateRef,
ViewEncapsulation,
} from '@angular/core';
Expand All @@ -27,7 +28,7 @@ import {
TuiSliderModule,
TuiToggleModule,
} from '@taiga-ui/kit';
import {NgDompurifyModule} from '@tinkoff/ng-dompurify';
import {NgDompurifyModule, NgDompurifySanitizer} from '@tinkoff/ng-dompurify';

@Component({
standalone: true,
Expand Down Expand Up @@ -56,6 +57,7 @@ import {NgDompurifyModule} from '@tinkoff/ng-dompurify';
changeDetection: ChangeDetectionStrategy.OnPush,
})
export class HomeComponent {
private readonly dompurifySanitizer = inject(NgDompurifySanitizer);
private readonly dialogs = inject(TuiDialogService);
private readonly cd = inject(ChangeDetectorRef);

Expand Down Expand Up @@ -83,4 +85,8 @@ export class HomeComponent {
this.notification = open;
this.cd.detectChanges();
}

purify(value: string): string {
return this.dompurifySanitizer.sanitize(SecurityContext.HTML, value);
}
}

0 comments on commit 8cc3592

Please sign in to comment.