-
Notifications
You must be signed in to change notification settings - Fork 1.2k
[MBL-2883] RichText parsing and conversion to Swift-friendly normalized types #2810
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
Merged
stevestreza-ksr
merged 6 commits into
main
from
stevestreza/sdui-content/parsing-rich-text
Apr 7, 2026
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
eec3e9f
RichText parsing
stevestreza-ksr a36933d
Add unit tests
stevestreza-ksr 01b455d
Fixes for code review comments
stevestreza-ksr b18e52f
Code review comments
stevestreza-ksr 0a39e44
Whoops wrong spot
stevestreza-ksr b5f63d4
Fix build and use Suite and Test labels for GQL tests
stevestreza-ksr File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,86 @@ | ||
| import Foundation | ||
|
|
||
| /// Represents a single block-level element in a RichText list. Used to make implementing | ||
| /// the different views in SwiftUI more easily and with a consistent interface. | ||
| public indirect enum RichTextElement { | ||
| case text(Text, HeaderLevel?) | ||
| case listItemOpen | ||
| case listItemClose | ||
| case listItem(Text) | ||
| case audio(Audio) | ||
| case photo(Photo) | ||
| case video(Video) | ||
| case oembed(Oembed) | ||
| case unknown | ||
|
|
||
| public struct Text { | ||
| public let text: String | ||
| public let link: URL? | ||
| public let styles: [Style] | ||
| public let children: [RichTextElement] | ||
|
|
||
| public enum Style: String { | ||
| case strong = "STRONG" | ||
| case emphasis = "EMPHASIS" | ||
| case heading1 = "HEADING_1" | ||
| case heading2 = "HEADING_2" | ||
| case heading3 = "HEADING_3" | ||
| case heading4 = "HEADING_4" | ||
| } | ||
| } | ||
|
|
||
| public enum HeaderLevel: String { | ||
| case one = "HEADING_1" | ||
| case two = "HEADING_2" | ||
| case three = "HEADING_3" | ||
| case four = "HEADING_4" | ||
|
|
||
| /// Create a HeaderLevel from an array of style strings from GraphQL, if | ||
| /// one is present | ||
| internal init?(styles: [String]?) { | ||
| for style in styles ?? [] { | ||
| if let level = HeaderLevel(rawValue: style) { | ||
| self = level | ||
| return | ||
| } | ||
| } | ||
| return nil | ||
| } | ||
stevestreza-ksr marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
|
|
||
| public struct Audio { | ||
| public let altText: String? | ||
| public let assetID: String? | ||
| public let caption: String? | ||
| public let url: String? | ||
| } | ||
|
|
||
| public struct Photo { | ||
| public let altText: String? | ||
| public let assetID: String? | ||
| public let caption: String? | ||
| public let url: String? | ||
| } | ||
|
|
||
| public struct Video { | ||
| public let altText: String? | ||
| public let assetID: String? | ||
| public let caption: String? | ||
| public let url: String? | ||
| } | ||
|
|
||
| public struct Oembed { | ||
| public let width: Int | ||
| public let height: Int | ||
| public let version: String | ||
| public let title: String | ||
| public let type: String | ||
|
|
||
| public let iframeUrl: String? | ||
| public let originalUrl: String? | ||
|
|
||
| public let thumbnailUrl: String? | ||
| public let thumbnailWidth: Int? | ||
| public let thumbnailHeight: Int? | ||
| } | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.