Markdown Converter – Convert MD in C#

Markdown is a lightweight markup language designed to indicate formatting in plain text. MD files use Markdown language that was proposed and developed by John Gruber. They include inline text characters that determine how text is formatted, such as indentation, table formatting, fonts, and headings. In addition, MD files can be converted to HTML, PDF or images to take advantage of other formats for specific tasks.

The main highlight of Aspose.HTML is a conversion feature. The Aspose.Html.Converters namespace implements easy access to conversion methods. It provides a wide range of conversions to popular formats, such as Markdown to HTML, Markdown to DOCX, or Markdown to PDF.

You can download the complete examples and data files from GitHub.

This section provides information on the list of supported Markdown conversions and how to perform them using ConvertMarkdown() methods. All of these methods allow for the basic Markdown to HTML conversion. Conversions from Markdown to other formats go through the Markdown to HTML conversion stage.

Please take a look at the following C# example, which shows Markdown to JPG conversion with ImageSaveOptions specifying:

 1// Prepare a path to a source Markdown file
 2string sourcePath = Path.Combine(DataDir, "nature.md");
 3
 4// Prepare a path to save the converted file
 5string savePath = Path.Combine(OutputDir, "nature-options.jpg");
 6
 7// Convert Markdown to HTML
 8using var document = Converter.ConvertMarkdown(sourcePath);
 9
10// Initialize ImageSaveOptions 
11var options = new ImageSaveOptions(ImageFormat.Jpeg)
12{
13    UseAntialiasing = true,
14    HorizontalResolution = 200,
15    VerticalResolution = 200,
16    BackgroundColor = System.Drawing.Color.AliceBlue
17};
18options.PageSetup.AnyPage = new Page(new Aspose.Html.Drawing.Size(600, 950), new Margin(30, 20, 10, 10));
19
20// Convert HTML to JPG
21Converter.ConvertHTML(document, options, savePath);

In the example, the ConvertMarkdown(sourcePath) method takes the source path of an Markdown file and results an HTMLDocument. The ImageSaveOptions() constructor creates a new ImageSaveOptions object with JPG ImageFormat and a set of properties. Then, the ConvertHTML() method takes HTMLDocument, ImageSaveOptions, and output path and completes the Markdown to JPG conversion.

Aspose.HTML offers a free online Markdown Converter for converting Markdown files to a variety of popular formats. You can easily convert Markdown to HTML, Markdown to PDF, Markdown to JPG, or MHTML to DOCX. Just select the file, choose the format to convert, and you’re done. It’s fast and completely free!

Subscribe to Aspose Product Updates

Get monthly newsletters & offers directly delivered to your mailbox.