DEV Community

Cover image for How To Convert Medium Articles In Markdown Format
Nishu Jain
Nishu Jain

Posted on • Originally published at mediumapi.com

How To Convert Medium Articles In Markdown Format

Medium Articles → Markdown → HTML

There are several reasons why you might want to convert a Medium article from its original format to Markdown and then to HTML. In this article, I'll explain to you how you can do it using Python programming language with a few simple steps.

Why might you wanna do it?

Some of the benefits of using Markdown include:

  • Markdown is a simple, lightweight markup language that is easy to read and write. This makes it a convenient format for storing and editing articles, especially when compared to more complex formats such as HTML or XML.

  • Markdown supports a wide range of formatting options, such as headings, lists, links, and more, that can be applied using a simple and intuitive syntax. This allows you to add structure and formatting to your articles without having to use complex tags or styles.

  • Markdown is supported by a wide range of tools and platforms, including text editors, publishing systems, and more. This makes it easy to work with Markdown content and allows you to integrate your articles with other applications or services.

  • Markdown is a widely used and well-documented format with a large and active community of users. This means that you can easily find resources and support for working with Markdown and can share your articles with others who use the format.

Overall, converting a Medium article to Markdown can provide many benefits, such as making it easier to edit and format the article and enabling you to integrate it with other tools and platforms.

Whether or not this is the right approach for you will depend on your specific needs and goals.

Now let's jump to the code!


Python Code to convert Medium Article into Markdown and HTML


Code Explanation -

The code you provided is a Python script that uses the medium_api library to access the Unofficial Medium API and convert an article from Markdown to HTML.

You can install medium-api using the following command:

pip install medium-api
Enter fullscreen mode Exit fullscreen mode

Here is a brief explanation of what the code does:

  • The first two lines import the os and markdown libraries, which are used to access environmental variables and convert Markdown to HTML, respectively.
  • The third line imports the Medium class from the medium_api library, which is used to access the Unofficial Medium API.
  • The next three lines extract the ID of an article from its URL, and use the Medium object to retrieve the article data from the API. This data is stored in an article object.
  • The eighth line uses the markdown library to convert the article's Markdown content to HTML, and stores the result in a variable named html_output.
  • The last three lines write the HTML to a file named index.html, replacing all occurrences of the ( ' ) character with a single quote.

Overall, this code demonstrates how to use the medium_api library to access the Unofficial Medium API and convert an article from Markdown to HTML. It is not a complete application but rather a sample of how the API can be used in a Python script.


Resources 🚀

Thanks for reading, and have a nice day!


PS: We post tutorials, videos, code snippets, and insights related to Medium and our API. So be sure to follow us on:


Related Articles -

Top comments (0)