Markdown Converter | 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.

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:

using System.IO;
using Aspose.Html.Converters;
using Aspose.Html.Rendering.Image;
using Aspose.Html.Saving;
using System.Drawing;

    // Prepare a path to a source Markdown file
    string sourcePath = Path.Combine(DataDir, "");            
    // Prepare a path for converted file saving 
    string outputPath = Path.Combine(OutputDir, "nature-options.jpg");
    // Convert Markdown to HTML
    using var document = Converter.ConvertMarkdown(sourcePath);
    // Initialize an instance of ImageSaveOptions 
    var options = new ImageSaveOptions(ImageFormat.Jpeg)
        BackgroundColor = System.Drawing.Color.AliceBlue
    // Convert HTML document to JPG image file format
    Converter.ConvertHTML(document, options, outputPath);

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 BackgroundColor properties. Then, the ConvertHTML() method takes HTMLDocument, ImageSaveOptions, and output path and completes the Markdown to JPG conversion.