replace-hashtags.ts 443 B

1234567891011121314151617181920
  1. import { Pipe, PipeTransform } from "@angular/core";
  2. @Pipe({
  3. name: "replaceHashtags"
  4. })
  5. export class ReplaceHashtagsPipe implements PipeTransform {
  6. /**
  7. * Takes a string and highlights the hashtags.
  8. */
  9. transform(value: string, ...args) {
  10. for (let hashtag of args[0]) {
  11. value = value.replace(
  12. "#" + hashtag.text,
  13. '<span class="hashtag">#' + hashtag.text + "</span>"
  14. );
  15. }
  16. return value;
  17. }
  18. }