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

Rich text simplification #412

Merged
merged 15 commits into from
Nov 16, 2023
Merged

Rich text simplification #412

merged 15 commits into from
Nov 16, 2023

Conversation

ihabunek
Copy link
Owner

Hi! Sorry it took me so long. I found your pull request a bit too complex, so did some work to simplify it to something that's easier to follow. Please check out the commits where I explained briefly what I did.

In general:

  • don't use classes where not needed
  • remove "magic" method calling and replace with good old if-else
  • simplify stubbing
  • don't duplicate code if possible
  • simplify code where possible

I did test the result a bit on mastodon 4.2.0-glitch which I installed locally. I think I didn't break anything.

Having the choice explicit makes the code easier to read.
It did not help, just added to the indent.
This was doing double regex matching, calling parse_text was not needed
at all.
This is the first step towards easier stubbing
Remove has_urwidgets since we no longer need to worry if we have
urwidgets in the richtext module.
@ihabunek ihabunek requested a review from danschwarz November 16, 2023 11:00
@ihabunek ihabunek self-assigned this Nov 16, 2023
@ihabunek
Copy link
Owner Author

@danschwarz Can you tell me what's the point of urlencode_url?

I tried removing the call to it and encoding urls still worked well.

@danschwarz
Copy link
Collaborator

Hi, thanks for the detailed review and changes. I believe that the issue here was that we need our URL to be urlencoded. But when we were presented with an already-urlencoded URL, we'd urlencode it again, and that'd corrupt it.

It's harmless to urldecode an unencoded URL so adding this decode/encode step ensures that our URL is urlencoded once and only once.

I should've added a test case for this when I wrote it; I'll try to do so later.

@danschwarz
Copy link
Collaborator

Your PR looks good to me overall, despite the test failure (it can't import the 'urwidgets' library for some reason, even though we satisfy the Python >= 3.7 requirement.) Not sure how to fix that.

I see that you've addressed the situation where we don't have urwidgets at runtime by falling back to the old renderer. This eliminates the mess of stub libraries that I added. I'm OK with that tradeoff.

@danschwarz danschwarz merged commit 584f598 into danschwarz-richtext3 Nov 16, 2023
0 of 10 checks passed
@danschwarz
Copy link
Collaborator

Fixed it to build properly by pulling in the required "extra", which in turn pulls in urwidgets

@ihabunek ihabunek deleted the rich branch November 18, 2023 14:36
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.

2 participants