{"id":24063315,"url":"https://github.com/alexaubry/htmlstring","last_synced_at":"2025-12-11T23:01:45.716Z","repository":{"id":45071751,"uuid":"69547575","full_name":"alexaubry/HTMLString","owner":"alexaubry","description":"Escape and unescape HTML entities in Swift","archived":false,"fork":false,"pushed_at":"2022-07-12T23:00:26.000Z","size":1176,"stargazers_count":176,"open_issues_count":4,"forks_count":28,"subscribers_count":7,"default_branch":"main","last_synced_at":"2025-04-06T07:47:47.903Z","etag":null,"topics":["decoder","html-entities","html-escape","string","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/alexaubry.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","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":"2016-09-29T08:31:38.000Z","updated_at":"2025-03-23T10:44:23.000Z","dependencies_parsed_at":"2022-08-04T01:45:50.706Z","dependency_job_id":null,"html_url":"https://github.com/alexaubry/HTMLString","commit_stats":null,"previous_names":["alexaubry/htmlstring"],"tags_count":15,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alexaubry%2FHTMLString","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alexaubry%2FHTMLString/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alexaubry%2FHTMLString/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alexaubry%2FHTMLString/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/alexaubry","download_url":"https://codeload.github.com/alexaubry/HTMLString/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248065281,"owners_count":21041872,"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":["decoder","html-entities","html-escape","string","swift"],"created_at":"2025-01-09T09:12:47.336Z","updated_at":"2025-12-11T23:01:40.451Z","avatar_url":"https://github.com/alexaubry.png","language":"Swift","readme":"\u003cp align=\"center\"\u003e\n    \u003cimg src=\"https://github.com/alexaubry/HTMLString/raw/main/.github/logo.png\" alt=\"HTMLString\" /\u003e\n    \u003ca\u003e\n        \u003cimg src=\"https://img.shields.io/badge/Swift-5.0-ee4f37.svg\" alt=\"Swift 5.0\" /\u003e\n    \u003c/a\u003e\n    \u003ca href=\"https://cocoapods.org/pods/HTMLString\"\u003e\n        \u003cimg src=\"https://img.shields.io/cocoapods/v/HTMLString.svg\" alt=\"CocoaPods\" /\u003e\n    \u003c/a\u003e\n    \u003ca href=\"https://github.com/Carthage/Carthage\"\u003e\n        \u003cimg src=\"https://img.shields.io/badge/Carthage-compatible-4BC51D.svg?style=flat\" alt=\"Carthage compatible\" /\u003e\n    \u003c/a\u003e\n    \u003ca href=\"https://twitter.com/_alexaubry\"\u003e\n        \u003cimg src=\"https://github.com/alexaubry/HTMLString/raw/main/.github/contact-badge.svg?sanitize=true\" alt=\"Contact : @_alexaubry\" /\u003e\n    \u003c/a\u003e\n\u003c/p\u003e\n\n`HTMLString` is a library written in Swift that allows your program to add and remove HTML entities in Strings.\n\n|         | Main features |\n----------|----------------\n\u0026#128271; | Adds entities for ASCII and UTF-8/UTF-16 encodings\n\u0026#128221; | Removes more than 2100 named entities (like `\u0026amp;`)\n\u0026#128290; | Supports removing decimal and hexadecimal entities\n\u0026#128035; | Designed to support Swift Extended Grapheme Clusters (\u0026#8594; 100% emoji-proof)\n\u0026#009989; | Fully unit tested\n\u0026#009889; | Fast\n\u0026#128218; | [Documented](https://alexaubry.github.io/HTMLString/)\n\u0026#129302; | [Compatible with Objective-C](https://github.com/alexaubry/HTMLString/tree/main/README.md#objective%2Dc-api)\n\n## Supported Platforms\n\nThis package requires Swift 5 and Xcode 12.\n\n- iOS 9.0+\n- macOS 10.10+\n- tvOS 9.0+\n- watchOS 2.0+\n- Linux\n\n## Installation\n\n### Swift Package Manager\n\nAdd this line to your `Package.swift` :\n\n~~~swift\n.Package(url: \"https://github.com/alexaubry/HTMLString\", from: \"6.0.0\")\n~~~\n\n### CocoaPods\n\nAdd this line to your `Podfile`:\n\n~~~ruby\npod 'HTMLString', '~\u003e 6.0'\n~~~\n\n### Carthage\n\nAdd this line to your Cartfile:\n\n~~~\ngithub \"alexaubry/HTMLString\" ~\u003e 6.0\n~~~\n\n## Usage\n\n`HTMLString` allows you to add and remove HTML entities from a String.\n\n### \u0026#128271; Adding HTML Entities (Escape)\n\nWhen a character is not supported into the specified encoding, the library will replace it with a decimal entity (supported by all browsers supporting HTML 4 and later).\n\n\u003e For instance, the `\u0026` character will be replaced by `\u0026#038;`.\n\nYou can choose between ASCII and Unicode escaping:\n\n- Use the `addingASCIIEntities` function to escape for ASCII-encoded content\n- Use the `addingUnicodeEntities` function to escape for Unicode-compatible content\n\n\u003e \u0026#128161; **Pro Tip**: When your content supports UTF-8 or UTF-16, use Unicode escaping as it is faster and produces a less bloated output.\n\n#### Example\n\n~~~swift\nimport HTMLString\n\nlet emoji = \"My favorite emoji is 🙃\"\nlet escapedEmoji = emoji.addingASCIIEntities() // \"My favorite emoji is \u0026#128579;\"\nlet noNeedToEscapeThatEmoji = emoji.addingUnicodeEntities() // \"My favorite emoji is 🙃\"\n\nlet snack = \"Fish \u0026 Chips\"\nlet escapedSnack = snack.addingASCIIEntities() // \"Fish \u0026#038; Chips\"\nlet weAlsoNeedToEscapeThisSnack = snack.addingUnicodeEntities() // \"Fish \u0026#038; Chips\"\n~~~\n\n### \u0026#128221; Removing HTML Entities (Unescape)\n\nTo remove all the HTML entities from a String, use the `removingHTMLEntities` function.\n\n#### Example\n\n~~~swift\nimport HTMLString\n\nlet escapedEmoji = \"My favorite emoji is \u0026#x1F643;\"\nlet emoji = escapedEmoji.removingHTMLEntities() // \"My favorite emoji is 🙃\"\n\nlet escapedSnack = \"Fish \u0026amp; Chips\"\nlet snack = escapedSnack.removingHTMLEntities() // \"Fish \u0026 Chips\"\n~~~\n\n## Objective-C API\n\nWith Obj-C interoperability, you can import and use the `HTMLString` module from in Objective-C code.\n\nThe library introduces a set of Objective-C specific APIs as categories on the `NSString` type:\n\n- `-[NSString stringByAddingUnicodeEntities];` : Replaces every character incompatible with HTML Unicode encoding by a decimal HTML entitiy.\n- `-[NSString stringByAddingASCIIEntities];` : Replaces every character incompatible with HTML ASCII encoding by a decimal HTML entitiy.\n- `-[NSString stringByRemovingHTMLEntities];` : Replaces every HTML entity with the matching Unicode character.\n\n### Escaping Examples\n\n~~~objc\n@import HTMLString;\n\nNSString *emoji = @\"My favorite emoji is 🙃\";\nNSString *escapedEmoji = [emoji stringByAddingASCIIEntities]; // \"My favorite emoji is \u0026#128579;\"\n\nNSString *snack = @\"Fish \u0026 Chips\";\nNSString *escapedSnack = [snack stringByAddingUnicodeEntities]; // \"Fish \u0026#038; Chips\"\n~~~\n\n### Unescaping Examples\n\n~~~objc\n@import HTMLString;\n\nNSString *escapedEmoji = @\"My favorite emoji is \u0026#x1F643;\";\nNSString *emoji = [escapedEmoji stringByRemovingHTMLEntities]; // \"My favorite emoji is 🙃\"\n\nNSString *escapedSnack = @\"Fish \u0026amp; Chips\";\nNSString *snack = [escapedSnack stringByRemovingHTMLEntities]; // \"Fish \u0026 Chips\"\n~~~\n\n## Author\n\n- Alexis Aubry-Akers, hi@alexisonline.dev\n- You can find me on Twitter: [@_alexaubry](https://twitter.com/_alexaubry)\n\n## License\n\nHTMLString is available under the MIT license. See the [LICENSE](LICENSE) file for more info.\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Falexaubry%2Fhtmlstring","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Falexaubry%2Fhtmlstring","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Falexaubry%2Fhtmlstring/lists"}