Avoid dictionary lookups when setting paragraph style
This commit is contained in:
parent
5a7b5860dd
commit
1ee7ab9405
|
@ -257,6 +257,7 @@ public struct AttributedStringConverter<Callbacks: HTMLConversionCallbacks> {
|
|||
}
|
||||
|
||||
var attributes = [NSAttributedString.Key: Any]()
|
||||
var paragraphStyle = configuration.paragraphStyle
|
||||
var currentFontTraits: FontTrait = []
|
||||
for style in styleStack {
|
||||
switch style {
|
||||
|
@ -273,19 +274,17 @@ public struct AttributedStringConverter<Callbacks: HTMLConversionCallbacks> {
|
|||
case .strikethrough:
|
||||
attributes[.strikethroughStyle] = NSUnderlineStyle.single.rawValue
|
||||
case .blockquote:
|
||||
attributes[.paragraphStyle] = blockquoteParagraphStyle
|
||||
paragraphStyle = blockquoteParagraphStyle
|
||||
currentFontTraits.insert(.italic)
|
||||
case .orderedList, .unorderedList:
|
||||
attributes[.paragraphStyle] = listParagraphStyle
|
||||
paragraphStyle = listParagraphStyle
|
||||
}
|
||||
}
|
||||
|
||||
attributes[.font] = getFont(traits: currentFontTraits)
|
||||
attributes[.foregroundColor] = configuration.color
|
||||
|
||||
if !attributes.keys.contains(.paragraphStyle) {
|
||||
attributes[.paragraphStyle] = configuration.paragraphStyle
|
||||
}
|
||||
attributes[.paragraphStyle] = paragraphStyle
|
||||
|
||||
str.append(NSAttributedString(string: currentRun, attributes: attributes))
|
||||
currentRun = ""
|
||||
|
|
Loading…
Reference in New Issue