CutBox.app

Coverage Report

Created: 2024-03-12 03:40

.../Source/Extensions/NSAttributedString+HTML.swift
Line
Count
Source (jump to first uncovered line)
1
//
2
//  NSAttributedString+HTML.swift
3
//  CutBox
4
//
5
//  Created by Jason Milkins on 15/5/18.
6
//  Copyright © 2018-2023 ocodo. All rights reserved.
7
//
8
9
import Foundation
10
11
extension NSAttributedString {
12
1
    internal convenience init?(html: String) {
13
1
        guard let data = html.data(using: String.Encoding.utf16, allowLossyConversion: false) else {
14
0
            return nil
15
1
        }
16
1
17
1
        guard let attributedString = try? NSAttributedString(
18
1
            data: data,
19
1
            options: [.documentType: NSAttributedString.DocumentType.html,
20
1
                      .characterEncoding: String.Encoding.utf8.rawValue],
21
1
            documentAttributes: nil)
22
1
            else { return nil }
23
1
24
1
        self.init(attributedString: attributedString)
25
1
    }
26
}