Code Monkey home page Code Monkey logo

reversemarkdown-net's Introduction

Meet ReverseMarkdown

Windows Build status Windows Build status NuGet Version

ReverseMarkdown is a Html to Markdown (http://daringfireball.net/projects/markdown/syntax) converter library in C#. Conversion is very reliable since HtmlAgilityPack (HAP) library is used for traversing the Html DOM.

Note that the library implementation is based on the Ruby based Html to Markdown converter xijo/reverse_markdown.

Usage

You can install the package from NuGet using Install-Package ReverseMarkdown or clone the repository and built it yourself.

var converter = new ReverseMarkdown.Converter();

string html = "This a sample <strong>paragraph</strong> from <a href=\"http://test.com\">my site</a>";

string result = converter.Convert(html);

//result This a sample **paragraph** from [my site](http://test.com)
// with config
var config = new ReverseMarkdown.Config
{
    UnknownTags = Config.UnknownTagsOption.PassThrough, // Include the unknown tag completely in the result (default as well)
    GithubFlavored = true, // generate GitHub flavoured markdown, supported for BR, PRE and table tags
    RemoveComments = true, // will ignore all comments
    SmartHrefHandling = true // remove markdown output for links where appropriate
};

var converter = new ReverseMarkdown.Converter(config);

Configuration options

  • GithubFlavored - Github style markdown for br, pre and table. Default is false

  • RemoveComments - Remove comment tags with text. Default is false

  • SmartHrefHandling - how to handle <a> tag href attribute

    • false - Outputs [{name}]({href}{title}) even if name and href is identical. This is the default option.

    • true - If name and href equals, outputs just the name. Note that if Uri is not well formed as per Uri.IsWellFormedUriString (i.e string is not correctly escaped like http://example.com/path/file name.docx) then markdown syntax will be used anyway.

      If href contains http/https protocol, and name doesn't but otherwise are the same, output href only

      If tel: or mailto: scheme, but afterwards identical with name, output name only.

  • UnknownTags - handle unknown tags.

    • UnknownTagsOption.PassThrough - Include the unknown tag completely into the result. That is, the tag along with the text will be left in output. This is the default
    • UnknownTagsOption.Drop - Drop the unknown tag and its content
    • UnknownTagsOption.Bypass - Ignore the unknown tag but try to convert its content
    • UnknownTagsOption.Raise - Raise an error to let you know
  • WhitelistUriSchemes - Specify which schemes (without trailing colon) are to be allowed for <a> and <img> tags. Others will be bypassed (output text or nothing). By default allows everything.

    If string.Empty provided and when href or src schema coudn't be determined - whitelists

    Schema is determined by Uri class, with exception when url begins with / (file schema) and // (http schema)

  • TableWithoutHeaderRowHandling - handle table without header rows

    • TableWithoutHeaderRowHandlingOption.Default - First row will be used as header row (default)
    • TableWithoutHeaderRowHandlingOption.EmptyRow - An empty row will be added as the header row

Note that UnknownTags config has been changed to an enumeration in v2.0.0 (breaking change)

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
  • Can deal with nested lists
  • Github Flavoured Markdown conversion supported for br, pre and table. Use var config = new ReverseMarkdown.Config(githubFlavoured:true);. By default table will always be converted to Github flavored markdown immaterial of this flag.

Copyright

Copyright © 2019 Babu Annamalai

License

ReverseMarkdown is licensed under MIT. Refer to License file for more information.

reversemarkdown-net's People

Contributors

doggy8088 avatar ian-craig avatar janis-veinbergs avatar mysticmind avatar natelowry avatar promofaux avatar rickstrahl avatar rosskyl avatar stah avatar thepbjainatmicrosoft avatar zelloxy avatar

Watchers

 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.