Set HTML formatter as static

This commit is contained in:
aringenbach
2022-06-13 13:24:19 +02:00
committed by aringenbach
parent 24c3ba53e5
commit f2e14f2512
3 changed files with 16 additions and 18 deletions

View File

@@ -31,12 +31,12 @@ class HTMLFormatter: NSObject {
/// - postFormatOperations: Optional block to provide operations to apply
/// - Returns: The built `NSAttributedString`.
/// - Note: It is recommended to include "p" and "body" tags in `allowedTags` as these are often added when parsing.
func formatHTML(_ htmlString: String,
withAllowedTags allowedTags: [String],
font: UIFont,
andImageHandler imageHandler: DTHTMLElement.ImageHandler? = nil,
extraOptions: [AnyHashable: Any] = [:],
postFormatOperations: ((NSMutableAttributedString) -> Void)? = nil) -> NSAttributedString {
static func formatHTML(_ htmlString: String,
withAllowedTags allowedTags: [String],
font: UIFont,
andImageHandler imageHandler: DTHTMLElement.ImageHandler? = nil,
extraOptions: [AnyHashable: Any] = [:],
postFormatOperations: ((NSMutableAttributedString) -> Void)? = nil) -> NSAttributedString {
guard let data = htmlString.data(using: .utf8) else {
return NSAttributedString(string: htmlString)
}
@@ -72,7 +72,7 @@ class HTMLFormatter: NSObject {
/// - link: The link text to be inserted.
/// - url: The URL to be linked to.
/// - Returns: An attributed string.
func format(_ string: String, with link: String, using url: URL) -> NSAttributedString {
static func format(_ string: String, with link: String, using url: URL) -> NSAttributedString {
let baseString = NSMutableAttributedString(string: string)
let attributedLink = NSAttributedString(string: link, attributes: [.link: url])
@@ -91,8 +91,8 @@ extension HTMLFormatter {
/// - data: The data in HTML format from which to create the attributed string.
/// - options: Specifies how the document should be loaded.
/// - Returns: Returns an initialized object, or `nil` if the data cant be decoded.
@objc func formatHTML(_ data: Data,
options: [AnyHashable: Any]) -> NSAttributedString? {
@objc static func formatHTML(_ data: Data,
options: [AnyHashable: Any]) -> NSAttributedString? {
guard !data.isEmpty else {
return nil
}