{"id":15029225,"url":"https://github.com/psharanda/atributika","last_synced_at":"2025-05-15T07:07:06.081Z","repository":{"id":44871544,"uuid":"58332862","full_name":"psharanda/Atributika","owner":"psharanda","description":"Convert text with HTML tags, links, hashtags, mentions into NSAttributedString. Make them clickable with UILabel drop-in replacement.","archived":false,"fork":false,"pushed_at":"2024-06-11T23:44:21.000Z","size":808,"stargazers_count":1480,"open_issues_count":8,"forks_count":157,"subscribers_count":23,"default_branch":"master","last_synced_at":"2025-05-13T17:36:36.365Z","etag":null,"topics":["attributedstring","hashtag","html","html-parser","ios","nsattributedstring","swift","tags","textkit","uilabel","uitextview"],"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/psharanda.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":"2016-05-08T21:46:22.000Z","updated_at":"2025-05-12T15:59:45.000Z","dependencies_parsed_at":"2023-11-30T11:27:35.850Z","dependency_job_id":"fea5694c-b26f-44a1-b879-02be91ec81fe","html_url":"https://github.com/psharanda/Atributika","commit_stats":{"total_commits":182,"total_committers":19,"mean_commits":9.578947368421053,"dds":"0.19780219780219777","last_synced_commit":"2de3536009a6f9ba88344a612ed219e2eb99ca2f"},"previous_names":[],"tags_count":72,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/psharanda%2FAtributika","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/psharanda%2FAtributika/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/psharanda%2FAtributika/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/psharanda%2FAtributika/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/psharanda","download_url":"https://codeload.github.com/psharanda/Atributika/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254292042,"owners_count":22046426,"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":["attributedstring","hashtag","html","html-parser","ios","nsattributedstring","swift","tags","textkit","uilabel","uitextview"],"created_at":"2024-09-24T20:10:00.395Z","updated_at":"2025-05-15T07:07:01.053Z","avatar_url":"https://github.com/psharanda.png","language":"Swift","readme":"\n\u003cp align=\"center\"\u003e\n  \u003cimg src=\"https://raw.githubusercontent.com/psharanda/Atributika/master/README/logo@2x.png\" alt=\"\" width=\"392\" /\u003e\n\u003c/p\u003e\n\u003cbr\u003e\n\n**🚨V5 is now released!🚨**\n\n`Atributika` is a Swift library that provides a simple way to build NSAttributedString from HTML-like text, by identifying and styling tags, links, phone numbers, hashtags etc. \n\nA standalone `AtributikaViews` library offers UILabel/UITextView drop-in replacements capable of displaying highlightable and clickable links, with rich customization, and proper accessibility support. \n\n\u003e [!NOTE]\n\u003e Try my new library for doing Auto Layout, a typesafe reimagination of Visual Format Language:\n\u003e https://github.com/psharanda/FixFlex\n\n\n## Intro\nWhile NSAttributedString is undoubtedly powerful, it's also a low-level API that needs a considerable amount of setup work. If your string is a template and the actual content is only known at runtime, this becomes complicated. When dealing with localizations, constructing NSAttributedString isn't straightforward either. \n\nBut wait, `Atributika` comes to your rescue!\n\n```swift\nlet b = Attrs().font(.boldSystemFont(ofSize: 20)).foregroundColor(.red)\n        \nlabel.attributedText = \"Hello \u003cb\u003eWorld\u003c/b\u003e!!!\".style(tags: [\"b\": b]).attributedString\n```\n\n\u003cimg src=\"https://raw.githubusercontent.com/psharanda/Atributika/master/README/main.png\" alt=\"\" width=\"139\" /\u003e\n\nIndeed, that's much simpler. `Atributika` is easy-to-use, declarative, flexible, and handles the rough edges for you.\n\n\n## Features\n\nAtributika\n+ NSAttributedString builder.\n+ Detects and styles HTML-like **tags** using a custom high-speed parser.\n+ Detects and styles **hashtags** and **mentions** (i.e., #something and @someone).\n+ Identifies and styles **links** and **phone numbers**.\n+ Detects and styles regexes and NSDataDetector patterns.\n+ Styles the entire string or just specified ranges.\n+ Allows all the above to be chained together to parse complex strings!\n+ Provides a clean and expressive API to construct styles.\n+ Offers a separate set of detection utilities for standalone use.\n+ Compatible with iOS, tvOS, watchOS, and macOS.\n\nAtributikaViews\n+ Custom views with **highlightable and clickable** links. \n+ Custom text styles for `normal/highlighted/disabled` states.\n+ Supports custom highlighting.\n\n## V5\n\nV5 is a major rewrite of the project, executed in early 2023. It's not fully compatible with the previous version and requires some manual migration. The introduction of breaking changes was necessary for the project's further evolution.\n\nHere's what's new:\n\nNSAttributedString Building\n+ Completely rewritten HTML parser, which fixed a multitude of bugs and improved handling of edge cases.\n+ More generic and robust text transforming and attribute fine-tuning APIs.\n\nAttributedLabel / AttributedTextView\n+ Moved to a standalone library, independent of Atributika.\n+ Offers proper accessibility support.\n+ Improved performance and touch handling.\n+ AttributedLabel is based on UILabel (lightweight, with vertically-centered text).\n+ AttributedTextView is based on UITextView (supports scrolling and text selection, with text aligned to the top of the frame).\n\nNew examples have been added to the Demo application, including:\n+ Basic web browser powered by AttributedTextView\n+ SwiftUI integration\n+ Highlightable links for Markdown documents\n\n## Examples\n\n### Detect and style tags, provide base style for the rest of string, don't forget about special html symbols\n\n```swift\nlet redColor = UIColor(red:(0xD0 / 255.0), green: (0x02 / 255.0), blue:(0x1B / 255.0), alpha:1.0)\nlet a = Attrs().foregroundColor(redColor)\n\nlet font = UIFont(name: \"AvenirNext-Regular\", size: 24)!\nlet grayColor = UIColor(white: 0x66 / 255.0, alpha: 1)\nlet base = Attrs().font(font).foregroundColor(grayColor)\n\nlet str = \"\u003ca\u003e\u0026lt;a\u0026gt;\u003c/a\u003etributik\u003ca\u003e\u0026lt;/a\u0026gt;\u003c/a\u003e\"\n    .style(tags: [\"a\": a])\n    .styleBase(base)\n    .attributedString\n```\n\n\u003cimg src=\"https://raw.githubusercontent.com/psharanda/Atributika/master/README/test_atributika_logo.png\" alt=\"\" width=\"188\" /\u003e\n\n### Detect and style hashtags and mentions\n\n```swift\nlet str = \"#Hello @World!!!\"\n    .styleHashtags(Attrs().font(.boldSystemFont(ofSize: 45)))\n    .styleMentions(Attrs().foregroundColor(.red))\n    .attributedString\n```\n\n\u003cimg src=\"https://raw.githubusercontent.com/psharanda/Atributika/master/README/test_hashtags_mentions.png\" alt=\"\" width=\"232\" /\u003e\n\n\n### Detect and style links\n\n```swift\nlet str = \"Check this website http://google.com\"\n    .styleLinks(Attrs().foregroundColor(.blue))\n    .attributedString\n```\n\n\u003cimg src=\"https://raw.githubusercontent.com/psharanda/Atributika/master/README/test_links.png\" alt=\"\" width=\"237\" /\u003e\n\n### Detect and style phone numbers\n\n```swift\nlet str = \"Call me (888)555-5512\"\n    .stylePhoneNumbers(Attrs().foregroundColor(.red))\n    .attributedString\n```\n\n\u003cimg src=\"https://raw.githubusercontent.com/psharanda/Atributika/master/README/test_phone_numbers.png\" alt=\"\" width=\"195\" /\u003e\n\n### Uber String\n\n```swift\nlet links = Attrs().foregroundColor(.blue)\nlet phoneNumbers = Attrs().backgroundColor(.yellow)\nlet mentions = Attrs().font(.italicSystemFont(ofSize: 12)).foregroundColor(.black)\nlet b = Attrs().font(.boldSystemFont(ofSize: 12))\nlet u = Attrs().underlineStyle(.single)\n\nlet base = Attrs().font(.systemFont(ofSize: 12)).foregroundColor(.gray)\n\nlet str = \"@all I found \u003cu\u003ereally\u003c/u\u003e nice framework to manage attributed strings. It is called \u003cb\u003eAtributika\u003c/b\u003e. Call me if you want to know more (123)456-7890 #swift #nsattributedstring https://github.com/psharanda/Atributika\"\n    .style(tags: [\"u\": u, \"b\": b])\n    .styleMentions(mentions)\n    .styleHashtags(links)\n    .styleLinks(links)\n    .stylePhoneNumbers(phoneNumbers)\n    .styleBase(base)\n    .attributedString\n```    \n\n\u003cimg src=\"https://raw.githubusercontent.com/psharanda/Atributika/master/README/test_uber.png\" alt=\"\" width=\"342\" /\u003e\n\n## AttributedLabel\n\n```swift\n\nlet tweetLabel = AttributedLabel()\n\ntweetLabel.numberOfLines = 0\ntweetLabel.highlightedLinkAttributes = Attrs().foregroundColor(.red).attributes\n\nlet baseLinkAttrs = Attrs().foregroundColor(.blue)\n\nlet a = TagTuner {\n    Attrs(baseLinkAttrs).akaLink($0.tag.attributes[\"href\"] ?? \"\")\n}\n\nlet hashtag = DetectionTuner {\n    Attrs(baseLinkAttrs).akaLink(\"https://twitter.com/hashtag/\\($0.text.replacingOccurrences(of: \"#\", with: \"\"))\")\n}\n\nlet mention = DetectionTuner {\n    Attrs(baseLinkAttrs).akaLink(\"https://twitter.com/\\($0.text.replacingOccurrences(of: \"@\", with: \"\"))\")\n}\n\nlet link = DetectionTuner {\n    Attrs(baseLinkAttrs).akaLink($0.text)\n}\n\nlet tweet = \"@all I found \u003cu\u003ereally\u003c/u\u003e nice framework to manage attributed strings. It is called \u003cb\u003eAtributika\u003c/b\u003e. Call me if you want to know more (123)456-7890 #swift #nsattributedstring https://github.com/psharanda/Atributika\"\n\ntweetLabel.attributedText = tweet\n    .style(tags: [\"a\": a])\n    .styleHashtags(hashtag)\n    .styleMentions(mention)\n    .styleLinks(link)\n    .attributedString\n\ntweetLabel.onLinkTouchUpInside = { _, val in\n    if let linkStr = val as? String {\n        if let url = URL(string: linkStr) {\n            UIApplication.shared.openURL(url)\n        }\n    }\n}\n\nview.addSubview(tweetLabel)\n\n```\n\u003cimg src=\"https://raw.githubusercontent.com/psharanda/Atributika/master/README/test_attributedlabel.png\" alt=\"\" width=\"361\" /\u003e\n\n## Requirements\n\nCurrent version is compatible with:\n\n* Swift 5.0+\n* iOS 11.0 or later\n* tvOS 11.0 or later\n* watchOS 4.0 or later\n* macOS 10.13 or later\n\nNote: `AttributedLabel` / `AttributedTextView` are available only on iOS\n\n## Why does Atributika have one 't' in its name?\nBecause in Belarusian/Russian we have one letter 't' (атрыбутыка/атрибутика). So basically it is transcription, not a real word.\n\n## Integration\n\n### [Swift Package Manager](https://github.com/apple/swift-package-manager)\n\nAdd dependency to `Package.swift` file.\n\n```swift\n  dependencies: [\n    .package(url: \"https://github.com/psharanda/Atributika.git\", .upToNextMajor(from: \"5.0.0\"))\n  ]\n```\n\n### Carthage\n\nAdd `github \"psharanda/Atributika\"` to your `Cartfile`\n\n### CocoaPods\nAtributika is available through [CocoaPods](http://cocoapods.org). To install\nit, simply add the following line to your Podfile:\n\n```ruby\npod \"Atributika\"\npod \"AtributikaViews\"\n```\n\n### Manual\n1. Add Atributika to you project as a submodule using `git submodule add https://github.com/psharanda/Atributika.git`\n2. Open the `Atributika` folder \u0026 drag `Atributika.xcodeproj` into your project tree\n3. Add `Atributika.framework` to your target's `Link Binary with Libraries` Build Phase\n4. Import Atributika with `import Atributika` and you're ready to go\n\n## License\n\nAtributika is available under the MIT license. See the LICENSE file for more info.\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpsharanda%2Fatributika","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpsharanda%2Fatributika","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpsharanda%2Fatributika/lists"}