{"id":25516192,"url":"https://github.com/iaenhaall/attributedtext","last_synced_at":"2025-04-10T20:32:36.386Z","repository":{"id":48834145,"uuid":"346823111","full_name":"Iaenhaall/AttributedText","owner":"Iaenhaall","description":"AttributedText is a view for displaying some HTML-tagged text using SwiftUI Text View.","archived":false,"fork":false,"pushed_at":"2021-07-09T10:43:41.000Z","size":364,"stargazers_count":64,"open_issues_count":4,"forks_count":9,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-03-20T10:39:13.043Z","etag":null,"topics":["attributed","attributed-text","easy-to-use","formatted","formatted-text","html-tags","swiftui","swiftui-text","text"],"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/Iaenhaall.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-03-11T20:04:37.000Z","updated_at":"2025-03-12T19:39:32.000Z","dependencies_parsed_at":"2022-09-05T18:12:25.684Z","dependency_job_id":null,"html_url":"https://github.com/Iaenhaall/AttributedText","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Iaenhaall%2FAttributedText","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Iaenhaall%2FAttributedText/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Iaenhaall%2FAttributedText/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Iaenhaall%2FAttributedText/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Iaenhaall","download_url":"https://codeload.github.com/Iaenhaall/AttributedText/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248290041,"owners_count":21078923,"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","attributed-text","easy-to-use","formatted","formatted-text","html-tags","swiftui","swiftui-text","text"],"created_at":"2025-02-19T14:18:18.255Z","updated_at":"2025-04-10T20:32:36.352Z","avatar_url":"https://github.com/Iaenhaall.png","language":"Swift","funding_links":[],"categories":[],"sub_categories":[],"readme":"# AttributedText\n\nAttributedText is a view for displaying some HTML-tagged text using **SwiftUI Text View**.\n\nA simple example of usage.\n\n**Code example:**\n\n```swift\nAttributedText(\"A unit of \u003ci\u003elength\u003c/i\u003e equal to \u003cb\u003eone hundred-millionth of a centimetre\u003c/b\u003e, 10\u003csup\u003e−10\u003c/sup\u003e metre, used mainly to express \u003cu\u003ewavelengths and interatomic distances\u003c/u\u003e.\")\n```\n\n**Result:**\n\n![Example](./Images/Example.png)\n\n\n\n## Features\n\nYou can clone the repo and run the **AttributedTextExample** project to explore the `AttributedText` features.\n\nThese are the main points to pay attention to.\n\n1. You can define the tags you need or use the defaults.\n\n   You need to set the required tags and provide associated closures. Each closure must be a modifier that is applied to the **SwiftUI Text View** when a specific tag is encountered.\n\n   ##### Override the default values, for example at application launch.\n\n   ```swift\n   @main\n   struct ExampleApp: App {\n       init() {\n           AttributedText.tags = [\n               \"b\": { $0.bold() },\n               \"i\": { $0.italic() }\n           ]\n       }\n   }\n   ```\n\n   In this case only **\\\u003cb\\\u003e** and **\\\u003ci\\\u003e** tags will be processed. All other tags will be ignored or deleted.\n\n   ##### Set the custom values for each instance.\n\n   ```swift\n   private let tags: Dictionary\u003cString, (Text) -\u003e (Text)\u003e = [\n       // Set the necessary values.\n   ]\n   \n   var body: some View {\n       AttributedText(\"Text\", tags: tags)\n   }\n   ```\n\n2. Basic modifiers can still be applied, such as changing the font and color of the text.\n\n   **Code example:**\n\n   ```swift\n   AttributedText(\"This is \u003cb\u003ebold\u003c/b\u003e and \u003ci\u003eitalic\u003c/i\u003e text.\")\n       .foregroundColor(.blue)\n       .font(.title)\n   ```\n\n   **Result:**\n\n   ![1 feature](./Images/1%20feature.png)\n\n3. Handles unopened/unclosed tags.\n\n   **Code example:**\n\n   ```swift\n   AttributedText(\"This is italic\u003c/i\u003e and \u003cb\u003ebold text.\")\n   ```\n\n   **Result:**\n\n   ![2 feature](./Images/2%20feature.png)\n\n4. Supports overlapping tags.\n\n   **Code example:**\n\n   ```swift\n   AttributedText(\"This is \u003cb\u003ebold only, \u003ci\u003ebold and italic\u003c/b\u003e and italic only\u003c/i\u003e text.\")\n   ```\n\n   **Result:**\n\n   ![3 feature](./Images/3%20feature.png)\n\n5. Deletes tags that have no modifiers.\n\n   **Code example:**\n\n   ```swift\n   AttributedText(\"\u003cunknown\u003eThis is \u003cb\u003ebold\u003c/b\u003e and \u003ci\u003eitalic\u003c/i\u003e text.\u003c/unknown\u003e\")\n   ```\n\n   **Result:**\n\n   ![4 feature](./Images/4%20feature.png)\n\n6. Does **not** handle HTML characters such as `\u0026amp;`.\n\n   **Code example:**\n\n   ```swift\n   AttributedText(\"This is \u003cb\u003ebold\u003c/b\u003e \u0026amp; \u003ci\u003eitalic\u003c/i\u003e text.\")\n   ```\n\n   **Result:**\n\n   ![5 feature](./Images/5%20feature.png)\n\n7. **Only single-word tags are supported**. Tags with more than one word or containing any characters besides **letters** or **numbers** are ignored and not removed.\n\n   **Code example:**\n\n   ```swift\n   AttributedText(\"This is \u003ctag attribute1=\\\"value1\\\"\u003e \u003cb\u003ebold\u003c/b\u003e and \u003ci\u003eitalic\u003c/i\u003e text\u003c/tag\u003e.\")\n   ```\n\n   **Result:**\n\n   ![6 feature](./Images/6%20feature.png)\n\n\n\n## Installation and usage\n\n#### Via Swift Package Manager\n\n1. In Xcode 11 or greater select `File ▸ Swift Packages ▸ Add Package Dependency`.\n2. Paste the link to this repo https://github.com/Iaenhaall/AttributedText.git and click **Next**.\n3. Define the package options for this package or select the default. Click **Next**.\n4. Xcode downloads the code from GitHub and adds the package to the your project target. Click **Finish**.\n\n#### Manually\n\n1. Add **[AttributedText.swift](https://github.com/Iaenhaall/AttributedText/blob/master/Sources/AttributedText/AttributedText.swift)** and **[HTML2TextParser.swift](https://github.com/Iaenhaall/AttributedText/blob/master/Sources/AttributedText/HTML2TextParser.swift)** files to your project.\n\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fiaenhaall%2Fattributedtext","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fiaenhaall%2Fattributedtext","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fiaenhaall%2Fattributedtext/lists"}