Git Product home page Git Product logo

commonmark.net's Introduction

Build status

CommonMark.NET

Implementation of CommonMark specification (passes tests from version 0.27) in C# for converting Markdown documents to HTML.

The current version of the library is also available on NuGet.

Usage

To convert Markdown data in a stream or file:

using (var reader = new System.IO.StreamReader("source.md"))
using (var writer = new System.IO.StreamWriter("result.html"))
{
  CommonMark.CommonMarkConverter.Convert(reader, writer);
}

To convert data stored in a string:

var result = CommonMark.CommonMarkConverter.Convert("**Hello world!**");

See the wiki for an example how the parser can be extended with additional logic.

Important: The converter does not include any HTML sanitizing.

Installation via NuGet

Install-Package CommonMark.NET

Compatibility

The library uses no references except for System - it has no external dependencies. It is cross compiled to:

  • .NET Framework 2.0
  • .NET Framework 3.5 Client Profile
  • .NET Framework 4.0 Client Profile
  • .NET 4.0 Portable Class Library
    • .NET Framework 4.0 Client Profile
    • Silverlight 5
    • Windows 8
    • Windows Phone 8.1
    • Windows Phone Silverlight 8
    • Xamarin.Android
    • Xamarin.iOS
  • .NET 4.5 Portable Class Library (Optimized)
    • .NET Framework 4.5
    • Windows 8
    • Windows Phone 8.1
    • Windows Phone Silverlight 8
    • Xamarin.Android
    • Xamarin.iOS
  • .NET Framework 4.5 (Optimized)
  • .NET Core 1.0 (.NET Standard 1.0)

For working with the source code you will need Visual Studio 2015 or newer (Community edition is supported).

Performance

Using a simple tool to compare the performance of various Markdown implementations for .NET yields the following results:

 CommonMark.NET 0.4.1      4 ms   7%      

CommonMarkSharp 0.3.2     30 ms   46%
   MarkdownSharp 1.13     55 ms   84%     (might not conform to CommonMark specification)
     MarkdownDeep 1.5      7 ms   11%     (might not conform to CommonMark specification)
  MoonShine (sundown)      3 ms    6%     (wrapper for a native x86 .dll)
             Baseline     65 ms   100%    (used to compare results on different machines)

This benchmark is very simple and tests the processing of the CommonMark specification document itself (a 115 KB file). The results are provided just for a high-level comparison.

Reliability

The parser uses algorithms that completely avoid recursion so even specifically crafted input documents will not cause exceptions and will be rendered correctly. This is important because a StackOverflowException cannot be caught and will bring down the entire process.

References

This library is based on a port of the reference implementation in C, available on jgm/cmark repo. It follows the same approach - the source is parsed into a syntax tree that can be used to add custom processing if the application needs it and then formatted into HTML.

Running tests

All tests from spec.txt are merged into the unit testing project and can be executed from within Visual Studio.

The project also includes a slightly modified version of runtests.pl for compatibility with the original implementation. Use CommonMark.Console.exe --perltest as the argument to runtests.pl so that the application can correctly handle input from the Perl script.

commonmark.net's People

Contributors

knagis avatar dmitry-shechtman avatar rstefko avatar zoomcharts avatar sharwell avatar arthrp avatar donchak avatar meziantou avatar iignatov avatar joebuschmann avatar josephwoodward avatar stevehansen 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.