Fixed some issues with fenced code blocks.
HTML block parser was confusing backtick fenced code blocks with code spans, which has no consequence most of the time but could be problematic if you're writing code spans inside of the code block. Code span markers are now matched only when backtick fence matching has failed. Fixed an issue were two consecutive fenced code blocks with no blank line between them which was causing the next paragraph to become a code block (with both tilde and backtick fences).
This commit is contained in:
parent
05d1f999ec
commit
d6ed0d0803
1 changed files with 30 additions and 24 deletions
|
|
@ -1832,9 +1832,6 @@ class _MarkdownExtra_TmpImpl extends \Michelf\Markdown {
|
|||
<\?.*?\?> | <%.*?%> # Processing instruction
|
||||
|
|
||||
<!\[CDATA\[.*?\]\]> # CData Block
|
||||
|
|
||||
# Code span marker
|
||||
`+
|
||||
'. ( !$span ? ' # If not in span.
|
||||
|
|
||||
# Indented code block
|
||||
|
|
@ -1854,8 +1851,14 @@ class _MarkdownExtra_TmpImpl extends \Michelf\Markdown {
|
|||
'.$this->id_class_attr_nocatch_re.' # extra attributes
|
||||
)?
|
||||
[ ]*
|
||||
\n
|
||||
(?= \n )
|
||||
' : '' ). ' # End (if not is span).
|
||||
|
|
||||
# Code span marker
|
||||
# Note, this regex needs to go after backtick fenced
|
||||
# code blocks but it should also be kept outside of the
|
||||
# "if not in span" condition adding backticks to the parser
|
||||
`+
|
||||
)
|
||||
}xs';
|
||||
|
||||
|
|
@ -1897,28 +1900,12 @@ class _MarkdownExtra_TmpImpl extends \Michelf\Markdown {
|
|||
$text = $parts[2]; # Remaining text after current tag.
|
||||
$tag_re = preg_quote($tag); # For use in a regular expression.
|
||||
|
||||
#
|
||||
# Check for: Code span marker
|
||||
#
|
||||
if ($tag{0} == "`") {
|
||||
# Find corresponding end marker.
|
||||
$tag_re = preg_quote($tag);
|
||||
if (preg_match('{^(?>.+?|\n(?!\n))*?(?<!`)'.$tag_re.'(?!`)}',
|
||||
$text, $matches))
|
||||
{
|
||||
# End marker found: pass text unchanged until marker.
|
||||
$parsed .= $tag . $matches[0];
|
||||
$text = substr($text, strlen($matches[0]));
|
||||
}
|
||||
else {
|
||||
# Unmatched marker: just skip it.
|
||||
$parsed .= $tag;
|
||||
}
|
||||
}
|
||||
#
|
||||
# Check for: Fenced code block marker.
|
||||
# Note: need to recheck the whole tag to disambiguate backtick
|
||||
# fences from code spans
|
||||
#
|
||||
else if (preg_match('{^\n?([ ]{0,'.($indent+3).'})(~+|`+)}', $tag, $capture)) {
|
||||
if (preg_match('{^\n?([ ]{0,'.($indent+3).'})(~{3,}|`{3,})[ ]*(?:\.?[-_:a-zA-Z0-9]+|'.$this->id_class_attr_nocatch_re.')?[ ]*\n?$}', $tag, $capture)) {
|
||||
# Fenced code block marker: find matching end marker.
|
||||
$fence_indent = strlen($capture[1]); # use captured indent in re
|
||||
$fence_re = $capture[2]; # use captured fence in re
|
||||
|
|
@ -1943,6 +1930,25 @@ class _MarkdownExtra_TmpImpl extends \Michelf\Markdown {
|
|||
$parsed .= $tag;
|
||||
}
|
||||
#
|
||||
# Check for: Code span marker
|
||||
# Note: need to check this after backtick fenced code blocks
|
||||
#
|
||||
else if ($tag{0} == "`") {
|
||||
# Find corresponding end marker.
|
||||
$tag_re = preg_quote($tag);
|
||||
if (preg_match('{^(?>.+?|\n(?!\n))*?(?<!`)'.$tag_re.'(?!`)}',
|
||||
$text, $matches))
|
||||
{
|
||||
# End marker found: pass text unchanged until marker.
|
||||
$parsed .= $tag . $matches[0];
|
||||
$text = substr($text, strlen($matches[0]));
|
||||
}
|
||||
else {
|
||||
# Unmatched marker: just skip it.
|
||||
$parsed .= $tag;
|
||||
}
|
||||
}
|
||||
#
|
||||
# Check for: Opening Block level tag or
|
||||
# Opening Context Block tag (like ins and del)
|
||||
# used as a block tag (tag is alone on it's line).
|
||||
|
|
@ -2786,7 +2792,7 @@ class _MarkdownExtra_TmpImpl extends \Michelf\Markdown {
|
|||
)
|
||||
|
||||
# Closing marker.
|
||||
\1 [ ]* \n
|
||||
\1 [ ]* (?= \n )
|
||||
}xm',
|
||||
array(&$this, '_doFencedCodeBlocks_callback'), $text);
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue