Theo van der Sluijs
Aug 10 · 5 min read

I had to move all my articles from Jekyll to Medium. But they are not compatible. The Medium editor is based on HTML text and Jekyll on MD files. And I had like more than 100 posts to copy paste on Medium. Luckily for me Medium has a API that can process my Markdown files with a little help of Python.

So I wanted to write blog articles and not beeing so busy with coding my blogs to have better blogs like I’ve explained in this article.

I really made a change in the way I think about writing articles and coding. I like coding and writing but I really have to separate these two things.

The only problem was that I really wanted to move all my blog articles of all my blog sites to medium. So I’ve created two publications, 40enfit and PurePython and started building a script to move my articles from the Jekyll sites.

Automated tools

If you don’t care to much about how your articles will show and you don’t have to many articles you can always use online convert tools like

It is by far the easiest way to publish a Markdown post to Medium with syntax highlighted code snippets.

But! You can only do one article at the time, it converts any code block to gists code blocks and you don’t have any way of changing the outcome of your article on Medium as edit them one by one on Medium.

So if that doesn’t work for you my python script is here to help.

Medium Token

Before you start using my script you need to send an email to medium to ask them to activate the Medium Integration part in your settings.

Medium offers an integration token for use with third-party applications, like your python script. Click the link to contact them.

When you got the Medium token you are ready to import all of your Jekyll posts in Medium. You can import them in two ways, as draft or as published article.

You can even import them as a story underneath your profile or underneath publications.

Some elements won’t work

I have to warn you! Some Markdown elements won’t work in Medium.

Like tables, Medium does not have an table option and tables will really look like crap!

| Names | Birthdates |
|: — |: — |
| Theo | 15 may 1975 |
| Johnson | 10 Februari 2007 |
| Jack | 30 April 2010 |

Yup…. looks like……shit.

Tables in Markdown are setup as the example above. In Jekyll it will show like this:

Jekyll tables look really good

Adding classes als won’t work. In Jekyll / Markdown you can add classes to like tables and other elements by using {: .my-class } like text.

In Markdown you can’t! If you have many of these elements in you Jekyll site you might want to add some extra my `sanitize_content_data` function.

def sanitize_content_data(self, file_data=None):
if file_data is None:
raise ValueError("No file_data")

# replaces html double quote
file_data = file_data.replace("“", "'")
file_data = file_data.replace("”", "'")

# remove the More tag
file_data = re.sub(self.more_tag, "", file_data, 0, re.MULTILINE | re.DOTALL)
replace the gist jekyll code with js file
gist_subst = "<script src=\"{}/\\1.js\"></script>".format(self.git_username)
file_data = re.sub(self.gist_tag, gist_subst, file_data, 0, re.MULTILINE | re.DOTALL)
return file_data
except ValueError as e:
return False

Install these pip libraries and Medium restrictions

So you need to install some pip libs to get this going.

pip install requests
pip install PyYAML

And you are all set to go!

But wait! If you have a lot of Markdown files… you cannot import them in one go. You can only import like 8 items per day.

Unfortunately you can not set publish dates, so you cannot import in draft and auto-publish them. It’s a restriction in the API of medium.

Some final Medium Markdown Python ingredients

So before you start up this little script there are some things you need and a few things you have to fill in.

First of all you need Python 3.4 or higher!

You need to install the libraries in the previous chapter.

And you need the medium token.

Then you need two folders where this script is on your hard drive. A md folder for where the Markdown files are and an backup folder for where the markdown files go when it is put on medium

Then there is the need for your github username to connect to your gists.

With print(imd.publications_response you can find out what publications you have and if you want to publish your Markdown files in a publication fill it ini the `publication_id` part

Then there is a publish status where you have to fill in“public”, “draft”, or “unlisted”

The general-tag is needed when there is only one tag provided within the Markdown files, the medium API breaks when you only have one tag.

Tags are used where no tags are provided at all.

You can provide a license for all your work in md_license, calid values are “all-rights-reserved”, “cc-40-by”, “cc-40-by-sa”, “cc-40-by-nd”, “cc-40-by-nc”, “cc-40-by-nc-nd”, “cc-40-by-nc-sa”, “cc-40-zero”, “public-domain”.
The default is “all-rights-reserved”.

Blog_url is the domain of your current jekyll blog.

csv_file is this file is created and usable to create like .htaccess url redirects

run = 8 is the number of files you process per run. You don’t want to run more as 9 [0–8] a day! Medium does not like that.

  token = ""  # Your Medium token
md_folder = "mds" # folder where your md files are
backup_folder = "backup" # folder where the md's are put when send to medium
git_username = "" # your github username

publication_id = "" #your publication ID
publishStatus = "public" # “public”, “draft”, or “unlisted” general_tag = "tag1"
tags = ["tag2", "tag3", "tag5"] # then no tags are there
md_license = 'cc-40-by-nc' blog_url = "" # domain of your current jekyll blog csv_file = "a-file-name.txt"
# this file is usable to create like .htaccess url redirects
run = 8 # you dont want to run more as 9 [0-8] a day! Medium does not like that.

Final Jekyll Markdown to Medium import code


Scribbles of code in Python. A new Medium publication about Python coding and other Tech.

Theo van der Sluijs

Written by

Nerd Herder ☆ Scrum Master ☆ Disruptor ☆ Python Lover (Code & Efteling) ☆ Dad ☆ Husband ☆ Zookeeper ☆ CycloCross biker ☆ Blogger ☆ Dutch


Scribbles of code in Python. A new Medium publication about Python coding and other Tech.

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade