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))*?(?