I love markdown, and I have the Wordpress markdown-for-wordpress-and-bbpress parsing markdown in my posts and comments.
However, I've noticed that Wordpress saves the comments rendered in html format. This makes it more difficult to go back and edit comments. How can I get wordpress to save comments in markdown format?
I couldn't find a plugin for it. Maybe there's an easy php hack?
Maybe it's not builtin to wordpress. Comments normally not saved with any markup without the markdown plugin. Could be a markdown-for-wordpress-and-bbpress "feature" / accident?
Cross-posted to wordpress.stackexchange.com. BAinternet had some good ideas of saving markup for comments like in the markup-on-save plugin, but no working solution yet.
may help? May be theme-dependent. Lists still get saved rendered sometimes.
In wp-content/plugins/markdown-for-wordpress-and-bbpress/markdown.php
comment out the pre_comment_content
markdown filter
if (MARKDOWN_WP_COMMENTS) {
remove_filter('comment_text', 'wpautop', 30);
remove_filter('comment_text', 'make_clickable');
#HACK don't save comments rendered in HTML
#add_filter('pre_comment_content', 'Markdown', 6);
add_filter('pre_comment_content', 'mdwp_hide_tags', 8);
add_filter('pre_comment_content', 'mdwp_show_tags', 12);
add_filter('get_comment_text', 'Markdown', 6);
add_filter('get_comment_excerpt', 'Markdown', 6);
add_filter('get_comment_excerpt', 'mdwp_strip_p', 7);
First thing you need to do is install and activate the WP-Markdown plugin. Upon activation, you need to visit Settings » Writing and scroll down to Markdown section. You can enable WP-Markdown for posts, pages, and custom post types. You can also enable Markdown support for comments.
Nice question. As this feature is not available in the Wordpress plugin, you'll need to do some hackery at least to stop it from saving in HTML format, which you have done.
Now you need for when the comments are displayed to process that markdown into HTML. So let's use the comment_text
hook:
<?php add_filter('comment_text', 'Markdown'); ?>
If you don't want your original code to feel like "hackery" -- turn it into a feature. Add a config option to the Markdown.php $save_format = 'html'
or $save_format = 'markdown'
then check if you want to execute the stripper function or not. In fact, you could be really smart and turn all of this into a function inside of Markdown.php (and remember to tell the author about your new feature, he might even update his original code ;)
function set_save_format($format) {
if ($format == 'markdown') {
// Ok we need to change the format of any comments output to html:
add_filter('comment_text', 'Markdown');
}
}
I guess u can use the http://adambrown.info/p/wp_hooks/hook/comment_save_pre-hook to manipulate the data.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With