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 attributes = [NSAttributedString.Key: Any]()
|
||||||
|
var paragraphStyle = configuration.paragraphStyle
|
||||||
var currentFontTraits: FontTrait = []
|
var currentFontTraits: FontTrait = []
|
||||||
for style in styleStack {
|
for style in styleStack {
|
||||||
switch style {
|
switch style {
|
||||||
|
@ -273,19 +274,17 @@ public struct AttributedStringConverter<Callbacks: HTMLConversionCallbacks> {
|
||||||
case .strikethrough:
|
case .strikethrough:
|
||||||
attributes[.strikethroughStyle] = NSUnderlineStyle.single.rawValue
|
attributes[.strikethroughStyle] = NSUnderlineStyle.single.rawValue
|
||||||
case .blockquote:
|
case .blockquote:
|
||||||
attributes[.paragraphStyle] = blockquoteParagraphStyle
|
paragraphStyle = blockquoteParagraphStyle
|
||||||
currentFontTraits.insert(.italic)
|
currentFontTraits.insert(.italic)
|
||||||
case .orderedList, .unorderedList:
|
case .orderedList, .unorderedList:
|
||||||
attributes[.paragraphStyle] = listParagraphStyle
|
paragraphStyle = listParagraphStyle
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
attributes[.font] = getFont(traits: currentFontTraits)
|
attributes[.font] = getFont(traits: currentFontTraits)
|
||||||
attributes[.foregroundColor] = configuration.color
|
attributes[.foregroundColor] = configuration.color
|
||||||
|
|
||||||
if !attributes.keys.contains(.paragraphStyle) {
|
attributes[.paragraphStyle] = paragraphStyle
|
||||||
attributes[.paragraphStyle] = configuration.paragraphStyle
|
|
||||||
}
|
|
||||||
|
|
||||||
str.append(NSAttributedString(string: currentRun, attributes: attributes))
|
str.append(NSAttributedString(string: currentRun, attributes: attributes))
|
||||||
currentRun = ""
|
currentRun = ""
|
||||||
|
|
Loading…
Reference in New Issue