pip install wp2md
wp2md
is a simple command line tool.
!wp2md -h
Example 1: Public Posts
To convert a wordpress post to markdown, simply point wp2md
at the url for the post:
!wp2md "https://outerbounds.com/blog/notebooks-in-production-with-metaflow/"
The generated markdown looks like this:
!cat notebooks-in-production-with-metaflow.md | head -n30
Example 2: Hidden Posts & Downloading Images
A Wordpress post may note be public (i.e. it might have a status other than published
). In that case, you will need two pieces of information to retrieve the markdown content for that post.
The url for the api. This is
<your_site>/wp-json/v2/posts
, for examplehttps://outerbounds.com/wp-json/wp/v2/posts
. Note: This is the api route to retrieve a single WP post.The
post id
you wish to convert to markdown. The post id can be extracted from wordpress edit url, for example the id forhttps://outerbounds.com/wp-admin/post.php?post=220&action=edit
is220
.
For example, we can get the contents of a post which has an id of 220
as follows:
! wp2md 220
By default, wp2md
downloads images locally into a folder named _<name_of_markdown_file>_data/
.
!ls _notebooks-in-production-with-metaflow_data/
You can prevent this by passing the --no_download
flag:
!rm notebooks-in-production-with-metaflow.md
!rm -rf _notebooks-in-production-with-metaflow_data/
! wp2md 220 --no_download
assert not Path('_notebooks-in-production-with-metaflow_data/').exists()