From d6ed0d080336e4ca8123b74f0c0977eddcc04086 Mon Sep 17 00:00:00 2001 From: Michel Fortin Date: Thu, 28 Nov 2013 16:10:03 -0500 Subject: [PATCH] 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). --- Michelf/Markdown.php | 54 ++++++++++++++++++++++++-------------------- 1 file changed, 30 insertions(+), 24 deletions(-) diff --git a/Michelf/Markdown.php b/Michelf/Markdown.php index 49d9809..8d1a4b7 100644 --- a/Michelf/Markdown.php +++ b/Michelf/Markdown.php @@ -1832,9 +1832,6 @@ class _MarkdownExtra_TmpImpl extends \Michelf\Markdown { <\?.*?\?> | <%.*?%> # Processing instruction | # 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))*?(?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))*?(?