replace-hashtags.ts 579 B

12345678910111213141516171819202122232425
  1. import { Pipe, PipeTransform } from "@angular/core";
  2. /**
  3. * Generated class for the ReplaceHashtagsPipe pipe.
  4. *
  5. * See https://angular.io/api/core/Pipe for more info on Angular Pipes.
  6. */
  7. @Pipe({
  8. name: "replaceHashtags"
  9. })
  10. export class ReplaceHashtagsPipe implements PipeTransform {
  11. /**
  12. * Takes a string and highlights the hashtags.
  13. */
  14. transform(value: string, ...args) {
  15. for (let hashtag of args[0]) {
  16. value = value.replace(
  17. "#" + hashtag.text,
  18. '<span class="hashtag">#' + hashtag.text + "</span>"
  19. );
  20. }
  21. return value;
  22. }
  23. }