Skip to content

Instantly share code, notes, and snippets.

@navix
Created January 5, 2023 20:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save navix/6f6f1aaf3fc17955c1c41966b8ddc46f to your computer and use it in GitHub Desktop.
Save navix/6f6f1aaf3fc17955c1c41966b8ddc46f to your computer and use it in GitHub Desktop.
nl2br pipe
import {Pipe, PipeTransform} from '@angular/core';
@Pipe({
name: 'nl2br',
standalone: true,
})
export class Nl2brPipe implements PipeTransform {
transform(text: string): string {
return Nl2brPipe.replace(text);
}
static replace(text: string): string {
return text.replace(/([^>\r\n]?)(\r\n|\n\r|\r|\n)/g, '$1<br>$2');
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment