diff --git a/MarkdownKit/Sources/Common/Elements/Bold/MarkdownBold.swift b/MarkdownKit/Sources/Common/Elements/Bold/MarkdownBold.swift index bd42d86..2d5c4fc 100644 --- a/MarkdownKit/Sources/Common/Elements/Bold/MarkdownBold.swift +++ b/MarkdownKit/Sources/Common/Elements/Bold/MarkdownBold.swift @@ -26,20 +26,14 @@ open class MarkdownBold: MarkdownCommonElement { public func match(_ match: NSTextCheckingResult, attributedString: NSMutableAttributedString) { attributedString.deleteCharacters(in: match.range(at: 4)) - let currentAttributes = attributedString.attributes( - at: match.range(at: 3).location, - longestEffectiveRange: nil, - in: match.range(at: 3) - ) - - addAttributes(attributedString, range: match.range(at: 3)) - - if let font = currentAttributes[.font] as? MarkdownFont { - attributedString.addAttribute( - NSAttributedString.Key.font, - value: font.bold(), - range: match.range(at: 3) - ) + attributedString.enumerateAttribute(.font, in: match.range(at: 3)) { value, range, stop in + if let font = value as? MarkdownFont { + attributedString.addAttribute( + NSAttributedString.Key.font, + value: font.bold(), + range: range + ) + } } attributedString.deleteCharacters(in: match.range(at: 2)) diff --git a/MarkdownKit/Sources/Common/Elements/Italic/MarkdownItalic.swift b/MarkdownKit/Sources/Common/Elements/Italic/MarkdownItalic.swift index 708cfdd..b8cc71d 100644 --- a/MarkdownKit/Sources/Common/Elements/Italic/MarkdownItalic.swift +++ b/MarkdownKit/Sources/Common/Elements/Italic/MarkdownItalic.swift @@ -9,7 +9,7 @@ import Foundation open class MarkdownItalic: MarkdownCommonElement { - fileprivate static let regex = "(\\s|^)(\\*|_)(?![\\*_\\s])(.+?)(?