Wordpress with Markdown

Today I updated Wordpress which went smooth so I decided to fix a problem on my blog which appeared when I first migrated to Wordpress. I’m using the plugin Markdown for WordPress and bbPress so I can write posts with Markdown syntax and I use code sections heavily. The problem was that using special characters like: & “ ‘ within code paragraph would look like this:

& ” ‘ < >

For now I just reverts posts upon displaying so the html entities are replaced by special characters. I know this is not the right way but its temporary :)

I asked on the Wordpress IRC and a nice guy called ‘ansimation’ gave me this to work with:

function reconvert_pre_entities( $d ) {
     return preg_replace_callback('/<pre>(.*?)/sim', create_function('$matches', 'return( html_entity_decode($matches[0]) );'), $d );
}
add_action('the_content', 'reconvert_pre_entities' );

When I get a little time I’m going to incorporate this into the Markdown plugin so it wont affect any of the other blogs not using Markdown.

Wordpress with Markdown
© 2009 by Jacob Emcken is licensed under CC BY-SA 4.0 Creative Commons Logo Creative Commons Attribution icon Creative Commons Share Alike icon