<commit_before><?php
/*
	Plugin Name: Parsedown for WordPress
	Plugin URI: 
	Description: A drop-in Markdown plugin using Parsedown Extra.
	Author: <NAME>
	Author URI: http://robinadr.com/

	This plugin uses the Parsedown and Parsedown Extra libraries, which are distributed 
	under the MIT license by <NAME>. A full copy of the license is included in 
	Parsedown/license.txt.
*/

/*

This plugin is intended to be a 100% compatible drop-in replacement for PHP Markdown 
Extra by Michel Fortin. Thus, some portions, namely filter order and helper functions, 
are directly copied from his plugin. These portions are noted as such below. The 
following copyright notice applies to those portions:

PHP Markdown & Extra
Copyright (c) 2004-2013 <NAME>
<http://michelf.ca/>  
All rights reserved.

Based on Markdown  
Copyright (c) 2003-2006 <NAME>   
<http://daringfireball.net/>   
All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are
met:

*	Redistributions of source code must retain the above copyright notice,
	this list of conditions and the following disclaimer.

*	Redistributions in binary form must reproduce the above copyright
	notice, this list of conditions and the following disclaimer in the
	documentation and/or other materials provided with the distribution.

*	Neither the name "Markdown" nor the names of its contributors may
	be used to endorse or promote products derived from this software
	without specific prior written permission.

This software is provided by the copyright holders and contributors "as
is" and any express or implied warranties, including, but not limited
to, the implied warranties of merchantability and fitness for a
particular purpose are disclaimed. In no event shall the copyright owner
or contributors be liable for any direct, indirect, incidental, special,
exemplary, or consequential damages (including, but not limited to,
procurement of substitute goods or services; loss of use, data, or
profits; or business interruption) however caused and on any theory of
liability, whether in contract, strict liability, or tort (including
negligence or otherwise) arising in any way out of the use of this
software, even if advised of the possibility of such damage.

*/

require_once __FILE__ . '/Parsedown/Parsedown.php';
require_once __FILE__ . '/Parsedown/ParsedownExtra.php';

class Parsedown_WP extends ParsedownExtra
{
	private var $hidden_tags;
	private var $placeholders;

	public function __construct()
	{
		add_action( 'init', array( $this, 'init' ) );
	}

	public function init()
	{
		// These filters are taken directly from PHP Markdown Extra by <NAME>
		// to ensure it's a 100% drop-in solution.

		// Post filters
		remove_filter( 'the_content',		'wpautop' );
		remove_filter( 'the_content_rss',	'wpautop' );
		remove_filter( 'the_excerpt',		'wpautop' );

		add_filter( 'the_content', 			array( $this, 'pdwp_markdown' ), 6 );
		add_filter( 'the_content_rss', 		array( $this, 'pdwp_markdown' ), 6 );
		add_filter( 'get_the_excerpt', 		array( $this, 'pdwp_markdown' ), 6 );
		add_filter( 'get_the_excerpt', 		'trim', 7 );
		add_filter( 'the_excerpt', 			array( $this, 'pdwp_add_p' )  );
		add_filter( 'the_excerpt_rss', 		array( $this, 'pdwp_strip_p' )  );

		remove_filter( 'content_save_pre', 	'balanceTags', 50 );
		remove_filter( 'excerpt_save_pre', 	'balanceTags', 50 );
		add_filter( 'the_content', 			'balanceTags', 50 );
		add_filter( 'get_the_excerpt', 		'balanceTags', 9 );

		// Comment filters
		remove_filter( 'comment_text', 		'wpautop', 30 );
		remove_filter( 'comment_text', 		'make_clickable' );

		add_filter( 'pre_comment_content', 	array( $this, 'pdwp_markdown' ), 6 );
		add_filter( 'pre_comment_content', 	array( $this, 'pdwp_hide_tags' ), 8 );
		add_filter( 'pre_comment_content', 	array( $this, 'pdwp_show_tags' ), 12 );
		add_filter( 'get_comment_text', 	array( $this, 'pdwp_markdown' ), 6 );
		add_filter( 'get_comment_excerpt', 	array( $this, 'pdwp_markdown' ), 6 );
		add_filter( 'get_comment_excerpt', 	array( $this, 'pdwp_strip_p' ), 7 );

		// Taken from PHP Markdown Extra by <NAME>
		$this->hidden_tags = array(
			'<p>', '</p>', '<pre>', '</pre>', '<ol>', '</ol>', 
			'<ul>', '</ul>', '<li>', '</li>'
		);
		$this->hidden_tags = apply_filters( 'pdwp_hidden_tags', $this->hidden_tags );

		$this->placeholders = explode(' ', str_rot13(
			'pEj07ZbbBZ U1kqgh4w4p pre2zmeN6K QTi31t9pre ol0MP1jzJR ' .
			'ML5IjmbRol ulANi1NsGY J7zRLJqPul liA8ctl16T K9nhooUHli'
		) );
		$this->placeholders = apply_filters( 'pdwp_placeholders', $this->placeholders );
	}

	public function pdwp_markdown( $text )
	{
		return $this->text( $text );
	}

	// Taken directly from PHP Markdown Extra by <NAME>
	public function pdwp_add_p( $text )
	{
		if (!preg_match( '{^$|^<(p|ul|ol|dl|pre|blockquote)>}i', $text ) ) {
			$text = '<p>' . $text . '</p>';
			$text = preg_replace( '{\n{2,}}', "</p>\n\n<p>", $text );
		}
		return $text;
	}

	// Taken directly from PHP Markdown Extra by <NAME>
	public function pdwp_strip_p( $text )
	{
		return preg_replace( '{</?p>}i', '', $t );
	}

	// Taken from PHP Markdown Extra by <NAME>
	public function pdwp_hide_tags( $text )
	{
		return str_replace( self::$hidden_tags, self::$placeholders, $text );
	}

	// Taken from PHP Markdown Extra by <NAME>
	public function pdwp_show_tags( $text )
	{
		return str_replace( self::$placeholders, self::$hidden_tags, $text );
	}
}

$parsedown_wp = new Parsedown_WP();<commit_msg>Add some filters<commit_after><?php
/*
	Plugin Name: Parsedown for WordPress
	Plugin URI: http://robinadr.com/
	Description: A drop-in Markdown plugin using Parsedown Extra.
	Version: 1.0
	Author: <NAME>
	Author URI: http://robinadr.com/

	This plugin uses the Parsedown and Parsedown Extra libraries, which are distributed 
	under the MIT license by <NAME>. A full copy of the license is included in 
	Parsedown/license.txt.
*/

/*

This plugin is intended to be a 100% compatible drop-in replacement for PHP Markdown 
Extra by <NAME>. Thus, some portions, namely filter order and helper functions, 
are directly copied from his plugin. These portions are noted as such below. The 
following copyright notice applies to those portions:

PHP Markdown & Extra
Copyright (c) 2004-2013 <NAME>
<http://michelf.ca/>  
All rights reserved.

Based on Markdown  
Copyright (c) 2003-2006 <NAME>   
<http://daringfireball.net/>   
All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are
met:

*	Redistributions of source code must retain the above copyright notice,
	this list of conditions and the following disclaimer.

*	Redistributions in binary form must reproduce the above copyright
	notice, this list of conditions and the following disclaimer in the
	documentation and/or other materials provided with the distribution.

*	Neither the name "Markdown" nor the names of its contributors may
	be used to endorse or promote products derived from this software
	without specific prior written permission.

This software is provided by the copyright holders and contributors "as
is" and any express or implied warranties, including, but not limited
to, the implied warranties of merchantability and fitness for a
particular purpose are disclaimed. In no event shall the copyright owner
or contributors be liable for any direct, indirect, incidental, special,
exemplary, or consequential damages (including, but not limited to,
procurement of substitute goods or services; loss of use, data, or
profits; or business interruption) however caused and on any theory of
liability, whether in contract, strict liability, or tort (including
negligence or otherwise) arising in any way out of the use of this
software, even if advised of the possibility of such damage.

*/

require_once __FILE__ . '/Parsedown/Parsedown.php';
require_once __FILE__ . '/Parsedown/ParsedownExtra.php';

class Parsedown_WP extends ParsedownExtra
{
	private var $hidden_tags;
	private var $placeholders;

	public function __construct()
	{
		add_action( 'init', array( $this, 'init' ) );
	}

	public function init()
	{
		// These filters are taken directly from PHP Markdown Extra by M<NAME>
		// to ensure it's a 100% drop-in solution.

		// Post filters
		remove_filter( 'the_content',		'wpautop' );
		remove_filter( 'the_content_rss',	'wpautop' );
		remove_filter( 'the_excerpt',		'wpautop' );

		add_filter( 'the_content', 			array( $this, 'pdwp_markdown' ), 6 );
		add_filter( 'the_content_rss', 		array( $this, 'pdwp_markdown' ), 6 );
		add_filter( 'get_the_excerpt', 		array( $this, 'pdwp_markdown' ), 6 );
		add_filter( 'get_the_excerpt', 		'trim', 7 );
		add_filter( 'the_excerpt', 			array( $this, 'pdwp_add_p' )  );
		add_filter( 'the_excerpt_rss', 		array( $this, 'pdwp_strip_p' )  );

		remove_filter( 'content_save_pre', 	'balanceTags', 50 );
		remove_filter( 'excerpt_save_pre', 	'balanceTags', 50 );
		add_filter( 'the_content', 			'balanceTags', 50 );
		add_filter( 'get_the_excerpt', 		'balanceTags', 9 );

		// Comment filters
		remove_filter( 'comment_text', 		'wpautop', 30 );
		remove_filter( 'comment_text', 		'make_clickable' );

		add_filter( 'pre_comment_content', 	array( $this, 'pdwp_markdown' ), 6 );
		add_filter( 'pre_comment_content', 	array( $this, 'pdwp_hide_tags' ), 8 );
		add_filter( 'pre_comment_content', 	array( $this, 'pdwp_show_tags' ), 12 );
		add_filter( 'get_comment_text', 	array( $this, 'pdwp_markdown' ), 6 );
		add_filter( 'get_comment_excerpt', 	array( $this, 'pdwp_markdown' ), 6 );
		add_filter( 'get_comment_excerpt', 	array( $this, 'pdwp_strip_p' ), 7 );

		// Taken from PHP Markdown Extra by <NAME>
		$this->hidden_tags = array(
			'<p>', '</p>', '<pre>', '</pre>', '<ol>', '</ol>', 
			'<ul>', '</ul>', '<li>', '</li>'
		);
		$this->hidden_tags = apply_filters( 'pdwp_hidden_tags', $this->hidden_tags );

		$this->placeholders = explode(' ', str_rot13(
			'pEj07ZbbBZ U1kqgh4w4p pre2zmeN6K QTi31t9pre ol0MP1jzJR ' .
			'ML5IjmbRol ulANi1NsGY J7zRLJqPul liA8ctl16T K9nhooUHli'
		) );
		$this->placeholders = apply_filters( 'pdwp_placeholders', $this->placeholders );
	}

	public function pdwp_markdown( $text )
	{
		return apply_filters( 'pdwp_markdown', $this->text( $text ) );
	}

	// Taken from PHP Markdown Extra by <NAME>
	public function pdwp_add_p( $text )
	{
		$regex = apply_filters( 'pdwp_add_p_regex', '{^$|^<(p|ul|ol|dl|pre|blockquote)>}i' );

		if (!preg_match( $regex, $text ) ) {
			$text = '<p>' . $text . '</p>';
			$text = preg_replace( '{\n{2,}}', "</p>\n\n<p>", $text );
		}

		return apply_filters( 'pdwp_add_p', $text );
	}

	// Taken from PHP Markdown Extra by <NAME>
	public function pdwp_strip_p( $text )
	{
		return apply_filters( 'pdwp_strip_p', preg_replace( '{</?p>}i', '', $t ) );
	}

	// Taken from PHP Markdown Extra by <NAME>
	public function pdwp_hide_tags( $text )
	{
		return str_replace( self::$hidden_tags, self::$placeholders, $text );
	}

	// Taken from PHP Markdown Extra by <NAME>
	public function pdwp_show_tags( $text )
	{
		return str_replace( self::$placeholders, self::$hidden_tags, $text );
	}
}

$parsedown_wp = new Parsedown_WP();
{'fraction_non_alphanumeric': 0.12038437583414895, 'fraction_numerical': 0.01156686537948216, 'mean_word_length': 4.512506130456106, 'pattern_counts': {'":': 0, '<': 62, '<?xml version=': 0, '>': 74, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1151882', 'n_tokens_mistral': 4007, 'n_tokens_neox': 3714, 'n_words': 1217}