I’m in the process of migrating my blog from Drupal to WordPress. I have made liberal use of Markdown in the original posts (and Geshi syntax highlighting).
In see that the WP-Markdown plugin converts to (and from HTML) on save (and edit), so I now have a bunch of posts which appear with the Markdown ‘on show’.
Is there an API call which I can use to effectively do an ‘edit and save’ operation on each post to force the Markdown on Save plugin to operate on them all?
Or alternatively, a different Markdown plugin I should try?
Note: The following is largely untested (It worked after testing on one post).
As you’ve pointed out when you edit a post, the plug-in takes the content in the database (HTML) and converts that to MarkDown for editing. Since in your case the content is actually not in HTML, but already in MarkDown, we want to stop this happening. Then by updating the post, the plug-in should convert the MarkDown to HTML.
This should be fairly easy to do since this parsing is just hooked onto some filters, you simply remove the appropriate callbacks to prevent the plug-in from doing anything. (Then again, given the class structure of the plug-in, maybe its not quite so easy). Given that, you may just wish to manually edit the plug-in files to remove the filters.
The filters in question are added here.
Removing those (manually or otherwise) and then updating each of the posts should work. But that could take a while, so lets go for an automated solution…
You should test this script with one of your posts first to check that it works before running for the rest.
The script can be added to the very bottom of the
wp-markdown.php
file orfunctions.php
. Remove again after use. To trigger the script just append?markdown=correct
to an admin url.If you manually remove the filters before running this script, make sure you replace them again.
The easiest way to migrate a Markdown database from another CMS to WordPress would just be to install Robin Adrianse’s Parsedown for WordPress. In this case, there’s no need to convert anything. Your posts are ready to go as you originally wrote them, including Markdown footnotes if you used them (Parsedown for WordPress includes the very useful Markdown Extra extensions from Michel Fortrin, most of which made it to Github flavoured Markdown).
If you wish to use Markdown as your primary markup language in WordPress, it’s essential to enable Classic Editor to disable Gutenberg. I’d highly advise making to edit only in the plain text editor as it avoids wpautop line break parsing and radically improves performance (plain text text field). This combination works a treat for me on any WordPress from 4.9 to 5.8.
All posts are parsed as Markdown (HTML is still parsed as HTML is part of Markdown spec) but for comments it works fine. Either Markdown or HTML comments are supported, transparently. Nothing is permanently converted. Whatever you type in is converted to HTML on display. If you are using a caching plugin (pretty much obligatory with WordPress), there are no performance issues as the parsed Markdown is cached as HTML whenever the page is cached.
I specify Robin Adrianse’s version of Parsedown as there are several other versions which go too far, converting HTML to Markdown permanently. Parsedown for WordPress works fine with WordPress 5.8 and Classic Editor so ignore any version warnings. Robin Adrianse no longer uses WordPress so cannot be bothered keeping up with the never-ending version number changing (real hassle for developers who are mostly volunteers providing open source code).