Avoid dictionary lookups when setting paragraph style

This commit is contained in:
Shadowfacts 2023-12-26 12:02:38 -05:00
parent 5a7b5860dd
commit 1ee7ab9405
1 changed files with 4 additions and 5 deletions

View File

@ -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 = ""