* Only render HTML tags in markdown if they're del tags
* Consider non-allowed HTML tags as plain text nodes, so
a message of just '<shrug>' doesn't need to be sent as
HTML
* Consequently rewrite isPlaintext to just look at the parse
tree rather than making and gutting a renderer to walk
the tree (now we're using a library that actually produces
a meaningfgul parse tree).
* Tweak when we put \n on text output to avoid putting \n on
the end of messages.
Fixes https://github.com/vector-im/riot-web/issues/3065
Rather than keeping one in memory, abusing it in different ways
each time and then craefully putting it back the way it was (and
in one case, failing, because we forgot to put the `out` method
back).
so they don't claim it;s a wrapper around marked when it's now
commonmark, and comment why we render markdown to plaintext which
is somewhat unintuitive.
We still need to parse "plaintext" messages through the markdown
renderer so that escappes are rendered properly.
Fixesvector-im/riot-web#2870.
Signed-off-by: Johannes Löthberg <johannes@kyriasis.com>
Marked has some annoying bugs, and the author is inactive, so replace it
with commonmark.js, which is the reference JavaScript implementation of
CommonMark. CommonMark is also preferable since it has a specification,
and a conformance test suite to make sure that parsers are correct.
Signed-off-by: Johannes Löthberg <johannes@kyriasis.com>
Preserves the old behaviour of not wrapping everything in p tags,
but also returns valid markup if the resulting markdown contains
multiple paragraphs (previously it stripped the <p> from the start
and the </p> from the end, leaving closing and opening paragraph tags
in the middle of the returned markup).
Also turn on the 'xhtml' option so marked uses self-closing tags
for br's, hr's and so forth.