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

[chore/bugfix] Deinterface text.Formatter, allow underscores in hashtags #2233

Merged
merged 1 commit into from
Sep 29, 2023

Conversation

tsmethurst
Copy link
Contributor

Description

If this is a code change, please include a summary of what you've coded, and link to the issue(s) it closes/implements.

If this is a documentation change, please briefly describe what you've changed and why.

This pull request does the following:

  • Deinterface the text.Formatter to make the code a bit simpler.
  • Allow underscores in hashtags as long as hashtag is not only underscores (in line with Mastodon's hashtag behavior).
  • Refactor and comment some of the internal/text goldmark and parsing stuff, to make it more consistent and (i hope) more readable!

One of the side effects of this is that it's no longer possible to create italicized hashtags _#LikeThis_, however they can still be created *#LikeThis*.

closes #2199

Checklist

Please put an x inside each checkbox to indicate that you've read and followed it: [ ] -> [x]

If this is a documentation change, only the first checkbox must be filled (you can delete the others if you want).

  • I/we have read the GoToSocial contribution guidelines.
  • I/we have discussed the proposed changes already, either in an issue on the repository, or in the Matrix chat.
  • I/we have performed a self-review of added code.
  • I/we have written code that is legible and maintainable by others.
  • I/we have commented the added code, particularly in hard-to-understand areas.
  • I/we have made any necessary changes to documentation.
  • I/we have added tests that cover new code.
  • I/we have run tests and they pass locally with the changes.
  • I/we have run go fmt ./... and golangci-lint run.

@@ -1,70 +0,0 @@
// GoToSocial
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This stuff has moved into plain.go

@@ -0,0 +1,423 @@
// GoToSocial
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Logic in here was mostly taken from goldmark_extension.go. Just tried to make it more consistent.

@@ -0,0 +1,281 @@
// GoToSocial
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Stuff in this file was previously in goldmark_extension.go but I moved it here to reflect that this stuff is about parsing and not about rendering.

for i, r := range normalized {
if i >= maximumHashtagLength || !util.IsPermittedInHashtag(r) {
ok = false
if r != '_' {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This prevents playing silly buggers and making a hashtag like #____________.

Unfortunately silly hashtags are still possible, so stuff like #a_______________________ is OK.

We might want to fix this up later or make it a bit more nuanced in terms of what it allows, but for now I figured this was OK.

package text

import "unicode"

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Moved these from the more central util package and unexported them, since they were only being used in internal/text.

isPermittedInHashtag(r)
}

func isPermittedInHashtag(r rune) bool {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This and the following function is where underscores get excepted. In other words, these are the actual fixes for #2199

@tsmethurst tsmethurst merged commit 536d9e4 into main Sep 29, 2023
@tsmethurst tsmethurst deleted the hashtag_underscore_fix branch September 29, 2023 08:39
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.

[bug] Hashtags can't contain underscores?
1 participant