mirror of https://gitlab.com/openlp/web-remote.git
18 lines
576 B
TypeScript
18 lines
576 B
TypeScript
import { Pipe, PipeTransform } from '@angular/core';
|
|
import { DomSanitizer, SafeHtml } from '@angular/platform-browser';
|
|
|
|
@Pipe({name: 'nl2br'})
|
|
export class Nl2BrPipe implements PipeTransform {
|
|
constructor(private sanitizer: DomSanitizer) { }
|
|
|
|
transform(value: string): string|SafeHtml {
|
|
if (!value) {
|
|
return value;
|
|
}
|
|
if (typeof value !== 'string') {
|
|
throw Error(`Invalid pipe argument: '${value}' for pipe 'Nl2BrPipe'`);
|
|
}
|
|
return this.sanitizer.bypassSecurityTrustHtml(value.replace(/(?:\r\n|\r|\n)/g, '<br>'));
|
|
}
|
|
}
|