Convert Markdown to HTML in Python – Aspose.HTML

This article provides information on how to convert Markdown to HTML using the Aspose.HTML for Python via .NET API. You will learn about using the convert_markdown() methods and consider Python code examples to illustrate them. Also, you can try an Online Markdown Converter to test the Aspose.HTML functionality and convert Markdown on the fly.

Online Markdown Converter

You can convert Markdown to HTML with Aspose.HTML in real time. Load a Markdown file, select the output format and run the example. The save options are set by default. You will immediately receive the conversion result as a separate file.

                
            

If you want to convert Markdown to HTML programmatically, please see the following Python code examples.

Convert Markdown to HTML

Aspose.HTML for Python via .NET provides convert_markdown() methods as an understandable and straightforward way to perform Markdown to HTML conversion. If your case is to create a Markdown document from a user string directly in your code and save it to a file, the following example could help you:

  1. Prepare a source Markdown document. In the example, we create a Markdown file from code.
  2. Prepare a path for converted file saving.
  3. Use the convert_markdown() method of the Converter class to save Markdown as an HTML file. In the following example, you need to pass the source_path and save_path to the convert_markdown() method for Markdown to HTML conversion.
 1import os
 2from aspose.html import *
 3from aspose.html.converters import *
 4
 5# Prepare a path to a source Markdown file
 6output_dir = "output/"
 7source_path = os.path.join(output_dir, "document.md")
 8
 9# Prepare a simple Markdown example
10code = "### Hello, World!\nConvert Markdown to HTML!"
11
12# Create a Markdown file
13with open(source_path, "w") as file:
14    file.write(code)
15
16# Prepare a path to save the converted file
17save_path = os.path.join(output_dir, "document-output.html")
18
19# Convert Markdown to HTML document
20document = Converter.convert_markdown(source_path, save_path)

Download our Aspose.HTML for Python via .NET library allows you to successfully, quickly, and easily convert your HTML, MHTML, EPUB, SVG, and Markdown documents to the most popular formats.

You can check the quality of Markdown to HTML conversion with our online MD to HTML Converter. Upload, convert your files and get results in a few seconds. Try our forceful Markdown to HTML Converter for free now!

Text “MD to HTML Converter”

Subscribe to Aspose Product Updates

Get monthly newsletters & offers directly delivered to your mailbox.