Open j-f1 opened 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.
NSLayoutManager
NSTextViewportLayoutControllerDelegate
I believe the TextKit
could handle all the tags. Just calculate the region and draw the background or border.
Not sure placing so many WebView
in the table view could still performance smooth.
I don't know. But there are some repos that may help.
CoreText
. 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.
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
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
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.
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/5This adds support for:
del
,pre
,code
,b
,strong
,u
,i
,em
Not supported:
blockquote
requires some sort of custom rendering to inject the vertical bar to the left side (or for the design folks to come up with an acceptable blockquote style that fits better within the constraints ofNSAttributedString
)ul
/ol
,li
require rewriting the plain text content of the post to add in markers (e.g.1.
or•
). This doesn’t pose any visual challenges, but there are some thorny issues:NSParagraphStyle
(including computing the width of the marker????) or just accept the bullets being rendered more like inline strings.Alternatives
UITextView
but I don’t know by how much, especially since the web has had a ton of investment put into it. But they definitely have some latency which could result in briefly seeing the wrong post content when scrolling rapidly)Additional Context
It would be great to have this at least partially supported before the changes are published in a stable release.