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

Detect hashtag links just like the web UI does #960

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

Tamschi
Copy link

@Tamschi Tamschi commented Jan 8, 2025

Fixes #959.

See https://github.com/mastodon/mastodon/blob/67a8d4638c6e6a3ef178258504a6535746608c42/app/javascript/hooks/useLinks.ts#L13-L15 for the web logic.

Please note that I did not check whether this issue also exists in the iOS app, as I didn't find the matching part of the code there.

@Tamschi
Copy link
Author

Tamschi commented Jan 8, 2025

Also note that I think it would be better to (also) detect hashtag links by matching the href against that of Hashtag tags included with the post. I didn't do that here since there's no precedent for it in Mastodon, but it seems to be a similarly simple change.

String text=el.text();
boolean startsWithHash=text.startsWith("#");
Node previous=el.previousSibling();
if(startsWithHash || previous != null && previous.text().startsWith("#")){

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Q: Could you expand on why the previous sibling being a hashtag makes el a hashtag?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, that's wrong, I mixed up the call. I'll fix it in a minute.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed. The line now correctly says if(startsWithHash || previous != null && previous.text().endsWith("#")){.

@Tamschi Tamschi requested a review from 13-droid January 13, 2025 16:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Hashtag link detection is inconsistent with web UI
2 participants