Skip to content

Commit 2408ed9

Browse files
committed
#46 Documentation in ReadMe
1 parent 73b2b2d commit 2408ed9

File tree

2 files changed

+19
-2
lines changed

2 files changed

+19
-2
lines changed

README.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,25 @@ The result is this:
207207

208208
<a name="concatenation"/>
209209

210+
### Dynamic Attributes from Source Text
211+
212+
SwiftRichString also support some dynamic element in style applied by reading specific attributes from html-tagged string.
213+
The following example render the `linkURL` property by reading the value from the source string inside `href` tag (like in real HTML text):
214+
215+
```
216+
let normal = Style {
217+
$0.color = UIColor.black
218+
}
219+
let link = Style {
220+
$0.color = UIColor.red
221+
$0.linkURL = URLRepresentable.tagAttribute("href")
222+
}
223+
let group = StyleGroup.init(base: normal, ["a" : link])
224+
225+
let bodyHTML = "Go to <a href=\"http://www.apple.com\">Apple</a> web site!"
226+
self.textView?.attributedText = bodyHTML.set(style: group)
227+
```
228+
210229
### String & Attributed String concatenation
211230
SwiftRichString allows you to simplify string concatenation by providing custom `+` operator between `String`,`AttributedString` (typealias of `NSMutableAttributedString`) and `Style`.
212231

Sources/SwiftRichString/Attributes/URLRepresentable.swift

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,4 @@ public enum URLRepresentable: DynamicTagComposable {
3838
}
3939
}
4040

41-
42-
4341
}

0 commit comments

Comments
 (0)