kivikakk / comrak

CommonMark + GFM compatible Markdown parser and renderer
Other
1.19k stars 139 forks source link

Markdown differences #449

Open liamwhite opened 2 months ago

liamwhite commented 2 months ago

GitHub supports a "difference mode" in its Markdown support. This can be demonstrated e.g. on this repository here by selecting the "Rich diff":

Capture
image

The difference algorithm seems to be at least vaguely syntax-aware, so this isn't necessarily handled on its own by just a Myers diff. Is it possible for comrak to support such a difference mode?

gjtorikian commented 2 months ago

I actually worked on this feature when I was at GitHub. It's not a complicated process; I vaguely remember it being a process where the before and after nodes of the HTML trees were walked, with a diff on children that were added or removed.

I don't know whether comrak should support this natively per se, but one can already walk through the AST on their own. Would a code sample showing that be helpful? How would you ultimately use this feature?

liamwhite commented 2 months ago

A code sample would be very helpful, yes. :)

My ultimate plan is to use it in a similar way to how GitHub uses it, for highlighting differences between different versions of forum posts/comments,