{"id":20704377,"url":"https://github.com/cocoatoucher/xmltext","last_synced_at":"2025-06-15T10:04:38.214Z","repository":{"id":150826465,"uuid":"346490633","full_name":"cocoatoucher/XMLText","owner":"cocoatoucher","description":"Generate styled SwiftUI Text from strings with XML tags.","archived":false,"fork":false,"pushed_at":"2022-01-04T07:53:09.000Z","size":552,"stargazers_count":21,"open_issues_count":0,"forks_count":6,"subscribers_count":6,"default_branch":"main","last_synced_at":"2025-03-29T20:51:09.254Z","etag":null,"topics":["attributed","attributedstring","html","ios","localisation","localization","macos","parsing","string","style","styled","swift","swiftui","text","tvos","xml"],"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/cocoatoucher.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2021-03-10T21:00:29.000Z","updated_at":"2024-11-09T09:41:26.000Z","dependencies_parsed_at":null,"dependency_job_id":"fcc1e5b9-2311-4ac0-ab03-6f1e95c06968","html_url":"https://github.com/cocoatoucher/XMLText","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cocoatoucher%2FXMLText","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cocoatoucher%2FXMLText/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cocoatoucher%2FXMLText/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cocoatoucher%2FXMLText/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/cocoatoucher","download_url":"https://codeload.github.com/cocoatoucher/XMLText/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":250350300,"owners_count":21416110,"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":["attributed","attributedstring","html","ios","localisation","localization","macos","parsing","string","style","styled","swift","swiftui","text","tvos","xml"],"created_at":"2024-11-17T01:12:04.489Z","updated_at":"2025-04-23T01:24:59.915Z","avatar_url":"https://github.com/cocoatoucher.png","language":"Swift","readme":"\u003cp align=\"center\"\u003e\n\u003cimg src=\"Docs/logo.png\" width=\"300\" max-width=\"80%\" alt=\"glide\"/\u003e\n\u003c/p\u003e\n\nXMLText is a mini library that can generate SwiftUI `Text` from a given XML string with tags. It uses `AttributedString` to compose the final text output.\n\n```\nText(\n    xmlString: \"my \u003cbold\u003elocalized\u003c/bold\u003e and \u003citalic\u003estyled\u003c/italic\u003e string\",\n    styleGroup: myStyleDefinitions\n)\n```\n\n***The original idea comes directly from [`SwiftRichString` library by `Daniele Margutti` on GitHub](https://github.com/malcommac/SwiftRichString). Code for XML parsing, StyleProtocol, and StyleGroup are taken from this library, slight modifications are made to them in order to generate `SwiftUI` `Text` instead of `NSAttributedString`.***\n\nThis is really useful for localising your apps for styled strings without having to know the location of the strings in the code that needs to be styled. This is a pretty fine alternative to having to use `NSAttributedString` with `UIViewRepresentable` of a `UILabel` in a `SwiftUI` app, as the layout of `UIViewRepresentable` for such dynamic views as `UILabel` doesn't always work and is prone to glitches when combined with other `SwiftUI` views.\n\n## Examples\n\u003cp align=\"center\"\u003e\n\u003cimg src=\"Docs/examples.png\" width=\"400\" max-width=\"80%\" alt=\"glide devices\"/\u003e\n\u003c/p\u003e\n\n\u003cp align=\"center\"\u003e\niOS 15.0 / macOS 12.0 / tvOS 15.0 / watchOS 8.0\n\u003c/p\u003e\n\n## Supported `Text` modifiers\n\n#### font(*SwiftUI.Font*)\n#### foregroundColor(*Color*)\n#### strikethrough(*Color*)\n#### underline(*Color*)\n#### kerning(*CGFloat*)\n#### tracking(*CGFloat*)\n#### baselineOffset(*CGFloat*)\n\n## Sample usage\n\nThis is an example of XML strings that would appear in your Localizable.strings files with words in different order for each different language, namely English and Swedish for this example.\nIf you are not familiar with that approach, please note that the style information(`StyleGroup` keys, e.g. `\u003citalicStyle\u003e`) is also contained in the localized strings.\n\n\n```\n// This goes to English Localizable.strings\nlet englishXML = \"%1$@ \u003citalicStyle\u003e%2$@\u003c/italicStyle\u003e\"\n\n// This goes to Swedish Localizable.strings\nlet swedishXML = \"\u003citalicStyle\u003e%2$@\u003c/italicStyle\u003e %1$@\"\n\nlet normalStyle = Style { style in\n\tstyle.font = .subheadline\n\tstyle.foregroundColor = .red\n}\n\nlet italicStyle = Style { style in\n\tstyle.font = Font.italic(.system(size: 20))()\n\tstyle.foregroundColor = .blue\n}\n\nlet styleGroup = StyleGroup(\n\tbase: normalStyle,\n\t[\"italicStyle\": italicStyle]\n)\n\nText(\n\txmlString: String(format: englishXML, \"Director\", \"Martin\"),\n\tstyleGroup: styleGroup\n)\nText(\n\txmlString: String(format: swedishXML, \"Regissör\", \"Martin\"),\n\tstyleGroup: styleGroup\n)\n```\n\n### 🔗 Links\n\nYou can add links inside your strings via:\n`\u003ca href=\"http://www.example.com\"\u003eThis is a link\u003c/a\u003e`\n\n### 🎆 Images (not supported)\n\nIt is currently not supported to include `Image` elements within `AttributedString`.\n\n### Custom XML Attributes (not supported)\n\nFor example: `\u003citalicStyle myAttribute=\"something\"\u003e\u003c/italicStyle\u003e`\n\nThis is currently not supported for sake of simplicity and given the fact that the library doesn't have so many capabilities for that to make sense. If there would be some use cases regarding this, a similar approach to `XMLDynamicAttributesResolver` of `SwiftRichString` library could be considered in the future.\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcocoatoucher%2Fxmltext","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcocoatoucher%2Fxmltext","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcocoatoucher%2Fxmltext/lists"}