Skip to content

Commit c94f68a

Browse files
authored
Merge pull request #105 from stefanomondino/master
Dynamic attributes fallback to default implementation (see #102)
2 parents 2a355ee + 3920953 commit c94f68a

File tree

2 files changed

+9
-7
lines changed

2 files changed

+9
-7
lines changed

ExampleiOS/ViewController.swift

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,9 @@ class ViewController: UIViewController {
3030
fatalError()
3131
}
3232

33-
self.textView?.attributedText = text.set(style: xmlStyle)
33+
// self.textView?.attributedText = text.set(style: xmlStyle)
3434

35-
return
35+
// return
3636

3737
// self.textView?.attributedText = "ciao ciao " + AttributedString(image: UIImage(named: "rocket")!,
3838
// bounds: CGRect(x: 0, y: -20, width: 25, height: 25)) + "ciao ciao"
@@ -85,6 +85,7 @@ class ViewController: UIViewController {
8585
"b": boldStyle,
8686
"em": italicStyle,
8787
"i": italicStyle,
88+
"a": uppercasedRed,
8889
"li": Style {
8990
$0.paragraphSpacingBefore = self.baseFontSize / 2
9091
$0.firstLineHeadIndent = self.baseFontSize

Sources/SwiftRichString/Support/XMLDynamicAttributesResolver.swift

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -90,22 +90,23 @@ extension XMLDynamicAttributesResolver {
9090

9191
open class StandardXMLAttributesResolver: XMLDynamicAttributesResolver {
9292

93-
public func applyDynamicAttributes(to attributedString: inout AttributedString, xmlStyle: XMLDynamicStyle, fromStyle: StyleXML) {
93+
public init() {}
94+
95+
open func applyDynamicAttributes(to attributedString: inout AttributedString, xmlStyle: XMLDynamicStyle, fromStyle: StyleXML) {
9496
let finalStyleToApply = Style()
9597
xmlStyle.enumerateAttributes { key, value in
9698
switch key {
9799
case "color": // color support
98100
finalStyleToApply.color = Color(hexString: value)
99101

100-
default:
101-
break
102+
default: break
102103
}
103104
}
104-
105+
self.styleForUnknownXMLTag(xmlStyle.tag, to: &attributedString, attributes: xmlStyle.xmlAttributes, fromStyle: fromStyle)
105106
attributedString.add(style: finalStyleToApply)
106107
}
107108

108-
public func styleForUnknownXMLTag(_ tag: String, to attributedString: inout AttributedString, attributes: [String: String]?, fromStyle: StyleXML) {
109+
open func styleForUnknownXMLTag(_ tag: String, to attributedString: inout AttributedString, attributes: [String: String]?, fromStyle: StyleXML) {
109110
let finalStyleToApply = Style()
110111
switch tag {
111112
case "a": // href support

0 commit comments

Comments
 (0)