How to Convert Markdown to HTML in Python
We can easily make consistent Markdown to HTML conversions in Python using a free API.
We can structure our API call using the ready-to-run Python code examples provided below. This will quickly convert Markdown files (.md or .markdown) into the corresponding HTML code.
We can first install the SDK using pip install:
pip install cloudmersive-convert-api-client
Next, we can quickly grab a free Cloudmersive API key to authorize our requests (this will allow us to make a limit of 800 API calls per month with no additional commitments).
Lastly, we can add the imports and call the function (using our Markdown file path to load our file contents):
from __future__ import print_function
import time
import cloudmersive_convert_api_client
from cloudmersive_convert_api_client.rest import ApiException
from pprint import pprint
# Configure API key authorization: Apikey
configuration = cloudmersive_convert_api_client.Configuration()
configuration.api_key['Apikey'] = 'YOUR_API_KEY'
# create an instance of the API class
api_instance = cloudmersive_convert_api_client.ConvertWebApi(cloudmersive_convert_api_client.ApiClient(configuration))
input_file = '/path/to/inputfile' # file | Input file to perform the operation on.
try:
# Convert Markdown to HTML
api_response = api_instance.convert_web_md_to_html(input_file)
pprint(api_response)
except ApiException as e:
print("Exception when calling ConvertWebApi->convert_web_md_to_html: %s\n" % e)
It’s just that easy — we can now make quick Markdown to HTML conversions in Python through a free, low-code API.