diff --git a/src/app/components/stream/status/databinded-text/databinded-text.component.spec.ts b/src/app/components/stream/status/databinded-text/databinded-text.component.spec.ts index 95c71731..7797d62e 100644 --- a/src/app/components/stream/status/databinded-text/databinded-text.component.spec.ts +++ b/src/app/components/stream/status/databinded-text/databinded-text.component.spec.ts @@ -36,7 +36,7 @@ describe('DatabindedTextComponent', () => { const url = 'https://test.social/tags/programmers'; const sample = `
bla1 #${hashtag} bla2
`; component.text = sample; - expect(component.processedText).toContain('#programmers'); + expect(component.processedText).toContain('#programmers'); expect(component.processedText).toContain('bla1'); expect(component.processedText).toContain('bla2'); }); @@ -75,7 +75,7 @@ describe('DatabindedTextComponent', () => { const linkUrl = 'mydomain.co/test'; const sample = `bla1 #${hashtag} bla2 @${mention} bla3 https://${linkUrl} bla4
`; component.text = sample; - expect(component.processedText).toContain('#programmers'); + expect(component.processedText).toContain('#programmers'); expect(component.processedText).toContain('@sengi_app'); expect(component.processedText).toContain('mydomain.co/test'); expect(component.processedText).toContain('bla1'); @@ -97,6 +97,5 @@ describe('DatabindedTextComponent', () => { component.text = sample; expect(component.processedText).toContain(''); - }); - + }); }); diff --git a/src/app/components/stream/status/databinded-text/databinded-text.component.ts b/src/app/components/stream/status/databinded-text/databinded-text.component.ts index 73d7ce8d..67fb060a 100644 --- a/src/app/components/stream/status/databinded-text/databinded-text.component.ts +++ b/src/app/components/stream/status/databinded-text/databinded-text.component.ts @@ -64,7 +64,8 @@ export class DatabindedTextComponent implements OnInit { let extractedLinkAndNext = section.split(''); let extractedHashtag = extractedLinkAndNext[0].split('#')[1].replace('', '').replace('', ''); - this.processedText += ` #${extractedHashtag}`; + let classname = this.getClassNameForHastag(extractedHashtag); + this.processedText += ` #${extractedHashtag}`; if (extractedLinkAndNext[1]) this.processedText += extractedLinkAndNext[1]; this.hashtags.push(extractedHashtag); } @@ -124,7 +125,8 @@ export class DatabindedTextComponent implements OnInit { ngAfterViewInit() { for (const hashtag of this.hashtags) { - let el = this.contentElement.nativeElement.querySelector(`.${hashtag}`); + let classname = this.getClassNameForHastag(hashtag); + let el = this.contentElement.nativeElement.querySelector(`.${classname}`); this.renderer.listen(el, 'click', (event) => { event.preventDefault(); @@ -161,6 +163,11 @@ export class DatabindedTextComponent implements OnInit { } } + private getClassNameForHastag(value: string): string { + let res = value.replace(/[.,\/#?!@$%+\^&\*;:{}=\-_`~()]/g, ""); + return `hashtag-${res}`; + } + private getClassNameForAccount(value: string): string { let res = value; while (res.includes('.')) res = res.replace('.', '-');