@@ -1996,9 +1996,6 @@ function _hashHTMLBlocks_inMarkdown($text, $indent = 0,
1996
1996
<\?.*?\?> | <%.*?%> # Processing instruction
1997
1997
|
1998
1998
<!\[CDATA\[.*?\]\]> # CData Block
1999
- |
2000
- # Code span marker
2001
- `+
2002
1999
' . ( !$ span ? ' # If not in span.
2003
2000
|
2004
2001
# Indented code block
@@ -2018,8 +2015,14 @@ function _hashHTMLBlocks_inMarkdown($text, $indent = 0,
2018
2015
' .$ this ->id_class_attr_nocatch_re .' # extra attributes
2019
2016
)?
2020
2017
[ ]*
2021
- \n
2018
+ (?= \n )
2022
2019
' : '' ). ' # End (if not is span).
2020
+ |
2021
+ # Code span marker
2022
+ # Note, this regex needs to go after backtick fenced
2023
+ # code blocks but it should also be kept outside of the
2024
+ # "if not in span" condition adding backticks to the parser
2025
+ `+
2023
2026
)
2024
2027
}xs ' ;
2025
2028
@@ -2061,28 +2064,12 @@ function _hashHTMLBlocks_inMarkdown($text, $indent = 0,
2061
2064
$ text = $ parts [2 ]; # Remaining text after current tag.
2062
2065
$ tag_re = preg_quote ($ tag ); # For use in a regular expression.
2063
2066
2064
- #
2065
- # Check for: Code span marker
2066
- #
2067
- if ($ tag {0 } == "` ") {
2068
- # Find corresponding end marker.
2069
- $ tag_re = preg_quote( $ tag);
2070
- if (preg_match('{^(?>.+?| \n(?! \n))*?(?<!`)'. $ tag_re.'(?!`)}',
2071
- $ text, $ matches))
2072
- {
2073
- # End marker found: pass text unchanged until marker.
2074
- $ parsed .= $ tag . $ matches [0 ];
2075
- $ text = substr( $ text, strlen( $ matches [0 ]));
2076
- }
2077
- else {
2078
- # Unmatched marker: just skip it.
2079
- $ parsed .= $ tag;
2080
- }
2081
- }
2082
2067
#
2083
2068
# Check for: Fenced code block marker.
2069
+ # Note: need to recheck the whole tag to disambiguate backtick
2070
+ # fences from code spans
2084
2071
#
2085
- else if (preg_match('{^ \n?([ ]{0,'.( $ indent+3).'})(~+|`+) }', $ tag, $ capture)) {
2072
+ if (preg_match ('{^\n?([ ]{0, ' .($ indent +3 ).'})(~{3,}|`{3,})[ ]*(?:\.?[-_:a-zA-Z0-9]+| ' . $ this -> id_class_attr_nocatch_re . ' )?[ ]*\n?$ } ' , $ tag , $ capture )) {
2086
2073
# Fenced code block marker: find matching end marker.
2087
2074
$ fence_indent = strlen ($ capture [1 ]); # use captured indent in re
2088
2075
$ fence_re = $ capture [2 ]; # use captured fence in re
@@ -2107,6 +2094,25 @@ function _hashHTMLBlocks_inMarkdown($text, $indent = 0,
2107
2094
$ parsed .= $ tag;
2108
2095
}
2109
2096
#
2097
+ # Check for: Code span marker
2098
+ # Note: need to check this after backtick fenced code blocks
2099
+ #
2100
+ else if ( $ tag{0} == "`") {
2101
+ # Find corresponding end marker.
2102
+ $ tag_re = preg_quote( $ tag);
2103
+ if (preg_match('{^(?>.+?| \n(?! \n))*?(?<!`)'. $ tag_re.'(?!`)}',
2104
+ $ text, $ matches))
2105
+ {
2106
+ # End marker found: pass text unchanged until marker.
2107
+ $ parsed .= $ tag . $ matches [0 ];
2108
+ $ text = substr( $ text, strlen( $ matches [0 ]));
2109
+ }
2110
+ else {
2111
+ # Unmatched marker: just skip it.
2112
+ $ parsed .= $ tag;
2113
+ }
2114
+ }
2115
+ #
2110
2116
# Check for: Opening Block level tag or
2111
2117
# Opening Context Block tag (like ins and del)
2112
2118
# used as a block tag (tag is alone on it's line).
@@ -2938,7 +2944,7 @@ function doFencedCodeBlocks($text) {
2938
2944
)
2939
2945
2940
2946
# Closing marker.
2941
- \1 [ ]* \n
2947
+ \1 [ ]* (?= \n )
2942
2948
}xm ' ,
2943
2949
array (&$ this , '_doFencedCodeBlocks_callback ' ), $ text );
2944
2950
0 commit comments