better misskey parsing in pleroma

This commit is contained in:
Nicolas Constant 2020-09-17 22:16:53 -04:00
parent a0952de788
commit 912d9e31b5
No known key found for this signature in database
GPG Key ID: 1E9F677FB01A5688
2 changed files with 17 additions and 3 deletions

View File

@ -156,6 +156,15 @@ describe('DatabindedTextComponent', () => {
expect(component.processedText).toContain('<p><a href="https://mastodon.social/users/sengi_app" class="account--sengi_app-mastodon-social-mastodon-social" title="@sengi_app@mastodon.social@mastodon.social" target="_blank" rel="noopener noreferrer">@sengi_app@mastodon.social</a><span> Blabla</span></p>'); //FIXME: dont let domain appear in name expect(component.processedText).toContain('<p><a href="https://mastodon.social/users/sengi_app" class="account--sengi_app-mastodon-social-mastodon-social" title="@sengi_app@mastodon.social@mastodon.social" target="_blank" rel="noopener noreferrer">@sengi_app@mastodon.social</a><span> Blabla</span></p>'); //FIXME: dont let domain appear in name
}); });
it('should parse mention - Misskey in Pleroma', () => {
const sample = `<p><a href="https://domain.xyz/@sengi" class="u-url mention">@sengi@domain.xyz</a><span> </span><a href="https://domain.eu/@sengi" class="u-url mention">@sengi@domain.eu</a><span> bla bla<br/>bla bla bla</span></p>`;
component.text = sample;
expect(component.processedText).toContain('<a href="https://domain.xyz/@sengi" class="account--sengi-domain-xyz" title="@sengi@domain.xyz" target="_blank" rel="noopener noreferrer">@sengi</a><span>');
expect(component.processedText).toContain('<a href="https://domain.eu/@sengi" class="account--sengi-domain-eu" title="@sengi@domain.eu" target="_blank" rel="noopener noreferrer">@sengi</a>');
expect(component.processedText).toContain('<span> bla bla<br/>bla bla bla</span>');
});
it('should parse mention - Misskey in Mastodon - 2', () => { it('should parse mention - Misskey in Mastodon - 2', () => {
const sample = `<p><span>Since </span><a href="https://mastodon.technology/@test" class="u-url mention" rel="nofollow noopener noreferrer" target="_blank">@test@mastodon.technology</a><span> mentioned </span></p>`; const sample = `<p><span>Since </span><a href="https://mastodon.technology/@test" class="u-url mention" rel="nofollow noopener noreferrer" target="_blank">@test@mastodon.technology</a><span> mentioned </span></p>`;

View File

@ -28,7 +28,7 @@ export class DatabindedTextComponent implements OnInit {
@Input('text') @Input('text')
set text(value: string) { set text(value: string) {
//console.log(value); // console.log(value);
let parser = new DOMParser(); let parser = new DOMParser();
var dom = parser.parseFromString(value, 'text/html') var dom = parser.parseFromString(value, 'text/html')
@ -113,13 +113,18 @@ export class DatabindedTextComponent implements OnInit {
extractedAccountAndNext = section.split('</a></span>'); extractedAccountAndNext = section.split('</a></span>');
extractedAccountName = extractedAccountAndNext[0].split('@<span class="article-type">')[1].replace('<span>', '').replace('</span>', ''); extractedAccountName = extractedAccountAndNext[0].split('@<span class="article-type">')[1].replace('<span>', '').replace('</span>', '');
} else if (section.includes('class="u-url mention" rel="nofollow noopener noreferrer" target="_blank">@') && !section.includes('target="_blank">@<')) { //Misskey } else if (section.includes('class="u-url mention" rel="nofollow noopener noreferrer" target="_blank">@') && !section.includes('target="_blank">@<')) { //Misskey
//console.warn('misskey');
extractedAccountAndNext = section.split('</a>'); extractedAccountAndNext = section.split('</a>');
extractedAccountName = extractedAccountAndNext[0].split('class="u-url mention" rel="nofollow noopener noreferrer" target="_blank">@')[1]; extractedAccountName = extractedAccountAndNext[0].split('class="u-url mention" rel="nofollow noopener noreferrer" target="_blank">@')[1];
if (extractedAccountName.includes('@')) if (extractedAccountName.includes('@'))
extractedAccountName = extractedAccountName.split('@')[0]; extractedAccountName = extractedAccountName.split('@')[0];
} else if(section.includes(' class="u-url mention">@') && !section.includes(' class="u-url mention">@<')) { //Misskey in pleroma
extractedAccountAndNext = section.split('</a>');
extractedAccountName = extractedAccountAndNext[0].split(' class="u-url mention">@')[1];
if (extractedAccountName.includes('@'))
extractedAccountName = extractedAccountName.split('@')[0];
} else if (!section.includes('@<span>')) { //GNU social } else if (!section.includes('@<span>')) { //GNU social
extractedAccountAndNext = section.split('</a>'); extractedAccountAndNext = section.split('</a>');
extractedAccountName = extractedAccountAndNext[0].split('>')[1]; extractedAccountName = extractedAccountAndNext[0].split('>')[1];