nio icon indicating copy to clipboard operation
nio copied to clipboard

Message Composition: Parse Markdown and send HTML

Open kiliankoe opened this issue 4 years ago • 8 comments

See #281.

kiliankoe avatar Mar 24 '21 16:03 kiliankoe

This library seems like it could do the job quite well: https://github.com/JohnSundell/Ink

kloenk avatar Aug 05 '21 15:08 kloenk

Or this one, probably makes more sense than an arbitrary custom parser: https://github.com/apple/swift-cmark

helje5 avatar Aug 05 '21 15:08 helje5

Also AttributedString, but it does not seem to have anything to output html, only to render markdown

kloenk avatar Aug 05 '21 15:08 kloenk

The HTML generated by NSAttributedString isn't any good anyways, IIRC. I use CMark in SwiftPM Catalog to display the READMEs, and it works really well for that purpose (and is very easy to use).

helje5 avatar Aug 05 '21 15:08 helje5

Finally, for editing, the message composition field should probably be a rich text field as well, so that users can also just bold/italic the text. So the HTML renderer is (should be) not just "Markdown to HTML", but "Markdown + AttributedString attributes to HTML".

helje5 avatar Aug 05 '21 15:08 helje5

The HTML generated by NSAttributedString isn't any good anyways, IIRC. I use CMark in SwiftPM Catalog to display the READMEs, and it works really well for that purpose (and is very easy to use).

Do you have api doc for cmark-swift (or a link to a project which uses it)? I did not yet figure out if we can add the mx-* custom html tags. This is as far as I saw possible in Ink.

The AttributedString is new in iOS 15 IIRC.

kloenk avatar Aug 05 '21 15:08 kloenk

AttributedString is new in iOS 15. NSAttributedString was new in NeXTstep.

Presumably those "mx" tags would be produced by typing @user and #channel and such? Not sure whether such things can be added to CMark. In Nio however, one should deal with those in the UI anyways. I.e. if you type @, a completion panel should pop up and then store the result as an attributed string key (and turn the text into a proper "pill"/badge).

I say "should", because this is quite a bit of work to get right :-)

helje5 avatar Aug 05 '21 15:08 helje5

It's also there for Blockquote > . This is AFAIK defined in the markdown spec, but resulting html is changed for matrix.

Stuff like @user #channel is IIRC just an a tag, with a link (usually matrix.to)

kloenk avatar Aug 05 '21 16:08 kloenk