1
0
mirror of https://github.com/erusev/parsedown.git synced 2023-08-10 21:13:06 +03:00

Merge pull request #600 from aidantwoods/fix/code-block-closer

Fix fenced code block closer length rules
This commit is contained in:
Aidan Woods 2018-04-05 18:46:49 +01:00 committed by GitHub
commit 96581dbe16
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 19 additions and 7 deletions

View File

@ -443,16 +443,16 @@ class Parsedown
protected function blockFencedCode($Line) protected function blockFencedCode($Line)
{ {
if (preg_match('/^['.$Line['text'][0].']{3,}[ ]*([^`]+)?[ ]*$/', $Line['text'], $matches)) if (preg_match('/^(['.$Line['text'][0].']{3,})[ ]*([^`]+)?[ ]*$/', $Line['text'], $matches))
{ {
$Element = array( $Element = array(
'name' => 'code', 'name' => 'code',
'text' => '', 'text' => '',
); );
if (isset($matches[1])) if (isset($matches[2]))
{ {
$class = 'language-'.$matches[1]; $class = 'language-'.$matches[2];
$Element['attributes'] = array( $Element['attributes'] = array(
'class' => $class, 'class' => $class,
@ -461,6 +461,7 @@ class Parsedown
$Block = array( $Block = array(
'char' => $Line['text'][0], 'char' => $Line['text'][0],
'openerLength' => mb_strlen($matches[1]),
'element' => array( 'element' => array(
'name' => 'pre', 'name' => 'pre',
'element' => $Element, 'element' => $Element,
@ -485,8 +486,10 @@ class Parsedown
unset($Block['interrupted']); unset($Block['interrupted']);
} }
if (preg_match('/^'.$Block['char'].'{3,}[ ]*$/', $Line['text'])) if (
{ preg_match('/^(['.preg_quote($Block['char']).']{3,})[ ]*$/', $Line['text'], $matches)
and mb_strlen($matches[1]) >= $Block['openerLength']
) {
$Block['element']['element']['text'] = substr($Block['element']['element']['text'], 1); $Block['element']['element']['text'] = substr($Block['element']['element']['text'], 1);
$Block['complete'] = true; $Block['complete'] = true;

View File

@ -9,3 +9,6 @@ echo $message;</code></pre>
echo "Hello World"; echo "Hello World";
?&gt; ?&gt;
&lt;a href="http://auraphp.com" &gt;Aura Project&lt;/a&gt;</code></pre> &lt;a href="http://auraphp.com" &gt;Aura Project&lt;/a&gt;</code></pre>
<pre><code>the following isn't quite enough to close
```
still a fenced code block</code></pre>

View File

@ -23,3 +23,9 @@ echo "Hello World";
?> ?>
<a href="http://auraphp.com" >Aura Project</a> <a href="http://auraphp.com" >Aura Project</a>
``` ```
````
the following isn't quite enough to close
```
still a fenced code block
````