Code Monkey home page Code Monkey logo

html2markdown's Introduction

HTML2Markdown

Converts HTML to Markdown.


Html2Markdown

Build Status

Branch Status
master master
develop develop

Support

This project will currently convert the following HTML tags:-

  • <a>
  • <strong>
  • <b>
  • <em>
  • <i>
  • <br>
  • <code>
  • <h1>
  • <h2>
  • <h3>
  • <h4>
  • <h5>
  • <h6>
  • <blockquote>
  • <img>
  • <hr>
  • <p>
  • <pre>
  • <ul>
  • <ol>

Installing via NuGet

NuGet version

    Install-Package Html2Markdown

Usage

Strings

var html = "Something to <strong>convert</strong>";
var converter = new Converter();
var markdown = converter.Convert(html);

Files

var path = "file.html";
var converter = new Converter();
var markdown = converter.ConvertFile(path);

Customise

Create new IScheme implementation

Create your own implementation of IScheme and construct Converter with that.

var html = "Something to <strong>convert</strong>";
var converter = new Converter(customConversionScheme);
var markdown = converter.Convert(html);

Try it

This library is showcased at http://html2markdown.bayn.es.

Contributing

For those interested in contributing then please read the guidelines

License

This project is licensed under Apache License 2.0.

html2markdown's People

Contributors

baynezy avatar dependabot[bot] avatar flensrocker avatar gitstream-cm[bot] avatar stevetemple avatar theaob avatar youssefazaroual avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

html2markdown's Issues

Line breaks, spaces, tabs...

In html line breaks, spaces, and tabs don't make sense and should be replaced by a single space in markdown.

Html:

<p>
  text
  text
  text
</p>

Markdown:
text text text\r\n\r\n

Convert to Portable Library

Update the project to be a portable class library

  • Convert to portable library
  • Make sure unit tests are working
  • Work out how to do versioning properly
  • Fix build to AppVeyor - including NuGet build

Line breaks kill italics

I have some HTML like this:

<i>Some text</br></i>

It's a strange way of doing it, but I have no control over the HTML. The problem is that this causes the converter to incorrectly render the markdown. It would be nice if elements in between the </i> didn't break it.

Nested HTML in <blockquote> does't convert properly

<blockquote>
    <p class="right" align="right">
            <em>“Qualquer coisa que possas fazer ou sonhar, podes começá-la. A ousadia encerra em si mesma genialidade, poder e magia.<br />
            Ouse fazer, e o poder lhe será dado!”</em><br />
            <strong>— Johann Wolfgang von Goethe</strong>
    </p>
</blockquote>

Creates

>

            *“Qualquer coisa que possas fazer ou sonhar, podes começá-la. A ousadia encerra em si mesma genialidade, poder e magia.  

            Ouse fazer, e o poder lhe será dado!”*  

            **— Johann Wolfgang von Goethe**

Should be

> *“Qualquer coisa que possas fazer ou sonhar, podes começá-la. A ousadia encerra em si mesma genialidade, poder e magia.  
> Ouse fazer, e o poder lhe será dado!”*  
> **— Johann Wolfgang von Goethe**

Modify to use depth first search

Change over the codebase to convert HTML by walking the graph, using depth first search. This will underpin subsequent features.

anchor with attribute after href

The existing regular expression for anchor does not match other attributes after href ex:

anchor

you can fix it with this regexp :

@"<a.+?href\s*=\s*'""['""][^>]*>([^<]+)"

Does not handle multiline <pre> tags properly

<pre><code>Install-Package Html2Markdown
</code></pre>

Does not convert properly

<pre><code>var converter = new Converter();
var result = converter.Convert(html);
</code></pre>

Does not convert properly

Missing method

Getting this error after updating to 1.0.3

System.MissingMethodException : Method not found: 'Void LinqExtensions.EachExtension.Each(System.Collections.Generic.IEnumerable`1<!!0>, System.Action`1<!!0>)'.

Updating LinqExtensions to 0.0.1.14396 fixes it.

Remove DOCTYPES

Things like <!DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> should be removed

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.