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

Support to display a limited set of HTML tags (aligned with mastodon PR #23913) plus URL support #356

Closed
wants to merge 53 commits into from

Conversation

danschwarz
Copy link
Collaborator

@danschwarz danschwarz commented May 15, 2023

This is essentially a rewrite of the closed PR #348 using @AnonymouX47 's TextEmbed widget from urwidgets. It does not suffer from the rendering issue that caused problems for the previous PR, that used urwid.Text. As a bonus, it includes support for clickable links on terminals that support OCS 8 hyperlinks.

This PR renders all HTML elements, and some HTML attributes, that will be supported in Mastodon 4.2 spec

HTML Status on a glitch-soc server

image

The same status on the TUI with this PR

image

As the urwidgets dependency is Python 3.7+, I have removed the Python 3.6 automated Github tests.

danschwarz and others added 30 commits March 31, 2023 21:06
Title is now a positional parameter.

Also added some error handling in the command processing
for looking up list IDs per @ihabunek 's suggestions
Also don't check if account is found, that function alredy raises a
ConsoleError.
Top level widgets are separated by blank lines, but
The final blank line of the status is omitted. This exactly
matches existing status rendering in master, for statuses that
contain only the currently supported tags
No longer specifying color "white" when it's more correct to
omit the color and just specify an attribute like underline,
bold, etc.
If the class name appears in the constants.py PALETTE entry, it is
honored. Otherwise, the class is ignored and the tag is handled
as a generic tag of that type.  This allows hashtag anchors
to be highlighted, and URL anchors to be styled differently
regardless of the strange class markup that Akkoma adds to URL
anchors
danschwarz and others added 10 commits April 6, 2023 23:28
Uses the Hyperlink widget along with TextEmbed widget
We see this problem with statuses from Pixelfed servers.
Per the Mastodon API spec, the content tag is supposed to be
HTML, but Pixelfed sends statuses that often start as plain text.
They may include embedded anchor tags etc. within the text.
This confuses BeautifulSoup HTML parsers and results in bad
rendering artifacts.

This workaround detects the above condition and attempts to fix it by
surrounding the status in <p></p>. This converts it to nominally
valid HTML (at least, parseable by BeautifulSoup.)
Also, hashtags are created as OCS-8 hyperlinks, so they are
directly clickable in terminals that support OCS-8
Also, now renders HTML in Account overlay page
Also, removed Python 3.6 tests as urwidgets is Python 3.7+
README.rst Outdated Show resolved Hide resolved
Pleroma, Akkoma, and other servers do not follow the Mastodon spec
for the 'uri' attribute which specifies that it contains the domain
name of the instance. Instead, they return a complete URI.

As a workaround, we now detect this situation and parse out the
domain from the URI when necessary. This fixes issue ihabunek#347.

Thanks to @laleanor for their patch and @rjp for ideas on how to
make it work with GotoSocial and other servers
Previously this only worked for anchor tags with nested spans.
Now it works for anchor tags with or without nested spans.
@danschwarz
Copy link
Collaborator Author

Update- I've got a new version of this PR that removes the hard dependency on the urwidgets library. If you have urwidgets installed, it works with full functionality including OCS 8 support for hyperlinks. If you do not have urwidgets, it still works, all HTML tags are shown properly, but hyperlinks display as plain text. When it's good enough to submit, I'll close out this PR and open up a new one.

@danschwarz
Copy link
Collaborator Author

Closed in favor of #403 PR which is the same code as above, without the hard dependency

@danschwarz danschwarz closed this Sep 22, 2023
@danschwarz danschwarz deleted the rt-hyperlinks branch January 21, 2024 03:08
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.

3 participants