Created
July 28, 2025 23:46
-
-
Save seanho/9b11c2b0b1f6207bcbfe097e6e849603 to your computer and use it in GitHub Desktop.
AttribuedString markdown parsing
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
| let attrString = try AttributedString(markdown: markdown) | |
| for (intentBlock, intentRange) in attrString.runs[\.presentationIntent] { | |
| guard let intentBlock else { continue } | |
| for intent in intentBlock.components { | |
| switch intent.kind { | |
| case .paragraph: | |
| case let .header(level): | |
| case .orderedList: | |
| case .unorderedList: | |
| case let .listItem(ordinal): | |
| case let .codeBlock(languageHint): | |
| case .blockQuote: | |
| case .thematicBreak: | |
| case let .table(columns): | |
| case .tableHeaderRow: | |
| case let .tableRow(rowIndex): | |
| case let .tableCell(columnIndex): | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment