better handle detection with pleroma URLs
This commit is contained in:
parent
af790dc646
commit
d8f2a38e5b
|
@ -203,10 +203,24 @@ describe('CreateStatusComponent', () => {
|
||||||
expect(result).toBe('<p>test @sengi_app@mastodon.social qsdqds qsd qsd qsd q @test@mastodon.social <span class="h-card"><a href="https://mastodon.social/@no" class="u-url">@<span>no</span></a></span></p>');
|
expect(result).toBe('<p>test @sengi_app@mastodon.social qsdqds qsd qsd qsd q @test@mastodon.social <span class="h-card"><a href="https://mastodon.social/@no" class="u-url">@<span>no</span></a></span></p>');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should tranform external mentions properly - mastodon 2', () => {
|
||||||
|
let mastodonMention = '<p>test <span class="h-card"><a href="https://pleroma.site/users/sengi_app" class="u-url mention">@<span>sengi_app</span></a></span> qsdqds qsd qsd qsd q <span class="h-card"><a href="https://pleroma.site/users/test" class="u-url mention">@<span>test</span></a></span> <span class="h-card"><a href="https://pleroma.site/users/no" class="u-url">@<span>no</span></a></span></p>';
|
||||||
|
|
||||||
|
const result = <string>(<any>component).tranformHtmlRepliesToReplies(mastodonMention);
|
||||||
|
expect(result).toBe('<p>test @sengi_app@pleroma.site qsdqds qsd qsd qsd q @test@pleroma.site <span class="h-card"><a href="https://pleroma.site/users/no" class="u-url">@<span>no</span></a></span></p>');
|
||||||
|
});
|
||||||
|
|
||||||
it('should tranform external mentions properly - pleroma', () => {
|
it('should tranform external mentions properly - pleroma', () => {
|
||||||
let pleromaMention = '<p>test <span class="h-card"><a data-user="50504" class="u-url mention" href="https://mastodon.social/@sengi_app" rel="ugc">@<span>sengi_app</span></a></span> qsdqds qsd qsd qsd q <span class="h-card"><a data-user="50504" class="u-url mention" href="https://mastodon.social/@test" rel="ugc">@<span>test</span></a></span> <span class="h-card"><a href="https://mastodon.social/@no" class="u-url">@<span>no</span></a></span></p>';
|
let pleromaMention = '<p>test <span class="h-card"><a data-user="50504" class="u-url mention" href="https://mastodon.social/@sengi_app" rel="ugc">@<span>sengi_app</span></a></span> qsdqds qsd qsd qsd q <span class="h-card"><a data-user="50504" class="u-url mention" href="https://mastodon.social/@test" rel="ugc">@<span>test</span></a></span> <span class="h-card"><a href="https://mastodon.social/@no" class="u-url">@<span>no</span></a></span></p>';
|
||||||
|
|
||||||
const result = <string>(<any>component).tranformHtmlRepliesToReplies(pleromaMention);
|
const result = <string>(<any>component).tranformHtmlRepliesToReplies(pleromaMention);
|
||||||
expect(result).toBe('<p>test @sengi_app@mastodon.social qsdqds qsd qsd qsd q @test@mastodon.social <span class="h-card"><a href="https://mastodon.social/@no" class="u-url">@<span>no</span></a></span></p>');
|
expect(result).toBe('<p>test @sengi_app@mastodon.social qsdqds qsd qsd qsd q @test@mastodon.social <span class="h-card"><a href="https://mastodon.social/@no" class="u-url">@<span>no</span></a></span></p>');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should tranform external mentions properly - pleroma 2', () => {
|
||||||
|
let pleromaMention = '<p>test <span class="h-card"><a data-user="50504" class="u-url mention" href="https://pleroma.site/users/sengi_app" rel="ugc">@<span>sengi_app</span></a></span> qsdqds qsd qsd qsd q <span class="h-card"><a data-user="50504" class="u-url mention" href="https://pleroma.site/users/test" rel="ugc">@<span>test</span></a></span> <span class="h-card"><a href="https://pleroma.site/users/no" class="u-url">@<span>no</span></a></span></p>';
|
||||||
|
|
||||||
|
const result = <string>(<any>component).tranformHtmlRepliesToReplies(pleromaMention);
|
||||||
|
expect(result).toBe('<p>test @sengi_app@pleroma.site qsdqds qsd qsd qsd q @test@pleroma.site <span class="h-card"><a href="https://pleroma.site/users/no" class="u-url">@<span>no</span></a></span></p>');
|
||||||
|
});
|
||||||
});
|
});
|
|
@ -852,8 +852,8 @@ export class CreateStatusComponent implements OnInit, OnDestroy {
|
||||||
}
|
}
|
||||||
|
|
||||||
private tranformHtmlRepliesToReplies(data: string): string {
|
private tranformHtmlRepliesToReplies(data: string): string {
|
||||||
const mastodonMentionRegex = /<span class="h-card"><a href="https:\/\/([a-zA-Z0-9\/.]{0,255})\/@([a-zA-Z0-9_-]{0,255})" class="u-url mention">@<span>[a-zA-Z0-9_-]{0,255}<\/span><\/a><\/span>/gmi;
|
const mastodonMentionRegex = /<span class="h-card"><a href="https:\/\/([a-zA-Z0-9.]{0,255})\/[a-zA-Z0-9_@/-]{0,255}" class="u-url mention">@<span>([a-zA-Z0-9_-]{0,255})<\/span><\/a><\/span>/gmi;
|
||||||
const pleromaMentionRegex = /<span class="h-card"><a data-user="[a-zA-Z0-9]{0,255}" class="u-url mention" href="https:\/\/([a-zA-Z0-9\/.]{0,255})\/@([a-zA-Z0-9_-]{0,255})" rel="ugc">@<span>[a-zA-Z0-9_-]{0,255}<\/span><\/a><\/span>/gmi;
|
const pleromaMentionRegex = /<span class="h-card"><a data-user="[a-zA-Z0-9]{0,255}" class="u-url mention" href="https:\/\/([a-zA-Z0-9.]{0,255})\/[a-zA-Z0-9_@/-]{0,255}" rel="ugc">@<span>([a-zA-Z0-9_-]{0,255})<\/span><\/a><\/span>/gmi;
|
||||||
|
|
||||||
while(data.match(mastodonMentionRegex)){
|
while(data.match(mastodonMentionRegex)){
|
||||||
data = data.replace(mastodonMentionRegex, '@$2@$1');
|
data = data.replace(mastodonMentionRegex, '@$2@$1');
|
||||||
|
|
Loading…
Reference in New Issue