Markdown live preview like stackoverflow for redcarpet on rails
Asked Answered
H

1

6

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!

Hebetate answered 7/2, 2014 at 14:36 Comment(1)
Take a look at dillinger.ioForeigner
J
3

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.

Jeffcott answered 7/2, 2014 at 16:37 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.