Total Pageviews

Wednesday, 9 March 2016

transform html into markdown

Transform html into markdown. Useful for example if you want to import html into your markdown based application.
Build Status Gem Version Code Climate Code Climate



  1. Nokogiri
  2. Ruby 1.9.3 or higher


Install the gem
[sudo] gem install reverse_markdown
or add it to your Gemfile
gem 'reverse_markdown'


  • Supports all the established html tags like h1h2h3h4h5h6pemstrongibblockquotecodeimgahrliolultabletrthtdbr
  • Module based - if you miss a tag, just add it
  • Can deal with nested lists
  • Inline and block code is supported
  • Supports blockquote



You can convert html content as string or Nokogiri document:
input  = '<strong>feelings</strong>'
result = ReverseMarkdown.convert input
result.inspect # " **feelings** "


It's also possible to convert html files to markdown using the binary:
$ reverse_markdown file.html >
$ cat file.html | reverse_markdown >


The following options are available:
  • unknown_tags (default pass_through) - how to handle unknown tags. Valid options are:
    • pass_through - Include the unknown tag completely into the result
    • drop - Drop the unknown tag and its content
    • bypass - Ignore the unknown tag but try to convert its content
    • raise - Raise an error to let you know
  • github_flavored (default false) - use github flavored markdown (yet only code blocks are supported)
  • tag_border (default ' ') - how to handle tag borders. valid options are:
    • ' ' - Add whitespace if there is none at tag borders.
    • '' - Do not not add whitespace
  • from