wp-parsedown.php (view raw)
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 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
<?php
/*
Plugin Name: WP-Parsedown
Plugin URI: https://github.com/petermolnar/wp-parsedown
Description: [Parsedown Extra](www.parsedown.org/demo?extra=1) on-the-fly
Version: 0.3
Author: Peter Molnar <hello@petermolnar.eu>
Author URI: https://petermolnar.eu/
License: GPLv3
*/
if ( ! class_exists( 'WP_PARSEDOWN' ) ) :
include_once ( dirname(__FILE__) . '/lib/parsedown/Parsedown.php');
include_once ( dirname(__FILE__) . '/lib/parsedown-extra/ParsedownExtra.php');
/**
* main wp-ghost class
*/
class WP_PARSEDOWN {
public function __construct () {
add_action( 'init', array(&$this,'init'));
}
public function init () {
remove_filter( 'the_content', 'wpautop' );
remove_filter( 'the_excerpt', 'wpautop' );
add_filter( 'the_content', array( &$this, 'parsedown'), 8, 1 );
}
public function parsedown ( $markdown ) {
$post = get_post();
if ( defined( 'WP_DEBUG' ) && WP_DEBUG == true ) {
$message = sprintf ( __('parsing post: %s', $this->plugin_constant), $post->ID );
error_log( __CLASS__ . ": " . $message );
}
$parsedown = new ParsedownExtra();
$parsedown->setBreaksEnabled(true);
return $parsedown->text ( $markdown );
}
}
$wp_parsedown = new WP_PARSEDOWN ();
endif;
|