wp-parsedown/wp-parsedown.php

51 lines
1.2 KiB
PHP
Raw Normal View History

2014-07-22 10:30:41 +01:00
<?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
2016-01-19 14:44:29 +00:00
Version: 0.5
2014-07-22 10:30:41 +01:00
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
*/
2015-05-05 12:05:08 +01:00
class WP_PARSEDOWN {
2014-07-22 10:30:41 +01:00
2015-05-05 12:05:08 +01:00
public function __construct () {
add_action( 'init', array(&$this,'init'));
2014-07-22 10:30:41 +01:00
}
2015-05-05 12:05:08 +01:00
public function init () {
2014-09-23 15:38:14 +01:00
remove_filter( 'the_content', 'wpautop' );
remove_filter( 'the_excerpt', 'wpautop' );
2015-05-05 12:05:08 +01:00
add_filter( 'the_content', array( &$this, 'parsedown'), 8, 1 );
2014-07-22 10:30:41 +01:00
}
2015-05-05 12:05:08 +01:00
public function parsedown ( $markdown ) {
$post = get_post();
2014-07-22 10:30:41 +01:00
2015-05-05 12:05:08 +01:00
if ( defined( 'WP_DEBUG' ) && WP_DEBUG == true ) {
2015-05-05 12:16:17 +01:00
$message = sprintf ( __('parsing post: %s'), $post->ID );
2015-05-05 12:05:08 +01:00
error_log( __CLASS__ . ": " . $message );
2014-07-22 10:30:41 +01:00
}
2015-05-05 12:05:08 +01:00
$parsedown = new ParsedownExtra();
$parsedown->setBreaksEnabled(true);
return $parsedown->text ( $markdown );
2014-07-22 10:30:41 +01:00
}
}
2015-05-05 12:05:08 +01:00
$wp_parsedown = new WP_PARSEDOWN ();
2014-07-22 10:30:41 +01:00
2015-05-05 12:05:08 +01:00
endif;