Open ara4n opened 6 years ago
SwiftSoup looks very promising - I'll have to take a look at this.
The built-in WebKit HTML-to-NSAttributedString parser worked fine when it worked but created random crashes that I couldn't trace back to anywhere specific, hence why we're currently using the Markdown instead.
ftr one can follow the spec bug for finally speccing the html subset that org.matrix.custom.html supports over at https://github.com/matrix-org/matrix-doc/issues/1560. although we still want to replace this with a better fallback solution in future.
-- Matthew Hodgson Matrix.org
On 26 Aug 2018, at 11:53, Neil Alexander notifications@github.com wrote:
SwiftSoup looks very promising - I'll have to take a look at this.
The built-in WebKit HTML-to-NSAttributedString parser worked fine when it worked but created random crashes that I couldn't trace back to anywhere specific, hence why we're currently using the Markdown instead.
— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub, or mute the thread.
There's no guarantee that the plain body will contain MD, and despite formatted_body not being properly specified yet, you really should be displaying rich text bodies by parsing the HTML rather than parsing MD from the plain-text body in the desperate hope that it actually contains MD.
Parsing the HTML subset we use should be no harder and in fact substantially less magical than parsing MD.
You could use something like https://github.com/scinfu/SwiftSoup, and just build out the required NSAttributedString components from the resulting parse tree. The only tags you need to do are:
...all of which should map straight through to NSAttributedString stuff, with the possible exception of
img
andhr
.I'd ignore the table tags (
'table', 'thead', 'caption', 'tbody', 'tr', 'th', 'td'
) given commonmark can't generate them atm.This would then pave the way for things like Replies to work correctly (as per #51).