From b16addc663d7ec76c85eb3097c65b933b221fa49 Mon Sep 17 00:00:00 2001 From: Florian Dorn Date: Thu, 12 Sep 2013 17:16:10 +0200 Subject: [PATCH 1/6] added support for the tel: url-scheme --- markdown.php | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/markdown.php b/markdown.php index 17e5152..e387b1e 100644 --- a/markdown.php +++ b/markdown.php @@ -1447,9 +1447,16 @@ class Markdown_Parser { > }xi', array(&$this, '_doAutoLinks_email_callback'), $text); + $text = preg_replace_callback('{<(tel:([^\'">\s]+))>}i',array(&$this, '_doAutoLinks_tel_callback'), $text); return $text; } + function _doAutoLinks_tel_callback($matches) { + $url = $this->encodeAttribute($matches[1]); + $tel = $this->encodeAttribute($matches[2]); + $link = "$tel"; + return $this->hashPart($link); + } function _doAutoLinks_url_callback($matches) { $url = $this->encodeAttribute($matches[1]); $link = "$url"; @@ -1740,4 +1747,4 @@ negligence or otherwise) arising in any way out of the use of this software, even if advised of the possibility of such damage. */ -?> \ No newline at end of file +?> From b2c76a3804a33d3d277c8d3be380b231d08239fb Mon Sep 17 00:00:00 2001 From: Jason Caldwell Date: Mon, 23 Sep 2013 03:59:54 -0700 Subject: [PATCH 2/6] GFM Enhancements (Backticks) - Adding support for GFM backticks ``` (for fenced code blocks); in additional to ~~~ already supported in Markdown Extra. - Adding support for GFM language marker; e.g. ```php Conflicts: markdown.php --- markdown.php | 37 +++++++++++++++++++++++++------------ 1 file changed, 25 insertions(+), 12 deletions(-) diff --git a/markdown.php b/markdown.php index 93efb8c..a4ccbb3 100644 --- a/markdown.php +++ b/markdown.php @@ -2010,7 +2010,8 @@ class MarkdownExtra_Parser extends Markdown_Parser { | # Fenced code block marker (?<= ^ | \n ) - [ ]{0,'.($indent+3).'}~{3,} + [ ]{0,'.($indent+3).'}[`~]{3,} + [A-Za-z0-9_\-]* # Language (optional). [ ]* (?: \.?[-_:a-zA-Z0-9]+ # standalone class name @@ -2082,7 +2083,7 @@ class MarkdownExtra_Parser extends Markdown_Parser { # # Check for: Fenced code block marker. # - else if (preg_match('{^\n?([ ]{0,'.($indent+3).'})(~+)}', $tag, $capture)) { + else if (preg_match('{^\n?([ ]{0,'.($indent+3).'})([`~]+)}', $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 @@ -2912,6 +2913,10 @@ class MarkdownExtra_Parser extends Markdown_Parser { # ~~~ # Code block # ~~~ + # + # ``` + # Code block + # ``` # $less_than_tab = $this->tab_width; @@ -2919,17 +2924,21 @@ class MarkdownExtra_Parser extends Markdown_Parser { (?:\n|\A) # 1: Opening marker ( - ~{3,} # Marker: three tilde or more. + [`~]{3,} # 3 or more backticks/tildes. + ) + # 2: Code language marker (optional). + ( + [A-Za-z0-9_\-]* # Word chars and/or `-`. ) [ ]* (?: - \.?([-_:a-zA-Z0-9]+) # 2: standalone class name + \.?([-_:a-zA-Z0-9]+) # 3: Stand-alone class name. | - '.$this->id_class_attr_catch_re.' # 3: Extra attributes + '.$this->id_class_attr_catch_re.' # 4: Extra attributes. )? [ ]* \n # Whitespace and newline following marker. - # 4: Content + # 5: Content ( (?> (?!\1 [ ]* \n) # Not a closing marker. @@ -2945,19 +2954,23 @@ class MarkdownExtra_Parser extends Markdown_Parser { return $text; } function _doFencedCodeBlocks_callback($matches) { - $classname =& $matches[2]; - $attrs =& $matches[3]; - $codeblock = $matches[4]; + $language = $matches[2]; + $classname = $matches[3]; + $attrs = $matches[4]; + $codeblock = $matches[5]; $codeblock = htmlspecialchars($codeblock, ENT_NOQUOTES); $codeblock = preg_replace_callback('/^\n+/', array(&$this, '_doFencedCodeBlocks_newlines'), $codeblock); + + $attr_str = ''; # Initialize string of attributes. + if($language != '') $attr_str .= ' lang="'.$language.'"'; if ($classname != "") { if ($classname{0} == '.') $classname = substr($classname, 1); - $attr_str = ' class="'.$this->code_class_prefix.$classname.'"'; + $attr_str .= ' class="'.$this->code_class_prefix.$classname.'"'; } else { - $attr_str = $this->doExtraAttributes($this->code_attr_on_pre ? "pre" : "code", $attrs); + $attr_str .= $this->doExtraAttributes($this->code_attr_on_pre ? "pre" : "code", $attrs); } $pre_attr_str = $this->code_attr_on_pre ? $attr_str : ''; $code_attr_str = $this->code_attr_on_pre ? '' : $attr_str; @@ -3331,4 +3344,4 @@ negligence or otherwise) arising in any way out of the use of this software, even if advised of the possibility of such damage. */ -?> \ No newline at end of file +?> From db9ef53240ac8742b816440d2e9a3450b351da0a Mon Sep 17 00:00:00 2001 From: Jason Caldwell Date: Mon, 30 Sep 2013 22:58:34 -0700 Subject: [PATCH 3/6] Improving GFM-Style Fenced Code Blocks; and Updating to `data-lang=""`. --- markdown.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/markdown.php b/markdown.php index a4ccbb3..e025626 100644 --- a/markdown.php +++ b/markdown.php @@ -2010,7 +2010,7 @@ class MarkdownExtra_Parser extends Markdown_Parser { | # Fenced code block marker (?<= ^ | \n ) - [ ]{0,'.($indent+3).'}[`~]{3,} + [ ]{0,'.($indent+3).'}(?:~{3,}|`{3,}) [A-Za-z0-9_\-]* # Language (optional). [ ]* (?: @@ -2083,7 +2083,7 @@ class MarkdownExtra_Parser extends Markdown_Parser { # # Check for: Fenced code block marker. # - else if (preg_match('{^\n?([ ]{0,'.($indent+3).'})([`~]+)}', $tag, $capture)) { + else if (preg_match('{^\n?([ ]{0,'.($indent+3).'})(~+|`+)}', $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 @@ -2924,7 +2924,7 @@ class MarkdownExtra_Parser extends Markdown_Parser { (?:\n|\A) # 1: Opening marker ( - [`~]{3,} # 3 or more backticks/tildes. + (?:~{3,}|`{3,}) # 3 or more tildes/backticks. ) # 2: Code language marker (optional). ( @@ -2963,7 +2963,7 @@ class MarkdownExtra_Parser extends Markdown_Parser { array(&$this, '_doFencedCodeBlocks_newlines'), $codeblock); $attr_str = ''; # Initialize string of attributes. - if($language != '') $attr_str .= ' lang="'.$language.'"'; + if($language != '') $attr_str .= ' data-lang="'.$language.'"'; if ($classname != "") { if ($classname{0} == '.') From 85ead87f4a7f7f3e8d6b4b0a9edda6ff41e0c0e3 Mon Sep 17 00:00:00 2001 From: Jason Caldwell Date: Sun, 13 Oct 2013 00:14:12 -0700 Subject: [PATCH 4/6] GFM-Style Fenced Code Blocks Only (no lang attribute) Removing the additional code that I applied previously to implement the `data-lang` attribute. In retrospect, this was a bad idea; as the existing implementation does a good job with this already when used properly. Many thanks to Michel Fortin for his help in accomplishing these changes :-) I hope this might be merged into the official copy at some point in the future. Conflicts: markdown.php --- markdown.php | 29 ++++++++--------------------- 1 file changed, 8 insertions(+), 21 deletions(-) diff --git a/markdown.php b/markdown.php index e025626..69c89b2 100644 --- a/markdown.php +++ b/markdown.php @@ -2011,7 +2011,6 @@ class MarkdownExtra_Parser extends Markdown_Parser { # Fenced code block marker (?<= ^ | \n ) [ ]{0,'.($indent+3).'}(?:~{3,}|`{3,}) - [A-Za-z0-9_\-]* # Language (optional). [ ]* (?: \.?[-_:a-zA-Z0-9]+ # standalone class name @@ -2913,10 +2912,6 @@ class MarkdownExtra_Parser extends Markdown_Parser { # ~~~ # Code block # ~~~ - # - # ``` - # Code block - # ``` # $less_than_tab = $this->tab_width; @@ -2926,19 +2921,15 @@ class MarkdownExtra_Parser extends Markdown_Parser { ( (?:~{3,}|`{3,}) # 3 or more tildes/backticks. ) - # 2: Code language marker (optional). - ( - [A-Za-z0-9_\-]* # Word chars and/or `-`. - ) [ ]* (?: - \.?([-_:a-zA-Z0-9]+) # 3: Stand-alone class name. + \.?([-_:a-zA-Z0-9]+) # 2: standalone class name | - '.$this->id_class_attr_catch_re.' # 4: Extra attributes. + '.$this->id_class_attr_catch_re.' # 3: Extra attributes )? [ ]* \n # Whitespace and newline following marker. - # 5: Content + # 4: Content ( (?> (?!\1 [ ]* \n) # Not a closing marker. @@ -2954,23 +2945,19 @@ class MarkdownExtra_Parser extends Markdown_Parser { return $text; } function _doFencedCodeBlocks_callback($matches) { - $language = $matches[2]; - $classname = $matches[3]; - $attrs = $matches[4]; - $codeblock = $matches[5]; + $classname =& $matches[2]; + $attrs =& $matches[3]; + $codeblock = $matches[4]; $codeblock = htmlspecialchars($codeblock, ENT_NOQUOTES); $codeblock = preg_replace_callback('/^\n+/', array(&$this, '_doFencedCodeBlocks_newlines'), $codeblock); - - $attr_str = ''; # Initialize string of attributes. - if($language != '') $attr_str .= ' data-lang="'.$language.'"'; if ($classname != "") { if ($classname{0} == '.') $classname = substr($classname, 1); - $attr_str .= ' class="'.$this->code_class_prefix.$classname.'"'; + $attr_str = ' class="'.$this->code_class_prefix.$classname.'"'; } else { - $attr_str .= $this->doExtraAttributes($this->code_attr_on_pre ? "pre" : "code", $attrs); + $attr_str = $this->doExtraAttributes($this->code_attr_on_pre ? "pre" : "code", $attrs); } $pre_attr_str = $this->code_attr_on_pre ? $attr_str : ''; $code_attr_str = $this->code_attr_on_pre ? '' : $attr_str; From 79fd7728f2851224528f1708f0651ec72f0a2b4d Mon Sep 17 00:00:00 2001 From: Michel Fortin Date: Thu, 28 Nov 2013 16:10:03 -0500 Subject: [PATCH 5/6] 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). --- markdown.php | 54 +++++++++++++++++++++++++++++----------------------- 1 file changed, 30 insertions(+), 24 deletions(-) diff --git a/markdown.php b/markdown.php index 69c89b2..2141e39 100644 --- a/markdown.php +++ b/markdown.php @@ -1996,9 +1996,6 @@ class MarkdownExtra_Parser extends Markdown_Parser { <\?.*?\?> | <%.*?%> # Processing instruction | # CData Block - | - # Code span marker - `+ '. ( !$span ? ' # If not in span. | # Indented code block @@ -2018,8 +2015,14 @@ class MarkdownExtra_Parser extends Markdown_Parser { '.$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'; @@ -2061,28 +2064,12 @@ class MarkdownExtra_Parser extends Markdown_Parser { $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 @@ -2107,6 +2094,25 @@ class MarkdownExtra_Parser extends Markdown_Parser { $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))*?(? Date: Thu, 28 Nov 2013 21:16:12 -0500 Subject: [PATCH 6/6] Updated version history. --- PHP Markdown Extra Readme.text | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/PHP Markdown Extra Readme.text b/PHP Markdown Extra Readme.text index 1e8c811..1f104d5 100644 --- a/PHP Markdown Extra Readme.text +++ b/PHP Markdown Extra Readme.text @@ -195,6 +195,19 @@ See Installation and Requirement above for details. Version History --------------- +Current Extra: + +* Added backtick fenced code blocks, originally from Github-flavored Markdown. + +* Added support for the `tel:` URL scheme in automatic links. + + + + is converted to: + + +1-111-111-1111 + + Extra 1.2.7 (11 Apr 2013): * Added optional class and id attributes to images and links using the same