fix Hometown hashtag, fix #357

This commit is contained in:
Nicolas Constant 2021-02-28 00:29:12 -05:00
parent 1d9e3c5130
commit 030ce2e568
No known key found for this signature in database
GPG Key ID: 1E9F677FB01A5688
2 changed files with 12 additions and 2 deletions

View File

@ -47,6 +47,16 @@ describe('DatabindedTextComponent', () => {
expect(component.processedText).toContain('bla2'); expect(component.processedText).toContain('bla2');
}); });
it('should parse hashtag - Hometown', () => {
const hashtag = 'MicroFiction';
const url = 'https://mastodon.social/tags/MicroFiction';
const sample = `<p>"bla1"<br><a href="${url}" class="mention hashtag" rel="nofollow noopener noreferrer" target="_blank">#<span class="article-type">${hashtag}</span></a> bla2</p>`;
component.text = sample;
expect(component.processedText).toContain(`<a href="${url}" class="hashtag-${hashtag}" title="#${hashtag}" target="_blank" rel="noopener noreferrer">#${hashtag}</a>`);
expect(component.processedText).toContain('bla1');
expect(component.processedText).toContain('bla2');
});
it('should parse hashtag - Pleroma 2.0.2', () => { it('should parse hashtag - Pleroma 2.0.2', () => {
const sample = `Blabla <a class="hashtag" data-tag="covid19" href="https://url.com/tag/covid19">#covid19</a> Blibli`; const sample = `Blabla <a class="hashtag" data-tag="covid19" href="https://url.com/tag/covid19">#covid19</a> Blibli`;
component.text = sample; component.text = sample;

View File

@ -93,7 +93,7 @@ export class DatabindedTextComponent implements OnInit {
private processHashtag(section: string) { private processHashtag(section: string) {
let extractedLinkAndNext = section.split('</a>'); let extractedLinkAndNext = section.split('</a>');
let extractedHashtag = extractedLinkAndNext[0].split('#')[1].replace('<span>', '').replace('</span>', ''); let extractedHashtag = extractedLinkAndNext[0].split('#')[1].replace('<span class="article-type">', '').replace('<span>', '').replace('</span>', '');
let extractedUrl = extractedLinkAndNext[0].split('href="')[1].split('"')[0]; let extractedUrl = extractedLinkAndNext[0].split('href="')[1].split('"')[0];
let classname = this.getClassNameForHastag(extractedHashtag); let classname = this.getClassNameForHastag(extractedHashtag);