Created
January 5, 2023 20:04
-
-
Save navix/6f6f1aaf3fc17955c1c41966b8ddc46f to your computer and use it in GitHub Desktop.
nl2br pipe
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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