Showing posts with label ruby. Show all posts
Showing posts with label ruby. Show all posts

2014-04-05

Enabling Markdown on your apache webserver - update 3

Last time on "Enabling Markdown on your apache webserver":
And now, the exciting conclusion....

I've updated my CGI handler yet again with a few new features and I've posted it on my GitHub account, in the docs-on-clearance repo (get 'em cheap while they're all marked down! yuk yuk yuk). The new features are:

1. Included an Apache config snippet that you can just drop into an include directory.

2. The rendered HTML now has a stylesheet! And not just any stylesheet - a cool responsive Bootstrap stylesheet loaded from a CDN! Yes, it's mostly the plain default one with some margins, but it looks a lot better.

3. I enabled table-of-contents links for all header sections so you can have URI fragments that point directly to sections of your document. I consider this unfinished as the fragments are of the form #toc_2 - which isn't very useful. I believe the latest versions of the gem have GitHub style toc fragments, but that's not what is in the ubuntu package repos.

4. I've added support for caching the rendered HTML with memcached. This is more like a nice-to-have, but since we're going to use this full-time for internal documentation at $WORK, I figured I should make the extra effort. Of course, I chose poorly an outdated gem to implement this with, but it's ship now, fix later. Updating to Dalli or something on the ToDo list.

tl;dr - see the docs-on-clearance repo for the code.

As always, I welcome comments, suggestions and pull requests.

2013-10-07

Enabling Markdown on your apache webserver - redux

In a previous post I enabled previewing of Markdown formatted documents using the Text::Markdown perl module. However simple that module was to implement, it only implemented daringfireball markdown. Things at $WORK have ramped up the adoption of Markdown and the atrophied standard is not enough. So, I've had to find another renderer.

Started by looking at how GitHub renders markdown and found they use the Redcarpet gem. The examples in the documentation combined with the ruby-redcarpet Ubuntu package make this a pretty simple exercise in upgrading my Markdown renderer:
  1. Install the Redcarpet gem:

  2. apt-get install ruby-redcarpet

  3. Replace ye olde Markdown.cgi with new hotness Markdown.cgi

  4. #!/usr/bin/ruby
    require 'redcarpet'
    print "Content-type: text/html\n\n"
    markdown = Redcarpet::Markdown.new(
        Redcarpet::Render::HTML,
        :autolink => true,
        :fenced_code_blocks => true,
    )
    puts markdown.render(File.read(ENV['PATH_TRANSLATED']))

  5. Start your browser, surf the docs!
UPDATE: I've updated my renderer for Markdown.

Ratings and Recommendations by outbrain