{"id":20742513,"url":"https://github.com/frankrausch/typographizer","last_synced_at":"2025-03-03T09:09:43.281Z","repository":{"id":204114103,"uuid":"82171581","full_name":"frankrausch/Typographizer","owner":"frankrausch","description":"Fix dumb quotation marks and apostrophes in Swift on iOS, macOS, watchOS, and tvOS","archived":false,"fork":false,"pushed_at":"2021-03-03T18:31:51.000Z","size":108,"stargazers_count":276,"open_issues_count":1,"forks_count":16,"subscribers_count":9,"default_branch":"main","last_synced_at":"2025-02-24T08:12:40.551Z","etag":null,"topics":["dumb-quotes","smart-quotes","swift","typography"],"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/frankrausch.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}},"created_at":"2017-02-16T11:01:59.000Z","updated_at":"2024-11-07T23:28:32.000Z","dependencies_parsed_at":null,"dependency_job_id":"1cd664e2-0f10-484d-86aa-4a3c26b45011","html_url":"https://github.com/frankrausch/Typographizer","commit_stats":null,"previous_names":["frankrausch/typographizer"],"tags_count":8,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/frankrausch%2FTypographizer","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/frankrausch%2FTypographizer/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/frankrausch%2FTypographizer/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/frankrausch%2FTypographizer/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/frankrausch","download_url":"https://codeload.github.com/frankrausch/Typographizer/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":241637293,"owners_count":19994946,"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":["dumb-quotes","smart-quotes","swift","typography"],"created_at":"2024-11-17T07:06:05.439Z","updated_at":"2025-03-03T09:09:43.260Z","avatar_url":"https://github.com/frankrausch.png","language":"Swift","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003cimg src=\"https://raw.githubusercontent.com/frankrausch/typographizer/master/logo.png\" width=\"90\" height=\"90\"\u003e\n\n## Typographizer · Smart Quotes for Swift Apps\n\nTypographizer turns those pesky dumb quotes (`\"\"`/`''`) and apostrophes (`'`) into their beautiful, curly, localized counterparts. Because [good typography uses smart quotes, not dumb quotes](http://smartquotesforsmartpeople.com/) and we should not let [the internet kill smart quotes](https://www.theatlantic.com/technology/archive/2016/12/quotation-mark-wars/511766/). Speaking of smartness: Typographizer is smart enough to skip HTML tags and everything between certain tags (like `\u003ccode\u003e` and `\u003cpre\u003e`).\n\nTypographizer has a small footprint, was written in pure Swift, and has been tested on macOS, iOS, watchOS, and tvOS.\n\nI started building Typographizer to typographize Wikipedia articles in my [V\u0026nbsp;for\u0026nbsp;Wiki](http://v-for-wiki.com) app.\n\n## Installation\n\nPut the `.swift` files into your app’s Xcode project.\n\n## How to Use\n\nThe easiest way to use Typographizer is the String extension (`String+Typographizer.swift`):\n\n```swift\nvar s = \"This is a string with \\\"dumb\\\" quotes.\"\n\ns = s.typographized(language: \"en\")\n\nprint(s) // This is a string with “dumb” quotes.\n```\n\n### Ignoring HTML Tags\n\nIf your string may contain HTML, set the `isHTML` parameter to `true`. Typographizer will then ignore the quotes inside tags and anything between `\u003cpre\u003e`, `\u003ccode\u003e`, `\u003cvar\u003e`, `\u003csamp\u003e`, `\u003ckbd\u003e`, `\u003cmath\u003e`, `\u003cscript\u003e`, and `\u003cstyle\u003e` tags:\n\n```swift\nvar s = \"This is a \\\"string\\\" with HTML. \u003ccode class=\"\"\u003eprint(\\\"hello world\\\")\u003c/code\u003e\"\n\ns = s.typographized(language: \"en\", isHTML: true)\n\nprint(s) // This is a “string” with HTML. \u003ccode class=\"\"\u003eprint(\"hello world\")\u003c/code\u003e\n```\n\n### Debug Mode\n\nActivate the debug mode to highlight the characters that have been changed—Typographizer will add this tag around them: `\u003cspan class=\"typographizer-debug typographizer-debug--XXX\"\u003e` `\u003c/span\u003e`\n\n```swift\nvar s = \"This is a string with \\\"dumb\\\" quotes.\"\n\ns = s.typographized(language: \"en\", isHTML: true, debug: true)\n\nprint(s) // This is a string with \u003cspan class=\"typographizer-debug typographizer-debug--opening-double\"\u003e“\u003c/span\u003edumb\u003cspan class=\"typographizer-debug typographizer-debug--closing-double\"\u003e”\u003c/span\u003e quotes.\n```\n\n(Yes, the class names are a little wordy, but that’s [on purpose](https://csswizardry.com/2013/01/mindbemding-getting-your-head-round-bem-syntax/).)\n\nUse CSS to visualize the changes:\n\n```css\n.typographizer-debug {\n  font-weight: bold;\n}\n\n.typographizer-debug--apostrophe {\n  color: red;\n}\n\n/* … */\n```\n\n### Measuring Performance\n\nPass `measurePerformance: true` to log performance stats:\n\n```swift\ns = s.typographized(language: \"en\", isHTML: true, debug: false, measurePerformance: true)\n```\n\nYou’ll see something like this in the Xcode console:\n\n```\nTypographizing took 0.00582303 seconds\n```\n\n## Features\n\n- [x] Fixes double quotes: `\"\"` → `“”` (localized)\n- [x] Fixes single quotes: `''` → `‘’` (localized)\n- [x] Fixes apostrophes: `'` → `’`\n- [x] Fixes hyphens that are used as en dashes: `… - …` → `… – …`\n- [x] Demo app project for macOS\n\n## Supported Languages\n\n| Language Code | Double Quotes | Single Quotes | Comment |\n| :---: | :---: | :---: | --- |\n| `bs` | `”` `”` | `’` `’` | |\n| `cs` | `„` `“` | `‚` `‘` | |\n| `da` | `„` `“` | `‚` `‘` | |\n| `de` | `„` `“` | `‚` `‘` | |\n| `de_CH` | `«` `»` | `‹` `›` | Swiss Standard German |\n| `en` | `“` `”` | `‘` `’` | |\n| `et` | `„` `“` | `‚` `‘` | |\n| `fi` | `”` `”` | `’` `’` | |\n| `fr` | `«\\u{00A0}` `\\u{00A0}»` | `‹\\u{00A0}` `\\u{00A0}›` | French Quotes are set with a non-breaking space (`\\u{00A0}`). A thin non-breaking space would be better, but it’s not supported in most browsers.|\n| `hu` | `„` `”` | `’` `’` | |\n| `is` | `„` `“` | `‚` `‘` | |\n| `ja` | `「` `」` |`『` `』`  | |\n| `lt` | `„` `“` | `‚` `‘` | |\n| `lv` | `„` `“` | `‚` `‘` | |\n| `nl` | `“` `”` | `‘` `’` | |\n| `nn` | `«` `»` | `’` `’` | |\n| `no` | `«` `»` | `’` `’` | |\n| `pl` | `„` `”` | `’` `’` | |\n| `ro` | `„` `”` | `’` `’` | |\n| `ru` | `«` `»` | `’` `’` | |\n| `sk` | `„` `“` | `‚` `‘` | |\n| `sl` | `„` `“` | `‚` `‘` | |\n| `sv` | `”` `”` | `’` `’` | |\n\n## Demo App\nTo get started, try the included demo app for macOS.\n\n![](https://cloud.githubusercontent.com/assets/6783714/24149232/0b818208-0e42-11e7-9257-b2afda792f2b.png \"Screenshot of Typographizer Demo App\")\n\n\n## To Do\n\n- [ ] Handle special cases like ’80s, ’Twas, Rock ’n’ Roll, etc.\n- [ ] Handle primes in coordinates properly:  \n52°\u0026nbsp;27'\u0026nbsp;20\"\u0026nbsp;N, 13°\u0026nbsp;19'\u0026nbsp;11\"\u0026nbsp;E → 52°\u0026nbsp;27′\u0026nbsp;20″\u0026nbsp;N, 13°\u0026nbsp;19′\u0026nbsp;11″\u0026nbsp;E\n- [ ] Add support for Hebrew\n- [ ] If there is only one dumb single quote in a string, it’s probably an apostrophe\n- [ ] Analyze HTML tags to verify correct quotes (opening and closing `\u003cp\u003e` tags make a good indicator for opening and closing quotation marks)\n- [ ] Track open/closed state while iterating over the text to make more informed decisions\n- [ ] Add more typographic refinements (e.g. prime symbols, thin spaces)\n\n## Credits\n\nTypographizer was created by [Frank Rausch](http://frankrausch.com) ([@frankrausch](https://twitter.com/frankrausch)).\n\nThanks to Tony Allevato for the great article on [Strings, characters, and performance in Swift—a deep dive](https://medium.com/@tonyallevato/strings-characters-and-performance-in-swift-a-deep-dive-b7b5bde58d53).\n\n## Contribution Guidelines\n\nPlease always use `self` when accessing methods and properties.\n\nPreferred:\n\n```swift\nself.coolMethod()\n```\n\nNot preferred:\n\n```swift\ncoolMethod()\n```\n\n## License\nThe Typographizer source code is released under the MIT License. Please view the LICENSE file for details.\n\nThe Typographizer logo is © 2017 Frank Rausch; all rights reserved.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffrankrausch%2Ftypographizer","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffrankrausch%2Ftypographizer","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffrankrausch%2Ftypographizer/lists"}