diff --git a/Tusker/HTMLConverter.swift b/Tusker/HTMLConverter.swift index 22504752..8f747811 100644 --- a/Tusker/HTMLConverter.swift +++ b/Tusker/HTMLConverter.swift @@ -86,6 +86,12 @@ struct HTMLConverter { } } + lazy var currentFont = if attributed.length == 0 { + font + } else { + attributed.attribute(.font, at: 0, effectiveRange: nil) as? UIFont ?? font + } + switch node.tagName() { case "br": // need to specify defaultFont here b/c otherwise it uses the default 12pt Helvetica which @@ -102,20 +108,8 @@ struct HTMLConverter { case "p": attributed.append(NSAttributedString(string: "\n\n", attributes: [.font: font])) case "em", "i": - let currentFont: UIFont - if attributed.length == 0 { - currentFont = font - } else { - currentFont = attributed.attribute(.font, at: 0, effectiveRange: nil) as? UIFont ?? font - } attributed.addAttribute(.font, value: currentFont.withTraits(.traitItalic)!, range: attributed.fullRange) case "strong", "b": - let currentFont: UIFont - if attributed.length == 0 { - currentFont = font - } else { - currentFont = attributed.attribute(.font, at: 0, effectiveRange: nil) as? UIFont ?? font - } attributed.addAttribute(.font, value: currentFont.withTraits(.traitBold)!, range: attributed.fullRange) case "del": attributed.addAttribute(.strikethroughStyle, value: NSUnderlineStyle.single.rawValue, range: attributed.fullRange) @@ -124,6 +118,14 @@ struct HTMLConverter { case "pre": attributed.append(NSAttributedString(string: "\n\n")) attributed.addAttribute(.font, value: monospaceFont, range: attributed.fullRange) + case "blockquote": + let paragraphStyle = paragraphStyle.mutableCopy() as! NSMutableParagraphStyle + paragraphStyle.headIndent = 32 + paragraphStyle.firstLineHeadIndent = 32 + attributed.addAttributes([ + .font: currentFont.withTraits(.traitItalic)!, + .paragraphStyle: paragraphStyle, + ], range: attributed.fullRange) default: break }