Giter VIP home page Giter VIP logo

reverse_markdown's Introduction

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 2.0.0 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, figure
  • 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)
  • 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.

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
  config.tag_border  = ''
end

Related stuff

Thanks

Thanks to all contributors and all other helpers:

reverse_markdown's People

Contributors

xijo avatar harlantwood avatar pocke avatar mauidude avatar henrypoydar avatar craig-day avatar ehsandarroudi avatar grddev avatar olleolleolle avatar willglynn avatar anshul78 avatar rgould avatar aried3r avatar visoft avatar danschultzer avatar diogoosorio avatar mu-is-too-short avatar gstamp avatar grmartin avatar gregoryjscott avatar jeanmartin avatar jesperronn avatar kerrick avatar michaelglass avatar staugaard avatar niall3rs avatar shivabhusal avatar livathinos avatar stephencroberts avatar sunaku avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.