public
Last active

Support Markdown syntax in P2 posts and comments

  • Download Gist
functions.php
PHP
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
<?php
 
// http://michelf.com/projects/php-markdown/extra/
require_once( dirname(__FILE__) . '/markdown-extra/markdown-extra.php' );
 
/**
* Format posts/comments with Markdown at display time. Only process
* blocks starting with \^md\s+.
**/
function p2mis_comment_markdown( $text ) {
if( ! function_exists('Markdown') ) {
return $text;
}
 
if( preg_match( '/^\^md\s+/i', $text ) ) {
$text = preg_replace( '/^\^md\s+/i', '', $text );
$text = Markdown($text);
}
 
return $text;
}
add_filter( 'comment_text', 'p2mis_comment_markdown', 1 );
add_filter( 'the_content', 'p2mis_comment_markdown', 1 );
 
// Remove the P2 list processing, which converts lists to HTML on save
add_filter( 'p2_add_component_post-list-creator', '__return_false' );
add_filter( 'p2_add_component_comment-list-creator', '__return_false' );

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.