This commit is contained in:
Mauro Romito 2022-12-15 01:41:45 +01:00
parent a484c283cb
commit 22479c53d6

View file

@ -51,6 +51,10 @@ class HTMLFormatter: NSObject {
DTDefaultFontName: font.fontName,
DTDefaultFontSize: font.pointSize,
DTDefaultLinkDecoration: false,
// This fixes the issue where links are displayed in black
// However doesn't matter the value provided the color doesn't change
// From the default accent one
DTDefaultLinkColor: "",
DTWillFlushBlockCallBack: sanitizeCallback
]
options.merge(extraOptions) { (_, new) in new }
@ -63,6 +67,7 @@ class HTMLFormatter: NSObject {
MXKTools.removeDTCoreTextArtifacts(mutableString)
postFormatOperations?(mutableString)
return mutableString
}
@ -109,3 +114,27 @@ extension HTMLFormatter {
return stringBuilder?.generatedAttributedString()
}
}
extension UIColor {
func toHexString() -> String {
var r:CGFloat = 0
var g:CGFloat = 0
var b:CGFloat = 0
var a:CGFloat = 0
getRed(&r, green: &g, blue: &b, alpha: &a)
let rgb:Int = (Int)(r*255)<<16 | (Int)(g*255)<<8 | (Int)(b*255)<<0
return NSString(format:"#%06x", rgb) as String
}
convenience init(red: Int, green: Int, blue: Int) {
assert(red >= 0 && red <= 255, "Invalid red component")
assert(green >= 0 && green <= 255, "Invalid green component")
assert(blue >= 0 && blue <= 255, "Invalid blue component")
self.init(red: CGFloat(red) / 255.0, green: CGFloat(green) / 255.0, blue: CGFloat(blue) / 255.0, alpha: 1.0)
}
}