Skip to content
This repository has been archived by the owner on Aug 19, 2023. It is now read-only.

Slowyourlife/reverse_markdown

This branch is 10 commits ahead of, 84 commits behind xijo/reverse_markdown:master.

Folders and files

NameName
Last commit message
Last commit date
Mar 30, 2014
May 10, 2015
May 9, 2015
Sep 4, 2014
Sep 4, 2014
Apr 13, 2015
May 9, 2015
Aug 11, 2012
Mar 30, 2014
Feb 1, 2015
Sep 4, 2014
Sep 21, 2020

Repository files navigation

Summary

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

Changelog

See Change Log

Requirements

  1. Nokogiri
  2. Ruby 1.9.3 or higher

Installation

Install the gem

[sudo] gem install reverse_markdown

or add it to your Gemfile

gem 'reverse_markdown'

Features

  • 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

Usage

Ruby

You can convert html content as string or Nokogiri document:

input  = '<strong>feelings</strong>'
result = ReverseMarkdown.convert input
result.inspect # " **feelings** "

Commandline

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

Configuration

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)

As options

Just pass your chosen configuration options in after the input. The given options will last for this operation only.

ReverseMarkdown.convert(input, unknown_tags: :raise, github_flavored: true)

Preconfigure

Or configure it block style on a initializer level. These configurations will last for all conversions until they are set to something different.

ReverseMarkdown.config do |config|
  config.unknown_tags     = :bypass
  config.github_flavored  = true
end

Related stuff

Thanks

Thanks to all contributors and all other helpers:

About

Ruby gem to convert html into markdown

Resources

License

Stars

Watchers

Forks

Languages

  • Ruby 84.1%
  • HTML 15.9%