Skip to content

Instantly share code, notes, and snippets.

@abackstrom
Created January 4, 2012 17:10
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save abackstrom/1561020 to your computer and use it in GitHub Desktop.
Save abackstrom/1561020 to your computer and use it in GitHub Desktop.
Support Markdown syntax in P2 posts and comments
<?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' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment