element-meta icon indicating copy to clipboard operation
element-meta copied to clipboard

Should we go back to GFM rather than CommonMark? (The general Markdown bug)

Open ara4n opened this issue 7 years ago • 19 comments

One fix to the irritating bug https://github.com/vector-im/riot-web/issues/4674 is to go back to GFM from CommonMark. This bug exists to track the comparison i'm building up between them:

https://docs.google.com/spreadsheets/d/1pXWhED9CPtQTnQ5QGrCFSXuSi1yyHV9Gd-dNFIUVXIs/edit#gid=0

It follows on from the conversation at https://github.com/vector-im/riot-web/issues/4809#issuecomment-355158896

ara4n avatar Jan 07 '18 21:01 ara4n

Ironically, github have been maintaining the GFM spec and reference implementation as a diff against cmark (the C ref impl of commonmark): https://github.com/commonmark/cmark/compare/master...github:master (thanks to @maxgrenderjones to pointing it out). So one solution could be to 'just' port the same patches commonmark.js, and then we end up with best of both worlds?

ara4n avatar Jan 07 '18 22:01 ara4n

See also https://github.com/vector-im/riot-web/issues/5674

CommonMark spec seems to allow code fences interrupting a paragraph (unlike GFM), but the actual reference implementation seems to have the GFM behaviour.

pafcu avatar Jan 09 '18 13:01 pafcu

I'd like to bump this issue because CommonMark has no support for strikethrough which I consider a very useful tool that is unavailable at the moment. Has there been any movement in this discussion internally or is the idea mostly dead by now?

dkanada avatar Mar 23 '20 02:03 dkanada

@ara4n Could we just return to Marked in Riot Web, or would we really want the C reference impl of GFM? The 2017 PR to move to CommonMark (https://github.com/matrix-org/matrix-react-sdk/pull/575) only says that "Marked has some annoying bugs", so it's not clear to me what those were / how annoying they were / if they still exist.

jryans avatar May 07 '20 15:05 jryans

CommonMark is missing so many simple but incredibly useful things. Please switch to GFM

mpfaff avatar Jul 13 '20 19:07 mpfaff

Do libraries exist that can efficiently transform html back to GFM? That's the biggest issue i see right now, and also where markdown style is erased (e.g. *italics* -> _italics_). So maybe a new format, e.g. m.style.gfm is needed to compensate for this?

This'd make markdown more predictable, instead of janky through it being converted to HTML and back.

ShadowJonathan avatar Feb 18 '21 08:02 ShadowJonathan

This is a major inconvenience. Coming from GitHub, Slack, and other platforms that support simple (I will refrain from saying standard) markdown to Element/Riot is frustrating to say the least.

I suspect it's also a good reason for more casual users to drop it as a client --and therefore being turned off the entire ecosystem.

onemorepereira avatar Jun 11 '21 15:06 onemorepereira

I really think this should have its priority raised, not reduced. The text formatting is the major pain point of Element for most users in my circle. It is generally seen as the worst composer of any messaging client and most significant drawback to using Matrix/Element. Hands down, I would strongly prefer plain text only messaging to the current markdown implementation.

The formatting kicks in at unwanted times (single-item lists), message source gets messed up when editing messages (escaping backslashes are lost, quotes get formatted completely differently), quotes with empty lines just don't work, and the list goes on... And there is no escape from this hell, because there is no option to permanently disable Markdown.

AgentOak avatar Oct 30 '21 18:10 AgentOak

I'd like to mention that comrak seems to be a good library to support this feature with, as element is already largely migrating towards rust.

ShadowJonathan avatar Dec 23 '21 20:12 ShadowJonathan

Thanks to https://github.com/vector-im/element-web/issues/4674 and https://github.com/matrix-org/matrix-react-sdk/pull/7200 we look to be drifting towards a GFM-flavoured dialect of commonmark anyway?

ara4n avatar Apr 13 '22 10:04 ara4n

I think lack of tilde strikethrough and table syntax remain glaring differences

t3chguy avatar Apr 13 '22 10:04 t3chguy

Missing tables wouldn't be that bad if html is passed through, but I think it's stripped?

ptman avatar Apr 13 '22 10:04 ptman

Have you considered using markdown-it which has the advantage to have some compatibility with common mark but without the lack of customization ?

Otherwise have you considered doing it our-self to have a product that fully meets element needs ?

Hugueprime avatar Jul 01 '22 15:07 Hugueprime

@Hugueprime that looks to be a JS implementation only, this issue relates to all Element client codebases given they must stay consistent. So needs JS + Kotlin + Swift implementations, or a reusable Rust implementation.

t3chguy avatar Jul 01 '22 15:07 t3chguy

In https://github.com/vector-im/element-web/issues/14898 I explained why I think using the dialect commonly used in messengers makes more sense, and GFM doesn't seem to implement that either unless I'm mistaken. If that's true, then it seems to me a custom addition, for example using either GFM or CommonMark but with a custom previous pass for some corner cases like for more lenient backtick handling, might be the way to go.

ell1e avatar Sep 30 '22 11:09 ell1e

From https://github.com/vector-im/element-web/issues/20724: we'd (at the very least) like to be able to use emoticons like >_> or >.< without them being interpreted as block quotes, so something like requiring a space after a > (like discord and other messengers do) would be wanted.

ShadowJonathan avatar Apr 21 '23 09:04 ShadowJonathan

If I'm not mistaken, both matrix-rust-sdk and matrix-rich-text-editor are using https://github.com/raphlinus/pulldown-cmark which supports some of the GFM extensions over CM:

Further, it optionally supports parsing footnotes, Github flavored tables, Github flavored task lists and strikethrough.

In fact, both Element X iOS and Android support composing GFM strikethrough and tables already. They don't correctly render the tables but the formatted HTML representation is correct.

Meanwhile Element Web remains stuck on its own CM extension. Changing that doesn't seem trivial due to the magic we're doing in https://github.com/matrix-org/matrix-react-sdk/blob/develop/src/Markdown.ts.

However, in general I think there's little point to stick to CM on just one platform and ergonomic strikethrough and tables, while being somewhat exotic, seem like highly desirable features to me.

Johennes avatar Jul 28 '23 09:07 Johennes

We switched from Mattermost to Matrix and run into this issue - meaning that in Mattermost a table was formatted and in Matrix not. This is, in our opinion, a keyfeature. Please switch to GFM!

DVTrast avatar Mar 26 '25 07:03 DVTrast

Maybe Element Web could try switching to pulldown-cmark (possibly wrapped by matrix-rust-sdk) via Wasm?

Johennes avatar Mar 26 '25 07:03 Johennes

Yea, it's odd that commonmark has html support

/html <table>
  <thead>
    <tr>
      <th>Column 1</th>
      <th>Column 2</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <td>Lorem</td>
      <td>Ipsum</td>
    </tr>
    <tr>
      <td>et</td>
      <td>dolor</td>
    </tr>
  </tbody>
</table>

which works in element with the /html command.. yet you can't do a table with the markdown lol

Image

G2G2G2G avatar May 21 '25 19:05 G2G2G2G