mastodon / mastodon-ios

Official iOS app for Mastodon
https://app.joinmastodon.org/ios
GNU General Public License v3.0
2k stars 247 forks source link

[Feature]: Support newly added rich text formatting #1060

Open j-f1 opened 1 year ago

j-f1 commented 1 year ago

Description

Mastodon recently added support for several new HTML elements in incoming posts: https://github.com/mastodon/mastodon/pull/23913. The iOS app should support rendering these elements to the biggest extent possible.

Suggested Solution

I just opened a PR to our text rendering dependency, MetaTextKit, with support for many of the new elements: https://github.com/TwidereProject/MetaTextKit/pull/5

This adds support for: del, pre, code, b, strong, u, i, em

Not supported:

Alternatives

Additional Context

It would be great to have this at least partially supported before the changes are published in a stable release.

MainasuK commented 1 year ago

Hi @j-f1. That's a challenge. :)

The recent v4.1.2 still does not have this feature. I'd like to know where I could try this (an alpha server?) or if some examples in HTML cover all the cases. So the parser could make a unit test for all the edge cases. Please let me know. 😄

And the NSAttributedString (also AttributedString) is some raw material string with an additional meta dictionary. Then you customized the render of the TextKit layout engine.

I believe the TextKit could handle all the tags. Just calculate the region and draw the background or border.

WebView

Not sure placing so many WebView in the table view could still performance smooth.

Other apps

I don't know. But there are some repos that may help.

P.S.

The target of MetaTextKit is a text view that could highlight the meta content and work with AutoLayout. But I found some tricks to layout the cell more efficacy. The idea is UITableView always gives you the accurate readable content width. So the problem is to calculate the layout height in the given width. I'm not sure whether the AutoLayout is still required because I'm already migrating to the SwiftUI (in Twidere X).

Whatever, I will check it later, and happy WWDC.

j-f1 commented 1 year ago

Thanks for the reply and happy WWDC! I don’t know of a good example post to check, but if you sign up for/spin up a server running glitch-soc you should be able to create one

MainasuK commented 11 months ago

https://github.com/TwidereProject/MetaTextKit/tree/2.3.0

The MetaTextKit v2.3.0 finish the inline format supports now. The UI is based on the glitch-soc web app. I test the framework on iOS 16 with some inputs but not fully test. So please update to this version only after the Mastodon fully support the rich text and test it with more inputs and old iOS version.

For the implementation detail. Please check this PR

j-f1 commented 11 months ago

Thank you for finishing that up @MainasuK! Unfortunately I won’t be able to open a PR but hopefully one of the other maintainers can give it a shot.