| 1 | Index: readme/class-parser.php |
|---|
| 2 | =================================================================== |
|---|
| 3 | --- readme/class-parser.php (revision 7290) |
|---|
| 4 | +++ readme/class-parser.php (working copy) |
|---|
| 5 | @@ -619,44 +619,57 @@ class Parser { |
|---|
| 6 | $trimmed_lines = array_map( 'trim', $lines ); |
|---|
| 7 | |
|---|
| 8 | /* |
|---|
| 9 | * The heading style being matched in the block. Can be 'heading' or 'bold'. |
|---|
| 10 | * Standard Markdown headings (## .. and == ... ==) are used, but if none are present. |
|---|
| 11 | * full line bolding will be used as a heading style. |
|---|
| 12 | */ |
|---|
| 13 | $heading_style = 'bold'; // 'heading' or 'bold' |
|---|
| 14 | foreach ( $trimmed_lines as $trimmed ) { |
|---|
| 15 | if ( $trimmed && ( $trimmed[0] == '#' || $trimmed[0] == '=' ) ) { |
|---|
| 16 | $heading_style = 'heading'; |
|---|
| 17 | break; |
|---|
| 18 | } |
|---|
| 19 | } |
|---|
| 20 | |
|---|
| 21 | + $in_code_block = false; |
|---|
| 22 | $line_count = count( $lines ); |
|---|
| 23 | for ( $i = 0; $i < $line_count; $i++ ) { |
|---|
| 24 | $line = &$lines[ $i ]; |
|---|
| 25 | $trimmed = &$trimmed_lines[ $i ]; |
|---|
| 26 | if ( ! $trimmed ) { |
|---|
| 27 | $value .= "\n"; |
|---|
| 28 | continue; |
|---|
| 29 | } |
|---|
| 30 | |
|---|
| 31 | + if ( ! $in_code_block && '`' == $trimmed[0] && strlen( $trimmed ) > 1 && '`' != substr( $trimmed, -1 ) ) { |
|---|
| 32 | + // Line started with ` and doesn't end with `, so we're entering a code block |
|---|
| 33 | + $in_code_block = true; |
|---|
| 34 | + } elseif ( $in_code_block && ( '`' == $trimmed[0] || '`' == substr( $trimmed, -1 ) ) ) { |
|---|
| 35 | + // In a code block, and either the line starts with `, or ends with it, which indiates end of block. |
|---|
| 36 | + $in_code_block = false; |
|---|
| 37 | + } |
|---|
| 38 | + |
|---|
| 39 | $is_heading = false; |
|---|
| 40 | - if ( 'heading' == $heading_style && ( $trimmed[0] == '#' || $trimmed[0] == '=' ) ) { |
|---|
| 41 | - $is_heading = true; |
|---|
| 42 | - } elseif ( 'bold' == $heading_style && ( substr( $trimmed, 0, 2 ) == '**' && substr( $trimmed, -2 ) == '**' ) ) { |
|---|
| 43 | - $is_heading = true; |
|---|
| 44 | + if ( ! $in_code_block ) { |
|---|
| 45 | + if ( 'heading' == $heading_style && ( $trimmed[0] == '#' || $trimmed[0] == '=' ) ) { |
|---|
| 46 | + $is_heading = true; |
|---|
| 47 | + } elseif ( 'bold' == $heading_style && ( substr( $trimmed, 0, 2 ) == '**' && substr( $trimmed, -2 ) == '**' ) ) { |
|---|
| 48 | + $is_heading = true; |
|---|
| 49 | + } |
|---|
| 50 | } |
|---|
| 51 | |
|---|
| 52 | if ( $is_heading ) { |
|---|
| 53 | if ( $value ) { |
|---|
| 54 | $return[ $key ] = trim( $value ); |
|---|
| 55 | } |
|---|
| 56 | |
|---|
| 57 | $value = ''; |
|---|
| 58 | // Trim off the first character of the line, as we know that's the heading style we're expecting to remove. |
|---|
| 59 | $key = trim( $line, $trimmed[0] . " \t" ); |
|---|
| 60 | continue; |
|---|
| 61 | } |
|---|
| 62 | |
|---|
| 63 | $value .= $line . "\n"; |
|---|
| 64 | } |
|---|
| 65 | Index: class-markdown.php |
|---|
| 66 | =================================================================== |
|---|
| 67 | --- class-markdown.php (revision 7290) |
|---|
| 68 | +++ class-markdown.php (working copy) |
|---|
| 69 | @@ -1,20 +1,20 @@ |
|---|
| 70 | <?php |
|---|
| 71 | namespace WordPressdotorg\Plugin_Directory; |
|---|
| 72 | |
|---|
| 73 | if ( ! class_exists( '\Michelf\MarkdownExtra' ) ) { |
|---|
| 74 | - include __DIR__ . '/libs/michelf-php-markdown-1.6.0/Michelf/MarkdownExtra.inc.php'; |
|---|
| 75 | + include __DIR__ . '/libs/michelf-php-markdown-1.8.0/Michelf/MarkdownExtra.inc.php'; |
|---|
| 76 | } |
|---|
| 77 | |
|---|
| 78 | /** |
|---|
| 79 | * WordPress.org Plugin Readme Parser Markdown. |
|---|
| 80 | * |
|---|
| 81 | * Relies on \Michaelf\Markdown_Extra |
|---|
| 82 | * |
|---|
| 83 | * @package WordPressdotorg\Plugin_Directory |
|---|
| 84 | */ |
|---|
| 85 | class Markdown extends \Michelf\MarkdownExtra { |
|---|
| 86 | |
|---|
| 87 | /** |
|---|
| 88 | * @param string $text |
|---|
| 89 | * @return string |
|---|
| 90 | */ |
|---|
| 91 | @@ -45,32 +45,35 @@ class Markdown extends \Michelf\Markdown |
|---|
| 92 | $text = str_replace( array( "\r\n", "\r" ), "\n", $text ); |
|---|
| 93 | |
|---|
| 94 | // Markdown can do inline code, we convert bbPress style block level code to Markdown style. |
|---|
| 95 | $text = preg_replace_callback( "!(^|\n)([ \t]*?)`(.*?)`!s", array( $this, 'code_trick_indent_cb' ), $text ); |
|---|
| 96 | |
|---|
| 97 | return $text; |
|---|
| 98 | } |
|---|
| 99 | |
|---|
| 100 | /** |
|---|
| 101 | * @access protected |
|---|
| 102 | * |
|---|
| 103 | * @param array $matches |
|---|
| 104 | * @return string |
|---|
| 105 | */ |
|---|
| 106 | protected function code_trick_indent_cb( $matches ) { |
|---|
| 107 | + |
|---|
| 108 | $text = $matches[3]; |
|---|
| 109 | - $text = preg_replace( '|^|m', $matches[2] . ' ', $text ); |
|---|
| 110 | +// $text = preg_replace( '|^|m', $matches[2] . ' ', $text ); |
|---|
| 111 | +$text = $matches[2] . '<pre><code>' . esc_html( $text ) . '</code></pre>'; |
|---|
| 112 | +// var_dump([ __METHOD__, $matches, $matches[1] . $text ]); |
|---|
| 113 | |
|---|
| 114 | return $matches[1] . $text; |
|---|
| 115 | } |
|---|
| 116 | |
|---|
| 117 | /** |
|---|
| 118 | * @access protected |
|---|
| 119 | * |
|---|
| 120 | * @param array $matches |
|---|
| 121 | * @return string |
|---|
| 122 | */ |
|---|
| 123 | protected function code_trick_decodeit_cb( $matches ) { |
|---|
| 124 | $trans_table = array_flip( get_html_translation_table( HTML_ENTITIES ) ); |
|---|
| 125 | |
|---|
| 126 | $text = $matches[2]; |
|---|
| 127 | $text = strtr( $text, $trans_table ); |
|---|