{"id":13872236,"url":"https://github.com/SwiftDocOrg/CommonMark","last_synced_at":"2025-07-16T02:30:28.736Z","repository":{"id":52201179,"uuid":"235409159","full_name":"SwiftDocOrg/CommonMark","owner":"SwiftDocOrg","description":"Create, parse, and render Markdown text according to the CommonMark specification ","archived":true,"fork":false,"pushed_at":"2021-05-05T13:56:20.000Z","size":232,"stargazers_count":179,"open_issues_count":3,"forks_count":10,"subscribers_count":5,"default_branch":"main","last_synced_at":"2024-11-07T10:53:51.647Z","etag":null,"topics":["cmark","commonmark","markdown","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/SwiftDocOrg.png","metadata":{"files":{"readme":"README.md","changelog":"Changelog.md","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-01-21T18:10:39.000Z","updated_at":"2024-07-02T20:05:58.000Z","dependencies_parsed_at":"2022-09-09T18:55:09.878Z","dependency_job_id":null,"html_url":"https://github.com/SwiftDocOrg/CommonMark","commit_stats":null,"previous_names":[],"tags_count":13,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SwiftDocOrg%2FCommonMark","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SwiftDocOrg%2FCommonMark/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SwiftDocOrg%2FCommonMark/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SwiftDocOrg%2FCommonMark/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/SwiftDocOrg","download_url":"https://codeload.github.com/SwiftDocOrg/CommonMark/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":226095617,"owners_count":17572963,"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":["cmark","commonmark","markdown","swift"],"created_at":"2024-08-05T23:00:37.674Z","updated_at":"2024-11-23T20:30:45.854Z","avatar_url":"https://github.com/SwiftDocOrg.png","language":"Swift","funding_links":[],"categories":["Swift"],"sub_categories":[],"readme":"# CommonMark\n\n![CI][ci badge]\n[![Documentation][documentation badge]][documentation]\n\nA Swift package for working with [CommonMark][commonmark] text.\nIt's built on top of [libcmark][cmark] \nand fully compliant with the [CommonMark Spec][commonmark].\n\n## Usage\n\n```swift\nimport CommonMark\n\nlet markdown = #\"\"\"\n# [Universal Declaration of Human Rights][udhr]\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[udhr]: https://www.un.org/en/universal-declaration-human-rights/ \"View full version\"\n\"\"\"#\n\nlet document = try Document(markdown)\n```\n\n### Inspecting Document Nodes\n\n```swift\ndocument.children.count // 3\n\nlet heading = document.children[0] as! Heading\nheading.headerLevel // 1\nheading.children.count // 1\n\nlet link = heading.children[0] as! Link\nlink.urlString // \"https://www.un.org/en/universal-declaration-human-rights/\")\nlink.title // \"View full version\"\n\nlet subheading = document.children[1] as! Heading\nsubheading.headerLevel // 2\nsubheading.children.count // 1\n\nlet subheadingText = subheading.children[0] as! Text\nsubheadingText.literal // \"Article 1.\"\n\nlet paragraph = document.children[2] as! Paragraph\nparagraph.description // \"All human beings [ ... ]\"\nparagraph.range.lowerBound // (line: 5, column: 1)\nparagraph.range.upperBound // (line: 7, column: 62)\n```\n\n### Rendering to HTML, XML, LaTeX, and Manpage\n\n```swift\nlet html = document.render(format: .html) // \u003ch1\u003e [ ... ]\nlet xml = document.render(format: .xml) // \u003c?xml [ ... ]\nlet latex = document.render(format: .latex) // \\section{ [ ... ]\nlet manpage = document.render(format: .manpage) // .SH [ ... ]\n\n// To get back CommonMark text, \n// you can either render with the `.commonmark` format...\ndocument.render(format: .commonmark) // # [Universal  [ ... ]\n// ...or call `description`\n// (individual nodes also return their CommonMark representation as their description)\ndocument.description // # [Universal  [ ... ]\n```\n\n### Creating Documents From Scratch\n\n#### Using Result Builders\n\nIn Swift 5.4 and later,\nyou can create CommonMark documents using `@resultBuilder` initializers.\n\n```swift\nimport CommonMark\n\nlet document = Document {\n    Heading {\n        Link(urlString: \"https://www.un.org/en/universal-declaration-human-rights/\",\n                title: \"View full version\")\n        {\n            \"Universal Declaration of Human Rights\"\n        }\n    }\n\n    Section { // sections increase the level of contained headings\n        Heading { \"Article 1.\" } // this is a second-level heading\n    }\n\n    // block-level strings are parsed as CommonMark literals\n    \"\"\"\n    **All** human beings are born free and equal in dignity and rights.\n    They are endowed with reason and conscience\n    and should act towards one another in a spirit of brotherhood.\n    \"\"\"\n}\n```\n\n#### Using the Conventional Approach\n\nThe following code produces the same result as the preceding example,\nusing conventional Swift initializers.\n\n```swift\nlet link = Link(urlString: \"https://www.un.org/en/universal-declaration-human-rights/\",\n                title: \"View full version\", \n                text: \"Universal Declaration of Human Rights\")\nlet heading = Heading(level: 1, children: [link])\n\nlet subheading = Heading(level: 2, text: \"Article 1.\")\n\nlet paragraph = Paragraph(children: #\"\"\"\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\"\"\"#.split(separator: \"\\n\")\n    .flatMap { [Text(String($0)), SoftLineBreak()] })\n\nDocument(children: [heading, subheading, paragraph]).description == document.description // true\n```\n\n## CommonMark Spec Compliance\n\nThis package passes all of the 649 test cases\nin the latest version (0.29) of the [CommonMark Spec][commonmark spec]:\n\n```console\n$ swift test\n\t Executed 649 tests, with 0 failures (0 unexpected) in 0.178 (0.201) seconds\n```\n\n## Requirements\n\n- Swift 5.1+\n\n## Installation\n\n### Swift Package Manager\n\nAdd the CommonMark 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/SwiftDocOrg/CommonMark\",\n        from: \"0.5.1\"\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[cmark]: https://github.com/commonmark/cmark\n[commonmark]: https://commonmark.org\n[commonmark spec]: https://spec.commonmark.org\n\n[ci badge]: https://github.com/SwiftDocOrg/CommonMark/workflows/CI/badge.svg\n[documentation badge]: https://github.com/SwiftDocOrg/CommonMark/workflows/Documentation/badge.svg\n[documentation]: https://github.com/SwiftDocOrg/CommonMark/wiki\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FSwiftDocOrg%2FCommonMark","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FSwiftDocOrg%2FCommonMark","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FSwiftDocOrg%2FCommonMark/lists"}