Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add GoToSocial URL support #631

Open
anantshri opened this issue Jan 5, 2024 · 3 comments
Open

Add GoToSocial URL support #631

anantshri opened this issue Jan 5, 2024 · 3 comments
Labels
enhancement enhance an existing feature

Comments

@anantshri
Copy link

URL which is within the toot content is not rendered properly

Original post : https://tatooine.club/@nemo/111696202370333457

Rendered in sengi as:
image

This is rendered correctly at my server side https://social.anantshri.info/@anant/statuses/01HK9YEMJBS6KR4NP8VTK2RHMB

this is rendered correctly on other clients (icecubes / pinafore)

when i copy all data i get this

https://tatooine.club/@nemo/111696202370333457

<p>Reached almost 50% coverage, and running out of steam so launching the Emoji Calendar 2024:</p><p><a href="https://captnemo.in/emoji-every-day/" rel="nofollow noopener noreferrer" target="_blank"><span class="invisible">https://</span><span>captnemo.in/emoji-every-day/</span><span class="invisible"></span></a></p><p>Please suggest more days to add.</p>

Reached almost 50% coverage, and running out of steam so launching the Emoji Calendar 2024:https://captnemo.in/emoji-every-day/Please suggest more days to add.

@NicolasConstant
Copy link
Owner

If I open this post via a Mastodon account it displays correctly:

image

But it seems you're using some exotic AP server on your side? Maybe there is a conversion between the original content and the content provided by your server's MastoAPI that differs from a common Mastodon/Pleroma/etc MastoAPI output.

Sengi parses MastoAPI content to be able to render it properly, so if it's not exactly the same than an usual MastoAPI output, there will be parsing errors/weird bugs.

@tsmethurst
Copy link

tsmethurst commented Jan 5, 2024

It looks like the link is getting dropped inside the processLink function of DatabindedTextComponent:

private processLink(section: string) {
if (!section.includes('</a>')) {
this.processedText += section;
return;
}
let extractedLinkAndNext = section.split('</a>')
let extractedUrl = extractedLinkAndNext[0].split('"')[1];
let extractedName = '';
if(extractedLinkAndNext[0].includes('<span class="article-type">')){
extractedName = extractedLinkAndNext[0].split('<span class="article-type">')[2].split('</span>')[0];
} else {
try {
extractedName = extractedLinkAndNext[0].split('<span class="ellipsis">')[1].split('</span>')[0];
} catch (err) {
try {
extractedName = extractedLinkAndNext[0].split(`<span class="">`)[1].split('</span>')[0];
}
catch (err) {
try {
extractedName = extractedLinkAndNext[0].split(' target="_blank">')[1].split('</span>')[0];
} catch (err) { // Pleroma
try {
extractedName = extractedLinkAndNext[0].split('</span><span>')[1].split('</span>')[0];
} catch (err) {
extractedName = extractedLinkAndNext[0].split('">')[1];
}
}
}
}
}
this.links.push(extractedUrl);
let classname = this.getClassNameForLink(extractedUrl);
let sanitizedLink = this.sanitizeLink(extractedUrl);
this.processedText += `<a href="${sanitizedLink}" class="${classname}" title="open link" target="_blank" rel="noopener noreferrer">${extractedName}</a>`;
if (extractedLinkAndNext.length > 1) this.processedText += extractedLinkAndNext[1];
}

Links in GoToSocial are just the URL with an anchor around them and an appropriate href. Nothing fancy. They look like this:

<a href="https://example.org" rel="nofollow noreferrer noopener" target="_blank">https://example.org</a>

Sometimes they'll look more like this, if the user who posted the link has Markdown enabled and wrote a link in a slightly fancier way:

<a href="https://example.org" rel="nofollow noreferrer noopener" target="_blank">example link</a>

Or even like this, if the user added a title to the link:

<a href="https://example.org" title="this is a link title" rel="nofollow noreferrer noopener" target="_blank">example link</a>

Perhaps it would be possible to allow such links through instead of dropping them, since they're very standard, safe HTML.

@NicolasConstant
Copy link
Owner

So it's more about GoToSocial link support then?

If I remember correctly, link parsing was related to some Electron edge cases, that's not something I would change right now. It would be better to just document the new use cases via the unit tests and fix the code accordingly.

@NicolasConstant NicolasConstant changed the title URL not displayed Add GoToSocial URL support Jan 6, 2024
@NicolasConstant NicolasConstant added the enhancement enhance an existing feature label Jan 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement enhance an existing feature
Projects
None yet
Development

No branches or pull requests

3 participants