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
Image recommendations - Add utility class to style HTML #4759
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Working nicely! Some minor optional stuff below from my first pass for future proofing if it also resonates with you, but happy to continue reviewing and approve as-is.
public static func nsAttributedStringFromHtml(_ html: String, styles: Styles) throws -> NSAttributedString { | ||
let attributedString = NSMutableAttributedString(string: html) | ||
let paragraphStyle = NSMutableParagraphStyle() | ||
paragraphStyle.lineSpacing = 3 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What do you think about propagating this value through Styles
as well?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done! One thing that's still a bit awkward here is that SwiftUI adds line spacing as a modifier, outside of the utility. I couldn't find any line spacing key while making AttributedString. I guess we could consider making a WKHtmlText
component or something, just for SwiftUI, with line spacing applied within so that we don't have to remember to add this modifier every time. Let me know what you think.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah a component that itself encapsulates those custom modifiers makes sense in the future to me too.
Phabricator:
https://phabricator.wikimedia.org/T356816
Notes
This PR creates a utility class for converting html strings into NSAttributedString and AttributedString. We need the AttributedString conversion to support attributed SwiftUI text views in the Components framework.
I believe I have covered all of the major needs from our old class in String+Html.swift, though note that I didn't strictly follow it. This utility supports:
I created some dummy UI to see both UI frameworks in action. Followup PRs for this task will be reusing the article intro view from the
T347121/prototype
, and connecting it to live data.Test Steps
Screenshots