Reputation: 6847
Most Markdown parsers generate very similar HTML output, but it can slightly vary.
Some parsers are strict and allow only this is **bold**
but not this is ** bold **
others accept both. There are many other nuances.
I want to use pagedown in the frontend. Which gem or library produces the same HTML output?
The result in the "preview" should be exactly the same as the generated HTML in the backend.
Upvotes: 0
Views: 131
Reputation: 23576
Pagedown description says that this is port of Sundown, so Redcarpet without any extensions should work as expected.
Upvotes: 2
Reputation: 54694
If you want exactly the same HTML you could simply save the pagedown output along with the markdown source in the database and only parse the markdown in Ruby if there was no HTML output posted (as a fallback , i.e. when javascript is disabled or broken).
Edit
As pointed out in the comments (thanks!) this is a potential security issue, because an attacker can submit arbitrary HTML.
Another solution would be to use Node.js on the client side and let pagedown do the parsing there, too.
Upvotes: 1