-
Notifications
You must be signed in to change notification settings - Fork 213
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
Styled markdown with AttributedString #3590
base: develop
Are you sure you want to change the base?
Conversation
…ing in the MarkdownFormatter
Generated by 🚫 Danger |
SDK Performance
|
SDK Size
|
…g and UITextView overrides it
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.
Overall looks good, just asked a couple of questions 👍
Sources/StreamChat/Extensions/AttributedString+Extensions.swift
Outdated
Show resolved
Hide resolved
Sources/StreamChatUI/Appearance+Formatters/MarkdownFormatter.swift
Outdated
Show resolved
Hide resolved
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.
Overall LGTM ✅ Just added a couple of comments. Also, as @martinmitrevski suggested, it would be nice that for code snippets, the whole paragraph as the same background color if possible 🤔
Sources/StreamChatUI/Appearance+Formatters/MarkdownFormatter.swift
Outdated
Show resolved
Hide resolved
… line breaks in a better way
…ithub.com/GetStream/stream-chat-swift into feature/attributed-string-styled-markdown
|
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.
LGTM! ✅
🔗 Issue Links
Resolves: IOS-41
🎯 Goal
Use AttributedString's markdown parsing support and apply styling on top of it.
📝 Summary
DefaultMarkdownFormatter
to use new AttributedString's markdown supportMarkdownParser
(will be used by the SwiftUI SDK)MarkdownStyles.linkFont
because UITextView overrides link attributes🛠 Implementation
Added MarkdownParser to the LLC which can be used by UIKit and SwiftUI SDKs. It deals with applying additional attributes (injected via a closure because UIKit and SwiftUI use different logic) to various blocks (quote, code, etc). Since SwiftUI text rendering does not support NSParagraphStyle, the extension currently copes with this by adding additional newlines (alternative would have been separate logic for UIKit and SwiftUI, but it felt unnecessary to complicate it so much for our needs).
UIKit also has customisation just for Markdown through
MarkdownStyles
andMarkdownFont
types where the latter is just changes to the default color and font (e.g. I can say that just change font size to 30, but keep using the default font).Important
MarkdownStyles.linkFont
does not really work because we use UITextView in the UIKit for rendering text and UITextView'slinkTextAttributes
is the one which drives the styling. Therefore,MarkdownStyles.linkFont.color = .green
does not actually do anything in the UIKit SDK.Note
Code blocks would need
NSLayoutManager
level customisation for background, can't be done with purely AttributedString. Considered this out of scope of this PR.🎨 Showcase
Performance
Compared the performance of the new and old implementation and roughly the new is 2x faster (tried a channel with multiple large messages with markdown).
🧪 Manual Testing Notes
@username
,@userid
) + plain links☑️ Contributor Checklist
docs-content
repo