Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Markdown live preview like stackoverflow for redcarpet on rails

I'm using Redcarpet as markdown tool and coderay for syntax highlighting in my rails app. What I want is a preview of what is being written in markdown format before posting it in database. A far better option is a live preview of what's being written like stackoveflow. I know there are many other options but is there any way to stick with redcarpet and coderay and still having a preview of my post with syntax highlighting? Most of the preview options skip the syntax highlighting portion, they even can't detect codes! At least detecting that portion as a code will do. I just need a preview of my post before publishing it. How can I achieve that? I am not interested in using any WYSIWYG editor either!

like image 638
Shuvro Avatar asked Feb 07 '14 14:02

Shuvro


1 Answers

Your options are either to stick with Redcarpet and use Ajax or to switch to a javascript based markdown processor like: https://github.com/evilstreak/markdown-js and a javascript based syntax highlighter such as: https://github.com/google/code-prettify

With your current setup you'd have to send the markdown to the server via Ajax, process it with Redcarpet then send it back to the browser and inject it into a preview area. This will be much slower and more taxing on your server when traffic goes up. I wouldn't recommend it.

Switch to the js based markdown processor and syntax highlighter so you can do it all in the browser.

like image 59
DiegoSalazar Avatar answered Nov 16 '22 21:11

DiegoSalazar