Skip to content

Commit a9640da

Browse files
committed
wip
1 parent 4a3e44e commit a9640da

2 files changed

Lines changed: 11 additions & 14 deletions

File tree

Sources/MarkdownToAttributedString/AttributedStringVisitor.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -667,7 +667,7 @@ extension StringAttrs {
667667
mutating func mergeAttributes(_ otherAttrs: StringAttrs) {
668668
for (key, val) in otherAttrs {
669669
if key == .markdownElements, let val = val as? MarkdownElementAttributes {
670-
let elAttrs = (self[.markdownElements] as? MarkdownElementAttributes)?.copy() as? MarkdownElementAttributes ?? MarkdownElementAttributes()
670+
var elAttrs = (self[.markdownElements] as? MarkdownElementAttributes)?.copy() as? MarkdownElementAttributes ?? MarkdownElementAttributes()
671671

672672
for (_, newAttribute) in val.allAttributes {
673673
elAttrs.add(newAttribute)

Sources/MarkdownToAttributedString/MarkdownElementAttribute.swift

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -232,26 +232,23 @@ public extension NSAttributedString.Key {
232232
static let paragraphBreak: NSAttributedString.Key = .init("MTASParagraphBreak")
233233
}
234234

235-
public class MarkdownElementAttributes: NSObject, NSCopying {
235+
public struct MarkdownElementAttributes: Equatable, Hashable, CustomStringConvertible {
236236
private var storage: [MarkupType: MarkdownElementAttribute]
237237

238238
public init(_ attributes: [MarkupType: MarkdownElementAttribute] = [:]) {
239239
self.storage = attributes
240-
super.init()
241240
}
242241

243-
public override func isEqual(_ object: Any?) -> Bool {
244-
guard let other = object as? MarkdownElementAttributes else { return false }
245-
return self.storage == other.storage
242+
static public func == (lhs: MarkdownElementAttributes, rhs: MarkdownElementAttributes) -> Bool {
243+
return lhs.storage == rhs.storage
246244
}
247245

248-
public override var hash: Int {
249-
return storage.hashValue
246+
public func hash(into hasher: inout Hasher) {
247+
hasher.combine(storage)
250248
}
251249

252-
public override var description: String {
253-
let addr = "\(Unmanaged.passUnretained(self).toOpaque())"
254-
return "<MarkdownElementAttributes: \(addr)> \(storage.description)"
250+
public var description: String {
251+
return "<MarkdownElementAttributes> \(storage.description)"
255252
}
256253

257254
public var allAttributes: [(MarkupType, MarkdownElementAttribute)] {
@@ -272,11 +269,11 @@ public extension MarkdownElementAttributes {
272269
return storage[key]
273270
}
274271

275-
func add(_ mdElAttr: MarkdownElementAttribute) {
272+
mutating func add(_ mdElAttr: MarkdownElementAttribute) {
276273
storage[mdElAttr.elementType] = mdElAttr
277274
}
278275

279-
func remove(_ type: MarkupType) {
276+
mutating func remove(_ type: MarkupType) {
280277
storage[type] = nil
281278
}
282279

@@ -335,7 +332,7 @@ public extension StringAttrs {
335332
}
336333

337334
mutating func addMarkdownElementAttr(_ attr: MarkdownElementAttribute) {
338-
let d = (self[.markdownElements] as? MarkdownElementAttributes) ?? MarkdownElementAttributes()
335+
var d = (self[.markdownElements] as? MarkdownElementAttributes) ?? MarkdownElementAttributes()
339336
d.add(attr)
340337
self[.markdownElements] = d
341338
}

0 commit comments

Comments
 (0)