We have several use cases where we need a html-renderer for local html-encoded strings: card questions and answers during test, drill, and card edit, and our help pages.
Originally we have implemented these using UIWebView, which is deprecated now.
The recommended replacement is WKWebView.
But both these APIs are actually overkill for our use case. They need a lot of resources and have slow startup time.
A possible alternative could be to use NSAttributedString instead.
This should be investigated in more detail.
"the approach is always the same: 1. turn the html into an attributedString 2. set that on the View/Control/TextView.. whatever"
Diff:
Selectable links: https://stackoverflow.com/questions/21629784/how-can-i-make-a-clickable-link-in-an-nsattributedstring
External css:
You can keep the CSS in a separate file in your bundle for macOS at least, as I've just had this working for me in to an NSTextView. First you need to include the stylesheet link in your HTML document's HEAD as you would usually (e.g. <link href="Base.css" type="text/css" rel="stylesheet">). Then when you create your NSAttributedString you need to pass a base URL (e.g. by using htmlUrl.deletingLastPathComponent() in Swift). – Quintin Willison May 17 '18 at 12:32
The same should work with image references, too.
the page history needs to be handled manually.
And no external links!
Last edit: Mathias Kussinger 2020-07-18
The html features of NSAttributedString are very limited. No tables, no badding. It makes no sense to use it to replace the Web views.