I wanted Ruby and JSON code blocks ala Github’s Flavored Markdown when rendering markdown documents in doppler. The idea is that we can API documentation authored in markdown, and rendered within a Rails application.
The first, harder part, is doing markdown rendering with syntax highlighting. You render markdown with your favorite markdown gem (eg. Redcarpet), then parse the document and replace all code divs with a syntax highlighted version produced by Coderay. I had to also do some div swapping to avoid nested
We can use this in a controller, assuming content lives in app/voews/content. Bonus: caching.
The corresponding view in pages/show.html.haml is as follows.
You can route to one of those pages in routes.rb.
See https://github.com/artsy/doppler/pull/24 for a complete pull request with the above.
And here’s a screenshot of a rendered page.