Skip to content

Commit

Permalink
switch to rmccue's readme parser
Browse files Browse the repository at this point in the history
fixed rmccue's parser to recognize markdownified readme
  • Loading branch information
afragen committed Jul 14, 2016
1 parent 4fc1632 commit e102dcb
Show file tree
Hide file tree
Showing 4 changed files with 388 additions and 51 deletions.
10 changes: 5 additions & 5 deletions github-updater.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
}

if ( ! class_exists( 'WPUpdatePhp' ) ) {
require_once ( plugin_dir_path( __FILE__ ) . '/vendor/wp-update-php/src/WPUpdatePhp.php' );
require_once( plugin_dir_path( __FILE__ ) . '/vendor/wp-update-php/src/WPUpdatePhp.php' );
}
$updatePhp = new WPUpdatePhp( '5.3.0' );
if ( method_exists( $updatePhp, 'set_plugin_name' ) ) {
Expand All @@ -52,10 +52,10 @@

// Add extra classes
$extra_classes = array(
'Parsedown' => __DIR__ . '/vendor/parsedown/Parsedown.php',
'WPUpdatePHP' => __DIR__ . '/vendor/wp-update-php/src/WPUpdatePhp.php',
'Automattic_Readme' => __DIR__ . '/vendor/parse-readme.php',
);
'Parsedown' => __DIR__ . '/vendor/parsedown/Parsedown.php',
'WPUpdatePHP' => __DIR__ . '/vendor/wp-update-php/src/WPUpdatePhp.php',
'Baikonur_ReadmeParser' => __DIR__ . '/vendor/ReadmeParser.php',
);

// Load Autoloader
require_once( __DIR__ . '/src/GitHub_Updater/Autoloader.php' );
Expand Down
4 changes: 2 additions & 2 deletions src/GitHub_Updater/Base.php
Original file line number Diff line number Diff line change
Expand Up @@ -911,8 +911,8 @@ protected function set_readme_info( $response ) {
unset( $response['sections']['screenshots'] );
unset( $response['sections']['installation'] );
$this->type->sections = array_merge( (array) $this->type->sections, (array) $response['sections'] );
$this->type->tested = $response['tested_up_to'];
$this->type->requires = $response['requires_at_least'];
$this->type->tested = $response['tested'];
$this->type->requires = $response['requires'];
$this->type->donate_link = $response['donate_link'];
$this->type->contributors = $response['contributors'];

Expand Down
55 changes: 11 additions & 44 deletions src/GitHub_Updater/Readme_Parser.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
*
* @package Fragen\GitHub_Updater
*/
class Readme_Parser extends \Automattic_Readme {
class Readme_Parser extends \Baikonur_ReadmeParser {

/**
* Constructor
Expand All @@ -35,55 +35,22 @@ public function __construct() {
*
* @return array
*/
public function parse_readme( $file_contents ) {
return (array) $this->parse_readme_contents( $file_contents );
public static function parse_readme( $file_contents ) {
return (array) parent::parse_readme_contents( $file_contents );
}

/**
* @param $text
* @param bool $markdown
* @param $text
*
* @return mixed|string
* @return string
*/
public function filter_text( $text, $markdown = false ) { // fancy, Markdown
$text = trim( $text );
$text = call_user_func( array(
get_parent_class( $this ),
'code_trick',
), $text, $markdown ); // A better parser than Markdown's for: backticks -> CODE
protected static function parse_markdown( $text ) {
$parser = new \Parsedown();
$text = parent::code_trick( $text );
$text = preg_replace( '/^[\s]*=[\s]+(.+?)[\s]+=/m', "\n" . '<h4>$1</h4>' . "\n", $text );
$text = $parser->text( trim( $text ) );

if ( $markdown ) { // Parse markdown.
$parser = new \Parsedown;
$text = $parser->text( $text );
}

$allowed = array(
'a' => array(
'href' => array(),
'title' => array(),
'rel' => array(),
),
'blockquote' => array( 'cite' => array() ),
'br' => array(),
'cite' => array(),
'p' => array(),
'code' => array(),
'pre' => array(),
'em' => array(),
'strong' => array(),
'ul' => array(),
'ol' => array(),
'li' => array(),
'h3' => array(),
'h4' => array(),
);

$text = balanceTags( $text );

$text = wp_kses( $text, $allowed );
$text = trim( $text );

return $text;
return trim( $text );
}

}
Loading

0 comments on commit e102dcb

Please sign in to comment.