{"id":20742517,"url":"https://github.com/frankrausch/attributedstringstyledmarkdown","last_synced_at":"2025-04-24T05:12:07.158Z","repository":{"id":41480677,"uuid":"429485828","full_name":"frankrausch/AttributedStringStyledMarkdown","owner":"frankrausch","description":"AttributedString Markdown initializer with custom styling","archived":false,"fork":false,"pushed_at":"2021-11-18T15:49:04.000Z","size":1135,"stargazers_count":79,"open_issues_count":1,"forks_count":3,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-04-24T05:11:46.704Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Swift","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/frankrausch.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2021-11-18T15:40:46.000Z","updated_at":"2025-03-27T18:17:38.000Z","dependencies_parsed_at":"2022-09-21T15:03:56.290Z","dependency_job_id":null,"html_url":"https://github.com/frankrausch/AttributedStringStyledMarkdown","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/frankrausch%2FAttributedStringStyledMarkdown","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/frankrausch%2FAttributedStringStyledMarkdown/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/frankrausch%2FAttributedStringStyledMarkdown/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/frankrausch%2FAttributedStringStyledMarkdown/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/frankrausch","download_url":"https://codeload.github.com/frankrausch/AttributedStringStyledMarkdown/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":250566509,"owners_count":21451232,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-17T07:06:06.188Z","updated_at":"2025-04-24T05:12:07.136Z","avatar_url":"https://github.com/frankrausch.png","language":"Swift","funding_links":[],"categories":[],"sub_categories":[],"readme":"# AttributedString Markdown initializer with custom styling\n\n[`AttributedString`](https://developer.apple.com/documentation/foundation/attributedstring) in iOS 15 and macOS 12 comes with a [Markdown initializer](https://developer.apple.com/documentation/foundation/attributedstring/3796160-init).\n\n----\n\nBut:\n\n- There is no styling (not even bold or italic) when [drawing](https://developer.apple.com/documentation/foundation/nsattributedstring/1524971-draw) the `AttributedString` in a custom view.\n- The `AttributedString` does have some styling applied when it’s assigned to a `UILabel` or to a `UITextView`, but they are noticeably different and weird things happen with the font sizes.\n- All line breaks that should separate the content blocks are missing.\n- The `AttributedString` colors don’t react to toggling between dark and light mode.\n\n## What’s going on?\n\nThere is not a lot of information about Markdown in `AttributedString` out there yet, but I think I was just [holding it wrong](https://www.urbandictionary.com/define.php?term=You%27re%20Holding%20It%20Wrong):\n\nThe Markdown initializer merely adds *semantic* (not visual) markup to the `AttributedString`. Both `UILabel` and `UITextView` interpret these to a certain extent, while drawing a raw `(NS)AttributedString` doesn’t.\n\nThe Markdown initializer merely puts the Markdown parsing results as [*Presentation Intents*](https://developer.apple.com/documentation/foundation/nspresentationintent) into the `AttributedString` runs.\n- There are `inlinePresentationIntent`s, e.g. `.stronglyEmphasized` for bold text.\n- There are `presentationIntent`s for blocks like headlines (like `.header(1)` for a `H1`).\n\n## This sample project\n\nThis sample project shows how you can find these intents and replace them with actual `AttributedString` styling information like font weights and foreground colors.\n\nI don’t know if there’s a more elegant way to solve this.\nDo let me know if you have a better solution!\n\n![AttributedString Markdown Light](attributedstring-markdown-light.jpg)\n\n![AttributedString Markdown Dark](attributedstring-markdown-dark.jpg)\n\n----\n\n© 2021 [Frank Rausch](https://twitter.com/frankrausch)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffrankrausch%2Fattributedstringstyledmarkdown","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffrankrausch%2Fattributedstringstyledmarkdown","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffrankrausch%2Fattributedstringstyledmarkdown/lists"}