Transform html into markdown. Useful for example if you want to import html into your markdown based application.
- Adds support for ruby versions 1.9.3 back in
- More options for handling of unknown tags
- Bugfixes in
li
indentation behavior
There were some breaking changes, please make sure you don't miss them:
- Only ruby versions 2.0.0 or above are supported
- There is no
Mapper
class any more. Just useReverseMarkdown.convert(input, options)
- Config option
github_style_code_blocks
changed its name togithub_flavored
Please open an issue and let me know about it if you have any trouble with the new version.
- Nokogiri
- 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
h1
,h2
,h3
,h4
,h5
,h6
,p
,em
,strong
,i
,b
,blockquote
,code
,img
,a
,hr
,li
,ol
,ul
,table
,tr
,th
,td
,br
- 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 > file.md
$ cat file.html | reverse_markdown > file.md
The following options are available:
unknown_tags
(defaultpass_through
) - how to handle unknown tags. Valid options are:pass_through
- Include the unknown tag completely into the resultdrop
- Drop the unknown tag and its contentbypass
- Ignore the unknown tag but try to convert its contentraise
- Raise an error to let you know
github_flavored
(defaultfalse
) - use github flavored markdown (yet only code blocks are supported)
Just pass your chosen configuration options in after the input
ReverseMarkdown.convert(input, unknown_tags: :raise, github_flavored: true)
Or configure it block style on a initializer level
ReverseMarkdown.config do |config|
config.ignore_unknown_tags = false
config.github_flavored = true
end
- Write custom converters - Wiki entry about how to write your own converter
- html_massage - A gem by Harlan T. Wood to convert regular sites into markdown using reverse_markdown
- word-to-markdown - Convert word docs into markdown while using reverse_markdown, by Ben Balter
- markdown syntax - The markdown syntax specification
- github flavored markdown - Githubs extension to markdown
- wmd-editor - Markdown flavored text editor
..to Ben Woosley for his improvements to the first version.
..to Harlan T. Wood for his help with the newer versions.
..and all contributors