Skip to content

Commit db594d2

Browse files
Pavel Sharandapsharanda
authored andcommitted
Update README.md
1 parent 2562166 commit db594d2

File tree

1 file changed

+57
-46
lines changed

1 file changed

+57
-46
lines changed

README.md

Lines changed: 57 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,14 @@
44
</p>
55
<br>
66

7-
`Atributika` is an easy and painless way to build NSAttributedString. It is able to detect HTML-like tags, links, phone numbers, hashtags, any regex or even standard ios data detectors and style them with various attributes like font, color, etc. `Atributika` comes with drop-in label replacement `AttributedLabel` which is able to make any detection clickable
87

9-
## Intro
10-
NSAttributedString is really powerful but still a low level API which requires a lot of work to setup things. It is especially painful if string is template and real content is known only in runtime. If you are dealing with localizations, it is also not easy to build NSAttributedString.
8+
`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, and so on.
9+
A standalone `AtributikaViews` library offers UILabel/UITextView drop-in replacements capable of displaying highlightable and clickable links, rich customization, and solid accessibility support.
1110

12-
Oh wait, but you can use Atributika!
11+
## Introduction
12+
While NSAttributedString is undoubtedly powerful, it's also a low-level API that demands a considerable amount of setup work. If your string is a template and the actual content is only known at runtime, this becomes particularly tedious. When dealing with localizations, constructing NSAttributedString isn't straightforward either.
13+
14+
But wait, `Atributika` comes to your rescue!
1315

1416
```swift
1517
let b = Attrs.font(.boldSystemFont(ofSize: 20)).foregroundColor(.red)
@@ -19,43 +21,49 @@ label.attributedText = "Hello <b>World</b>!!!".style(tags: ["b": b]).attributedS
1921

2022
<img src="https://raw.githubusercontent.com/psharanda/Atributika/master/README/main.png" alt="" width="139" />
2123

22-
Yeah, that's much better. Atributika is easy, declarative, flexible and covers all the raw edges for you.
24+
Indeed, that's much simpler. `Atributika` is easy-to-use, declarative, flexible, and handles the rough edges for you.
2325

2426

2527
## Features
2628

27-
+ AttributedLabel` is a drop-in label replacement which **makes detections clickable** and style them dynamically for `normal/highlighted/disabled` states.
28-
+ detect and style HTML-like **tags** using custom speedy parser
29-
+ detect and style **hashtags** and **mentions** (i.e. #something and @someone)
30-
+ detect and style **links** and **phone numbers**
31-
+ detect and style regex and NSDataDetector patterns
32-
+ style whole string or just particular ranges
33-
+ ... and you can chain all above to parse some uber strings!
34-
+ clean and expressive api to build styles
35-
+ separate set of detection utils, in case you want to use just them
36-
+ `+` operator to concatenate NSAttributedString with other attributed or regular strings
37-
+ works on iOS, tvOS, watchOS, macOS
29+
Atributika
30+
+ NSAttributedString builder.
31+
+ Detects and styles HTML-like **tags** using a custom high-speed parser.
32+
+ Detects and styles **hashtags** and **mentions** (i.e., #something and @someone).
33+
+ Identifies and styles **links** and **phone numbers**.
34+
+ Detects and styles regexes and NSDataDetector patterns.
35+
+ Styles the entire string or just specified ranges.
36+
+ Allows all the above to be chained together to parse complex strings!
37+
+ Provides a clean and expressive API to construct styles.
38+
+ Offers a separate set of detection utilities for standalone use.
39+
+ Compatible with iOS, tvOS, watchOS, and macOS.
3840

39-
## V5
41+
AtributikaViews
42+
+ Custom views with **highlightable and clickable** links.
43+
+ Custom text styles for `normal/highlighted/disabled` states.
44+
+ Supports custom highlighting.
4045

41-
V5 is a major rewrite of the project happened at Spring 2023
46+
## Version 5
4247

43-
NSAttributedString building
44-
+ HTML parser completely rewritten, supports more edge cases
45-
+ Text transforming and attributes fine tuning depening from detected text
48+
Version 5 is a significant 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.
4649

47-
AttributedLabel / AttributedTextView
48-
+ proper accessibility support
49-
+ doesn't depend from the string building code and classes
50-
+ better performance and touch handling
51-
+ subclass off UIControl
52-
+ AttributedLabel based on UILabel (more lightweight, text is centered vertically), AttributedTextView based on UITextView (supports scrolling and text selections, text is aligned to the top of the frame)
50+
Here's what's new:
5351

54-
`Style("xxx").`/`Style.` -> `Attr.`
55-
`styleAll` -> `styleBase`
52+
NSAttributedString Building
53+
+ Completely rewritten HTML parser, which fixed a multitude of bugs and improved handling of edge cases.
54+
+ More generic and robust Text transforming and attribute fine-tuning APIs.
5655

57-
AttributedLabel api is reworked a lot see updated example below
56+
AttributedLabel / AttributedTextView
57+
+ Moved to a standalone library, independent of Atributika.
58+
+ Offers proper accessibility support.
59+
+ Reworked API for improved performance and touch handling.
60+
+ AttributedLabel is based on UILabel (lightweight, with vertically-centered text).
61+
+ AttributedTextView is based on UITextView (supports scrolling and text selection, with text aligned to the top of the frame).
5862

63+
New examples have been added to the Demo application, including:
64+
+ Basic web browser powered by Atributika
65+
+ SwiftUI integration
66+
+ Highlightable links for Markdown documents
5967

6068
## Examples
6169

@@ -152,25 +160,27 @@ let str = "Call me (888)555-5512"
152160
let tweetLabel = AttributedLabel()
153161

154162
tweetLabel.numberOfLines = 0
155-
tweetLabel.highlightedLinkAttributes = Attrs.foregroundColor(.red)
163+
tweetLabel.highlightedLinkAttributes = Attrs().foregroundColor(.red).attributes
156164

157-
let a = TagTuner { tag in
158-
Attrs.foregroundColor(.blue).attributedLabelLink(tag.attributes["href"] ?? "")
165+
let baseLinkAttrs = Attrs().foregroundColor(.blue)
166+
167+
let a = TagTuner {
168+
Attrs(baseLinkAttrs).akaLink($0.tag.attributes["href"] ?? "")
159169
}
160170

161-
let hashtag = DetectionTuner { d in
162-
Attrs.foregroundColor(.blue).attributedLabelLink("https://twitter.com/hashtag/\(d.text.replacingOccurrences(of: "#", with: ""))")
171+
let hashtag = DetectionTuner {
172+
Attrs(baseLinkAttrs).akaLink("https://twitter.com/hashtag/\($0.text.replacingOccurrences(of: "#", with: ""))")
163173
}
164174

165-
let mention = DetectionTuner { d in
166-
Attrs.foregroundColor(.blue).attributedLabelLink("https://twitter.com/\(d.text.replacingOccurrences(of: "@", with: ""))")
175+
let mention = DetectionTuner {
176+
Attrs(baseLinkAttrs).akaLink("https://twitter.com/\($0.text.replacingOccurrences(of: "@", with: ""))")
167177
}
168178

169-
let link = DetectionTuner { d in
170-
Attrs.foregroundColor(.blue).attributedLabelLink(d.text)
179+
let link = DetectionTuner {
180+
Attrs(baseLinkAttrs).akaLink($0.text)
171181
}
172182

173-
let tweet = "@all I found <u>really</u> nice framework to manage attributed strings. It is called <b>Atributika</b>. Call me if you want to know more (123)456-7890 #swift #nsattributedstring https://github.com/psharanda/Atributika"
183+
let tweet = "@all I found <u>really</u> nice framework to manage attributed strings. It is called <b>Atributika</b>. Call me if you want to know more (123)456-7890 #swift #nsattributedstring https://github.com/psharanda/Atributika"
174184

175185
tweetLabel.attributedText = tweet
176186
.style(tags: ["a": a])
@@ -179,13 +189,13 @@ tweetLabel.attributedText = tweet
179189
.styleLinks(link)
180190
.attributedString
181191

182-
tweetLabel.onLinkTouchUpInside = { _, val in
183-
if let linkStr = val as? String {
184-
if let url = URL(string: linkStr) {
185-
UIApplication.shared.openURL(url)
186-
}
192+
tweetLabel.onLinkTouchUpInside = { _, val in
193+
if let linkStr = val as? String {
194+
if let url = URL(string: linkStr) {
195+
UIApplication.shared.openURL(url)
187196
}
188197
}
198+
}
189199

190200
view.addSubview(tweetLabel)
191201

@@ -217,7 +227,7 @@ Add dependency to `Package.swift` file.
217227

218228
```swift
219229
dependencies: [
220-
.package(url: "https://github.com/psharanda/Atributika.git", .exact("5.0.0"))
230+
.package(url: "https://github.com/psharanda/Atributika.git", .upToNextMajor(from: "5.0.0"))
221231
]
222232
```
223233

@@ -231,6 +241,7 @@ it, simply add the following line to your Podfile:
231241

232242
```ruby
233243
pod "Atributika"
244+
pod "AtributikaViews"
234245
```
235246

236247
### Manual

0 commit comments

Comments
 (0)