Changeset 3180
- Timestamp:
- 05/19/2016 06:54:53 AM (8 years ago)
- Location:
- sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory
- Files:
-
- 1 added
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/class-readme-parser.php
r3163 r3180 1 1 <?php 2 2 namespace WordPressdotorg\Plugin_Directory; 3 use Michelf\MarkdownExtra;3 use WordPressdotorg\Plugin_Directory\Markdown; 4 4 5 5 /** … … 7 7 * 8 8 * Based on Baikonur_ReadmeParser from https://github.com/rmccue/WordPress-Readme-Parser 9 *10 * Relies on \Michaelf\Markdown_Extra11 9 * 12 10 * @package WordPressdotorg\Plugin_Directory … … 384 382 protected function parse_markdown( $text ) { 385 383 static $markdown = null; 386 if ( ! class_exists( '\\Michelf\\MarkdownExtra' ) ) {387 // TODO: Autoloader?388 include __DIR__ . '/libs/michelf-php-markdown-1.6.0/Michelf/MarkdownExtra.inc.php';389 }390 384 if ( is_null( $markdown ) ) { 391 $markdown = new MarkdownExtra(); 392 } 393 394 $text = $this->code_trick( $text ); 395 $text = preg_replace( '/^[\s]*=[\s]+(.+?)[\s]+=/m', "\n" . '<h4>$1</h4>' . "\n", $text ); 396 $text = $markdown->transform( trim( $text ) ); 397 398 return trim( $text ); 399 } 400 401 protected function code_trick( $text ) { 402 // If doing markdown, first take any user formatted code blocks and turn them into backticks so that 403 // markdown will preserve things like underscores in code blocks 404 $text = preg_replace_callback( "!(<pre><code>|<code>)(.*?)(</code></pre>|</code>)!s", array( $this, 'code_trick_decodeit_cb' ), $text ); 405 $text = str_replace( array( "\r\n", "\r" ), "\n", $text ); 406 407 // Markdown can do inline code, we convert bbPress style block level code to Markdown style 408 $text = preg_replace_callback( "!(^|\n)([ \t]*?)`(.*?)`!s", array( $this, 'code_trick_indent_cb' ), $text ); 409 410 return $text; 411 } 412 413 protected function code_trick_indent_cb( $matches ) { 414 $text = $matches[3]; 415 $text = preg_replace( '|^|m', $matches[2] . ' ', $text ); 416 417 return $matches[1] . $text; 418 } 419 420 protected function code_trick_decodeit_cb( $matches ) { 421 $text = $matches[2]; 422 $trans_table = array_flip( get_html_translation_table( HTML_ENTITIES ) ); 423 $text = strtr( $text, $trans_table ); 424 $text = str_replace( '<br />', '', $text ); 425 $text = str_replace( '&', '&', $text ); 426 $text = str_replace( ''', "'", $text ); 427 428 if ( '<pre><code>' == $matches[1] ) { 429 $text = "\n$text\n"; 430 } 431 432 return "`$text`"; 433 } 385 $markdown = new Markdown(); 386 } 387 388 return $markdown->transform( $text ); 389 } 390 434 391 }
Note: See TracChangeset
for help on using the changeset viewer.