From 149e0dccc19b4b56dcd6f38d60686c22d50e0de4 Mon Sep 17 00:00:00 2001 From: Jason Caldwell Date: Mon, 30 Sep 2013 22:58:34 -0700 Subject: [PATCH] Improving GFM-Style Fenced Code Blocks; and Updating to `data-lang=""`. --- Michelf/Markdown.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Michelf/Markdown.php b/Michelf/Markdown.php index 6ef430c..bd5ff05 100644 --- a/Michelf/Markdown.php +++ b/Michelf/Markdown.php @@ -1846,7 +1846,7 @@ class _MarkdownExtra_TmpImpl extends \Michelf\Markdown { | # Fenced code block marker (?<= ^ | \n ) - [ ]{0,'.($indent+3).'}[`~]{3,} + [ ]{0,'.($indent+3).'}(?:~{3,}|`{3,}) [A-Za-z0-9_\-]* # Language (optional). [ ]* (?: @@ -1919,7 +1919,7 @@ class _MarkdownExtra_TmpImpl extends \Michelf\Markdown { # # 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 @@ -2772,7 +2772,7 @@ class _MarkdownExtra_TmpImpl extends \Michelf\Markdown { (?:\n|\A) # 1: Opening marker ( - [`~]{3,} # 3 or more backticks/tildes. + (?:~{3,}|`{3,}) # 3 or more tildes/backticks. ) # 2: Code language marker (optional). ( @@ -2811,7 +2811,7 @@ class _MarkdownExtra_TmpImpl extends \Michelf\Markdown { 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} == '.')