HTML NSAttributedString technique that avoids Sonoma's TextKit issues

Basic HTML strings do not display correctly on macOS Sonoma, I am wondering if there is an alternative technique that can be utilized. There was a minor change in macOS 14.2, which fixed some cases but made others much worse.

Consider the following code:

    override func viewDidLoad() {
        super.viewDidLoad()

        let html = """
<table width="100%" border="1" style="color: white">
  <tr>
    <td align="left">Left</td>
    <td align="right">Right</td>
  </tr>
</table>
"""
        let data = Data(html.utf8)
        let definition = try! NSAttributedString(data: data, options: [.documentType: NSAttributedString.DocumentType.html, .characterEncoding: NSNumber(value: String.Encoding.utf8.rawValue)], documentAttributes: nil)
        let frameRect = NSRect(x: 100, y: 0, width: 300, height: 200)
        let textView = NSTextView(frame: frameRect)
        textView.textStorage?.setAttributedString(definition)
        textView.backgroundColor = .clear

        view.addSubview(textView)
    }

On macOS 14 (23A5312d) it looks like this (FB13170237):

On macOS 14.2 (23C64) it looks like this (FB13465833):

Accepted Reply

Fixed in macOS 14.3 (23D56).

Replies

Fixed in macOS 14.3 (23D56).