{"id":13995407,"url":"https://github.com/mattt/CommonMarkAttributedString","last_synced_at":"2025-07-22T21:32:50.902Z","repository":{"id":63917285,"uuid":"245431458","full_name":"mattt/CommonMarkAttributedString","owner":"mattt","description":"Create NSAttributedStrings from Markdown Text","archived":true,"fork":false,"pushed_at":"2021-08-04T21:42:05.000Z","size":33,"stargazers_count":424,"open_issues_count":4,"forks_count":17,"subscribers_count":6,"default_branch":"main","last_synced_at":"2025-06-21T00:31:56.036Z","etag":null,"topics":["cmark","commonmark","markdown","nsattributedstring","swift"],"latest_commit_sha":null,"homepage":"","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/mattt.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2020-03-06T13:49:20.000Z","updated_at":"2024-10-29T16:33:23.000Z","dependencies_parsed_at":"2023-01-14T13:45:18.610Z","dependency_job_id":null,"html_url":"https://github.com/mattt/CommonMarkAttributedString","commit_stats":null,"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"purl":"pkg:github/mattt/CommonMarkAttributedString","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mattt%2FCommonMarkAttributedString","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mattt%2FCommonMarkAttributedString/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mattt%2FCommonMarkAttributedString/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mattt%2FCommonMarkAttributedString/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mattt","download_url":"https://codeload.github.com/mattt/CommonMarkAttributedString/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mattt%2FCommonMarkAttributedString/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":266496610,"owners_count":23938714,"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","status":"online","status_checked_at":"2025-07-22T02:00:09.085Z","response_time":66,"last_error":null,"robots_txt_status":null,"robots_txt_updated_at":null,"robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":["cmark","commonmark","markdown","nsattributedstring","swift"],"created_at":"2024-08-09T14:03:23.380Z","updated_at":"2025-07-22T21:32:50.589Z","avatar_url":"https://github.com/mattt.png","language":"Swift","readme":"# CommonMarkAttributedString\n\n![CI][ci badge]\n[![Documentation][documentation badge]][documentation]\n\n**CommonMarkAttributedString** is a Swift package that lets you\ncreate attributed strings using familiar CommonMark (Markdown) syntax.\nIt's built on top of [CommonMark][commonmark],\nwhich is fully compliant with the [CommonMark Spec][commonmark spec].\n\n## Supported Platforms\n\n- macOS 10.10+\n- Mac Catalyst 13.0+\n- iOS 9.0+\n- tvOS 9.0+\n\n## Usage\n\n```swift\nimport CommonMarkAttributedString\n\nlet commonmark = \"A *bold* way to add __emphasis__ to your `code`\"\n\nlet attributes: [NSAttributedString.Key: Any] = [\n    .font: NSFont.systemFont(ofSize: 24.0),\n    .foregroundColor: NSColor.systemBlue,\n]\n\nlet attributedString = try NSAttributedString(commonmark: commonmark, attributes: attributes)\n```\n\n![Result][screenshot-1]\n\nYou can also use CommonMarkAttributedString\nto create attributed strings that have multiple paragraphs,\nwith links, headings, lists, and images.\n\n```swift\nlet commonmark = #\"\"\"\n# [Universal Declaration of Human Rights][uhdr]\n\n## Article 1.\n\nAll human beings are born free and equal in dignity and rights.\nThey are endowed with reason and conscience\nand should act towards one another in a spirit of brotherhood.\n\n[uhdr]: https://www.un.org/en/universal-declaration-human-rights/ \"View full version\"\n\"\"\"#\n\nlet attributes: [NSAttributedString.Key: Any] = [\n    .font: NSFont.systemFont(ofSize: NSFont.systemFontSize),\n    .foregroundColor: NSColor.textColor,\n    .backgroundColor: NSColor.textBackgroundColor,\n]\n\nlet attributedString = try NSAttributedString(commonmark: commonmark, attributes: attributes)\n```\n\n![Result][screenshot-2]\n\n## Supported CommonMark Elements\n\n- [x] `Code`\n- [x] _Emphasis_\n- [x] [Link](#) _(inline links, link references, and autolinks)_\n- [x] **Strong**\n- [x] \u003e Block Quotes\n- [x] Headings\n- [x] Raw `\u003chtml\u003e` \u003csup\u003e*\u003c/sup\u003e\n- [x] • Bulleted Lists \u003csup\u003e*\u003c/sup\u003e\n- [x] 1. Ordered Lists \u003csup\u003e*\u003c/sup\u003e\n- [x] 🖼 Images \u003csup\u003e*\u003c/sup\u003e\n\n### Raw Inline HTML\n\nAccording to the [CommonMark specification][commonmark spec § 6.8],\neach inline HTML tag is considered its own element.\nThat is to say,\nCommonMark doesn't have a concept of opening or closing tags.\nSo, for example,\nthe CommonMark string `\u003cspan style=\"color: red;\"\u003ehello\u003c/span\u003e`\ncorresponds to a paragraph block containing three inline elements:\n\n- `Code` (`\u003cspan style=\"color: red;\"\u003e`)\n- `Text` (`hello`)\n- `Code` (`\u003c/span\u003e`)\n\nParsing and rendering HTML is out of scope for this library,\nso whenever CommonMarkAttributedString receives text containing any HTML,\nit falls back on `NSAttributedString`'s built-in HTML initializer.\n\n### Bulleted and Ordered Lists\n\nCommonMarkAttributedString renders bulleted and ordered lists\nusing conventional indentation and markers ---\ndisc (•), circle(◦), and square (■) \nfor unordered lists\nand\ndecimal numerals (1.), lowercase roman numerals (i.), and lowercase letters (a.)\nfor ordered lists.\n\n- Level 1\n    - Level 2\n        - Level 3\n\n\u003chr/\u003e\n\n1. Level 1\n    1. Level 2\n        1. Level 3\n\n\n### Images\n\nAttributed strings can embed images using the `NSTextAttachment` class.\nHowever,\nthere's no built-in way to load images asynchronously.\nRather than load images synchronously as they're encountered in CommonMark text,\nCommonMarkAttributedString provides an optional `attachments` parameter\nthat you can use to associate existing text attachments\nwith image URL strings.\n\n```swift\nlet commonmark = \"![](https://example.com/image.png)\"\n\nlet attachments: [String: NSTextAttachment] = [\n    \"https://example.com/image.png\": NSTextAttachment(data: \u003c#...#\u003e, ofType: \"public.png\")\n]\n\nlet attributedString = try NSAttributedString(commonmark: commonmark, attributes: attributes, attachments: attachments)\n```\n\n\n## Requirements\n\n- Swift 5.1+\n\n## Installation\n\n### Swift Package Manager\n\nAdd the CommonMarkAttributedString package to your target dependencies in `Package.swift`:\n\n```swift\nimport PackageDescription\n\nlet package = Package(\n  name: \"YourProject\",\n  dependencies: [\n    .package(\n        url: \"https://github.com/mattt/CommonMarkAttributedString\",\n        from: \"0.2.0\"\n    ),\n  ]\n)\n```\n\nThen run the `swift build` command to build your project.\n\n## License\n\nMIT\n\n## Contact\n\nMattt ([@mattt](https://twitter.com/mattt))\n\n[commonmark]: https://github.com/SwiftDocOrg/CommonMark\n[commonmark spec]: https://spec.commonmark.org\n[commonmark spec § 6.8]: https://spec.commonmark.org/0.29/#raw-html\n\n[screenshot-1]: https://user-images.githubusercontent.com/7659/76089806-35fcf400-5f6f-11ea-934c-b676b6af99cf.png\n[screenshot-2]: https://user-images.githubusercontent.com/7659/76094168-fe924580-5f76-11ea-821b-aa2f07c0e21b.png\n\n[ci badge]: https://github.com/mattt/CommonMarkAttributedString/workflows/CI/badge.svg\n[documentation badge]: https://github.com/mattt/CommonMarkAttributedString/workflows/Documentation/badge.svg\n[documentation]: https://github.com/mattt/CommonMarkAttributedString/wiki\n","funding_links":[],"categories":["Swift"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmattt%2FCommonMarkAttributedString","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmattt%2FCommonMarkAttributedString","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmattt%2FCommonMarkAttributedString/lists"}