better link parsing in pleroma

This commit is contained in:
Nicolas Constant 2019-05-25 17:19:07 -04:00
parent 9b129ae7b4
commit 0418ee6c2f
No known key found for this signature in database
GPG Key ID: 1E9F677FB01A5688
2 changed files with 19 additions and 8 deletions

View File

@ -148,5 +148,12 @@ describe('DatabindedTextComponent', () => {
component.text = sample;
expect(component.processedText).toContain('<p>Bla <a href class="link-httpscloudblogsmicrosoftcomopensource20190521servicemeshinterfacesmirelease" title="open link">cloudblogs.microsoft.com/opens</a></p>');
})
});
it('should parse link 2 - Pleroma', () => {
const sample = `Bla<br /><br /><a href="https://link/">https://link/</a>`;
component.text = sample;
expect(component.processedText).toContain('Bla<br /><br /><a href class="link-httpslink" title="open link">https://link/</a>');
});
});

View File

@ -48,8 +48,8 @@ export class DatabindedTextComponent implements OnInit {
this.processHashtag(section);
}
catch (err) {
console.warn('process hashtag');
console.warn(value);
console.error('error processing hashtag');
console.error(value);
}
} else if (section.includes('class="u-url mention"') || section.includes('class="mention"') || section.includes('class="mention status-link"') || section.includes('class="h-card mention')) {
@ -57,8 +57,8 @@ export class DatabindedTextComponent implements OnInit {
this.processUser(section);
}
catch (err) {
console.warn('process mention');
console.warn(value);
console.error('error processing mention');
console.error(value);
}
} else {
try {
@ -66,8 +66,8 @@ export class DatabindedTextComponent implements OnInit {
//this.processedText += `<a ${section}`;
}
catch (err) {
console.warn('process link');
console.warn(value);
console.error('error processing link');
console.error(value);
}
}
}
@ -133,7 +133,11 @@ export class DatabindedTextComponent implements OnInit {
try {
extractedName = extractedLinkAndNext[0].split(' target="_blank">')[1].split('</span>')[0];
} catch (err) { // Pleroma
extractedName = extractedLinkAndNext[0].split('</span><span>')[1].split('</span>')[0];
try {
extractedName = extractedLinkAndNext[0].split('</span><span>')[1].split('</span>')[0];
} catch (err) {
extractedName = extractedLinkAndNext[0].split('">')[1];
}
}
}
}