{"id":13872228,"url":"https://github.com/SwiftDocOrg/Markup","last_synced_at":"2025-07-16T02:30:28.496Z","repository":{"id":48977979,"uuid":"248605578","full_name":"SwiftDocOrg/Markup","owner":"SwiftDocOrg","description":"A Swift package for working with HTML, XML, and other markup languages, based on libxml2.","archived":true,"fork":false,"pushed_at":"2021-10-17T13:12:48.000Z","size":108,"stargazers_count":111,"open_issues_count":5,"forks_count":9,"subscribers_count":5,"default_branch":"main","last_synced_at":"2024-11-14T18:54:45.215Z","etag":null,"topics":["dtd","html","libxml2","relax-ng","swift","xml","xpath","xslt"],"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/SwiftDocOrg.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-19T21:09:45.000Z","updated_at":"2024-11-02T18:00:04.000Z","dependencies_parsed_at":"2022-09-04T07:00:52.910Z","dependency_job_id":null,"html_url":"https://github.com/SwiftDocOrg/Markup","commit_stats":null,"previous_names":[],"tags_count":8,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SwiftDocOrg%2FMarkup","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SwiftDocOrg%2FMarkup/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SwiftDocOrg%2FMarkup/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SwiftDocOrg%2FMarkup/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/SwiftDocOrg","download_url":"https://codeload.github.com/SwiftDocOrg/Markup/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":226095607,"owners_count":17572959,"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":["dtd","html","libxml2","relax-ng","swift","xml","xpath","xslt"],"created_at":"2024-08-05T23:00:37.398Z","updated_at":"2024-11-23T20:30:43.979Z","avatar_url":"https://github.com/SwiftDocOrg.png","language":"Swift","funding_links":[],"categories":["Swift"],"sub_categories":[],"readme":"# Markup\n\n![CI][ci badge]\n[![Documentation][documentation badge]][documentation]\n\nA Swift package for working with HTML, XML, and other markup languages,\nbased on [libxml2][libxml2].\n\n**This project is under active development and is not ready for production use.**\n\n## Features\n\n- [x] XML Support\n- [x] XHTML4 Support\n- [x] XPath Expression Evaluation\n- [ ] HTML5 Support (using [Gumbo][gumbo])\n- [ ] CSS Selector to XPath Functionality\n- [ ] XML Namespace Support\n- [ ] DTD and Relax-NG Validation\n- [ ] XInclude Support\n- [ ] XSLT Support\n- [ ] SAX Parser Interface\n- [x] HTML and XML Function Builder Interfaces\n\n## Requirements\n\n- Swift 5.1+\n- [libxml2][libxml2] _(except for macOS with Xcode 11.4 or later)_\n\n## Usage\n\n### XML\n\n#### Parsing \u0026 Introspection\n\n```swift\nimport XML\n\nlet xml = #\"\"\"\n\u003c?xml version=\"1.0\" encoding=\"UTF-8\"?\u003e\n\u003c!-- begin greeting --\u003e\n\u003cgreeting\u003eHello!\u003c/greeting\u003e\n\u003c!-- end greeting --\u003e\n\"\"\"#\n\nlet document = try XML.Document(string: xml)!\ndocument.root?.name // \"greeting\"\ndocument.root?.content // \"Hello!\"\n\ndocument.children.count // 3 (two comment nodes and one element node)\ndocument.root?.children.count // 1 (one text node)\n```\n\n#### Searching and XPath Expression Evaluation\n\n```swift\ndocument.search(\"//greeting\").count // 1\ndocument.evaluate(\"//greeting/text()\") // .string(\"Hello!\")\n```\n\n#### Modification\n\n```swift\nfor case let comment as Comment in document.children {\n    comment.remove()\n}\n\ndocument.root?.name = \"valediction\"\ndocument.root?[\"lang\"] = \"it\"\ndocument.root?.content = \"Arrivederci!\"\n\ndocument.description // =\u003e\n/*\n\u003c?xml version=\"1.0\" encoding=\"UTF-8\"?\u003e\n\u003cvalediction lang=\"it\"\u003eArrivederci!\u003c/valediction\u003e\n\n*/\n```\n\n* * *\n\n### HTML\n\n#### Parsing \u0026 Introspection\n\n```swift\nimport HTML\n\nlet html = #\"\"\"\n\u003c!DOCTYPE html\u003e\n\u003chtml lang=\"en\"\u003e\n\u003chead\u003e\n    \u003cmeta charset=\"UTF-8\"\u003e\n    \u003cmeta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\"\u003e\n    \u003ctitle\u003eWelcome\u003c/title\u003e\n\u003c/head\u003e\n\u003cbody\u003e\n    \u003cp\u003eHello, world!\u003c/p\u003e\n\u003c/body\u003e\n\u003c/html\u003e\n\"\"\"#\n\nlet document = try HTML.Document(string: html)!\ndocument.body?.children.count // 1 (one element node)\ndocument.body?.children.first?.name // \"p\"\ndocument.body?.children.first?.text // \"Hello, world!\"\n```\n\n#### Searching and XPath Expression Evaluation\n\n```swift\ndocument.search(\"/body/p\").count // 1\ndocument.search(\"/body/p\").first?.xpath // \"/body/p[0]\"\ndocument.evaluate(\"/body/p/text()\") // .string(\"Hello, world!\")\n```\n\n#### Creation and Modification\n\n```swift\nlet div = Element(name: \"div\")\ndiv[\"class\"] = \"wrapper\"\nif let p = document.search(\"/body/p\").first {\n    p.wrap(inside: div)\n}\n\ndocument.body?.description // =\u003e\n/*\n\u003cdiv class=\"wrapper\"\u003e\n    \u003cp\u003eHello, world!\u003c/p\u003e\n\u003c/div\u003e\n*/\n```\n\n#### Builder Interface\n\nAvailable in Swift 5.3+.\n\n```swift\nimport HTML\n\nlet document = HTML.Document {\n    html([\"lang\": \"en\"]) {\n        head {\n            meta([\"charset\": \"UTF-8\"])\n            title { \"Hello, world!\" }\n        }\n\n        body([\"class\": \"beautiful\"]) {\n            div([\"class\": \"wrapper\"]) {\n                span { \"Hello,\" }\n                tag(\"span\") { \"world!\" }\n            }\n        }\n    }\n}\n\ndocument.description // =\u003e\n/*\n\u003chtml lang=\"en\"\u003e\n  \u003chead\u003e\n      \u003cmeta charset=\"UTF-8\"\u003e\n      \u003ctitle\u003eHello, world!\u003c/title\u003e\n  \u003c/head\u003e\n  \u003cbody class=\"beautiful\"\u003e\n      \u003c?greeter start\u003e\n      \u003cdiv class=\"wrapper\"\u003e\n          \u003cspan\u003eHello,\u003c/span\u003e\n          \u003cspan\u003eworld!\u003c/span\u003e\n      \u003c/div\u003e\n      \u003c?greeter end\u003e\n  \u003c/body\u003e\n\u003c/html\u003e\n\n*/\n```\n\n## Installation\n\n### Swift Package Manager\n\nIf you're on Linux or if you're on macOS and using Xcode \u003c 11.4,\ninstall the [libxml2][libxml2] system library:\n\n```terminal\n# macOS for Xcode 11.3 and earlier\n$ brew install libxml2\n$ brew link --force libxml2\n\n# Linux (Ubuntu)\n$ sudo apt-get install libxml2-dev\n```\n\nAdd the Markup 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/Markup\",\n        from: \"0.1.2\"\n    ),\n  ]\n)\n```\n\nAdd `Markup` as a dependency to your target(s):\n\n```swift\ntargets: [\n.target(\n    name: \"YourTarget\",\n    dependencies: [\"Markup\"]),\n```\n\nIf you're using Markup in an app,\nlink `libxml2` to your target.\nOpen your Xcode project (`.xcodeproj`) or workspace (`.xcworkspace`) file,\nselect your top-level project entry in the Project Navigator,\nand select the target using Markup listed under the Targets heading. \nNavigate to the \"Build Phases\" tab,\nexpand \"Link Binary With Libraries\",\nand click the \u003ckbd\u003e+\u003c/kbd\u003e button to add a library.\nEnter \"libxml2\" to the search bar,\nselect \"libxml2.tbd\" from the filtered list,\nand click the Add button.\n\n\u003cimg width=\"512\" alt=\"Add libxml2 library to your target\" src=\"https://user-images.githubusercontent.com/7659/120312587-c7036d80-c28d-11eb-9388-d523c5f6916f.png\"\u003e\n\n## License\n\nMIT\n\n## Contact\n\nMattt ([@mattt](https://twitter.com/mattt))\n\n[libxml2]: http://xmlsoft.org\n[gumbo]: https://github.com/google/gumbo-parser\n[ci badge]: https://github.com/SwiftDocOrg/Markup/workflows/CI/badge.svg\n[documentation badge]: https://github.com/SwiftDocOrg/Markup/workflows/Documentation/badge.svg\n[documentation]: https://github.com/SwiftDocOrg/Markup/wiki\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FSwiftDocOrg%2FMarkup","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FSwiftDocOrg%2FMarkup","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FSwiftDocOrg%2FMarkup/lists"}