From 128de3aa970f03adb6e623d172859b13f06bab6c Mon Sep 17 00:00:00 2001 From: Michel Fortin Date: Tue, 14 Aug 2007 16:43:12 -0400 Subject: [PATCH] PHP Markdown Extra 1.1.2 --- License.text | 2 +- PHP Markdown Extra Readme.text | 46 ++++++++++++++-- markdown.php | 97 ++++++++++++++++++---------------- 3 files changed, 96 insertions(+), 49 deletions(-) diff --git a/License.text b/License.text index 85f6d15..3f0c1b1 100644 --- a/License.text +++ b/License.text @@ -1,5 +1,5 @@ PHP Markdown & Extra -Copyright (c) 2004-2006 Michel Fortin +Copyright (c) 2004-2007 Michel Fortin All rights reserved. diff --git a/PHP Markdown Extra Readme.text b/PHP Markdown Extra Readme.text index a9a1dd7..bb2779b 100644 --- a/PHP Markdown Extra Readme.text +++ b/PHP Markdown Extra Readme.text @@ -1,7 +1,7 @@ PHP Markdown Extra ================== -Version 1.1.1 - Thu 28 Dec 2006 +Version 1.1.2 - Wed 7 Feb 2007 by Michel Fortin @@ -155,7 +155,7 @@ perform the conversion to HTML. You can update PHP Markdown -- or replace it with PHP Markdown Extra -- in many of these programs by swapping the old "markdown.php" file for the new one. -Here is a short non-exaustive list of some programs and where they +Here is a short non-exhaustive list of some programs and where they hide the "markdown.php" file. | Program | Path to Markdown @@ -207,6 +207,46 @@ expected; (3) the output PHP Markdown actually produced. Version History --------------- +Extra 1.1.2 (7 Feb 2007) + +* Fixed an issue where headers preceded too closely by a paragraph + (with no blank line separating them) where put inside the paragraph. + +* Added the missing TextileRestricted method that was added to regular + PHP Markdown since 1.0.1d but which I forgot to add to Extra. + + +1.0.1f (7 Feb 2007): + +* Fixed an issue with WordPress where manually-entered excerpts, but + not the auto-generated ones, would contain nested paragraphs. + +* Fixed an issue introduced in 1.0.1d where headers and blockquotes + preceded too closely by a paragraph (not separated by a blank line) + where incorrectly put inside the paragraph. + +* Fixed an issue introduced in 1.0.1d in the tokenizeHTML method where + two consecutive code spans would be merged into one when together they + form a valid tag in a multiline paragraph. + +* Fixed an long-prevailing issue where blank lines in code blocks would + be doubled when the code block is in a list item. + + This was due to the list processing functions relying on artificially + doubled blank lines to correctly determine when list items should + contain block-level content. The list item processing model was thus + changed to avoid the need for double blank lines. + +* Fixed an issue with `<% asp-style %>` instructions used as inline + content where the opening `<` was encoded as `<`. + +* Fixed a parse error occuring when PHP is configured to accept + ASP-style delimiters as boundaries for PHP scripts. + +* Fixed a bug introduced in 1.0.1d where underscores in automatic links + got swapped with emphasis tags. + + Extra 1.1.1 (28 Dec 2006) * Fixed a problem where whitespace at the end of the line of an atx-style @@ -409,7 +449,7 @@ Extra 1.0b2 - 26 July 2005 * Added the pipe character to the backlash escape character lists. -1.0b1 (25 Jun 2005) +Extra 1.0b1 (25 Jun 2005) * First public release of PHP Markdown Extra. diff --git a/markdown.php b/markdown.php index f22bdd3..0c2cfed 100644 --- a/markdown.php +++ b/markdown.php @@ -3,7 +3,7 @@ # Markdown Extra - A text-to-HTML conversion tool for web writers # # PHP Markdown & Extra -# Copyright (c) 2004-2006 Michel Fortin +# Copyright (c) 2004-2007 Michel Fortin # # # Original Markdown @@ -12,8 +12,8 @@ # -define( 'MARKDOWN_VERSION', "1.0.1e" ); # Thu 28 Dec 2006 -define( 'MARKDOWNEXTRA_VERSION', "1.1.1" ); # Thu 28 Dec 2006 +define( 'MARKDOWN_VERSION', "1.0.1f" ); # Wed 7 Feb 2007 +define( 'MARKDOWNEXTRA_VERSION', "1.1.2" ); # Wed 7 Feb 2007 # @@ -71,7 +71,7 @@ function Markdown($text) { Plugin Name: Markdown Extra Plugin URI: http://www.michelf.com/projects/php-markdown/ Description: Markdown syntax allows you to write using an easy-to-read, easy-to-write plain text format. Based on the original Perl version by John Gruber. More... -Version: 1.1.1 +Version: 1.1.2 Author: Michel Fortin Author URI: http://www.michelf.com/ */ @@ -125,12 +125,14 @@ if (isset($wp_version)) { } function mdwp_add_p($text) { - if (strlen($text) == 0) return; - if (strcasecmp(substr($text, -3), '

') == 0) return $text; - return '

'.$text.'

'; + if (!preg_match('{^$|^<(p|ul|ol|dl|pre|blockquote)>}i', $text)) { + $text = '

'.$text.'

'; + $text = preg_replace('{\n{2,}}', "

\n\n

", $text); + } + return $text; } - function mdwp_strip_p($t) { return preg_replace('{}', '', $t); } + function mdwp_strip_p($t) { return preg_replace('{}i', '', $t); } function mdwp_hide_tags($text) { global $markdown_hidden_tags; @@ -182,6 +184,10 @@ if (strcasecmp(substr(__FILE__, -16), "classTextile.php") == 0) { if (function_exists('SmartyPants')) $text = SmartyPants($text); return $text; } + # Fake restricted version: restrictions are not supported for now. + function TextileRestricted($text, $lite='', $noimage='') { + return $this->TextileThis($text, $lite); + } # Workaround to ensure compatibility with TextPattern 4.0.3. function blockLite($text) { return $text; } } @@ -465,7 +471,7 @@ class Markdown_Parser { array(&$this, '_hashHTMLBlocks_callback'), $text); - # PHP and ASP-style processor instructions () + # PHP and ASP-style processor instructions (hashBlock("

".$this->runSpanGamut($matches[1])."

")."\n\n"; + $block = "

".$this->runSpanGamut($matches[1])."

"; + return "\n" . $this->hashBlock($block) . "\n\n"; } function _doHeaders_callback_setext_h2($matches) { - return $this->hashBlock("

".$this->runSpanGamut($matches[1])."

")."\n\n"; + $block = "

".$this->runSpanGamut($matches[1])."

"; + return "\n" . $this->hashBlock($block) . "\n\n"; } function _doHeaders_callback_atx($matches) { $level = strlen($matches[1]); - return $this->hashBlock("".$this->runSpanGamut($matches[2])."")."\n\n"; + $block = "".$this->runSpanGamut($matches[2]).""; + return "\n" . $this->hashBlock($block) . "\n\n"; } @@ -978,9 +987,7 @@ class Markdown_Parser { $marker_any = ( $list_type == "ul" ? $marker_ul : $marker_ol ); - # Turn double returns into triple returns, so that we can make a - # paragraph for the last item in a list, if necessary: - $list = preg_replace("/\n{2,}/", "\n\n\n", $list); + $list .= "\n"; $result = $this->processListItems($list, $marker_any); $result = $this->hashBlock("<$list_type>\n" . $result . ""); @@ -1024,8 +1031,8 @@ class Markdown_Parser { (\n)? # leading line = $1 (^[ \t]*) # leading whitespace = $2 ('.$marker_any.') [ \t]+ # list marker = $3 - ((?s:.+?) # list item text = $4 - (\n{1,2})) + ((?s:.+?)) # list item text = $4 + (?:(\n+(?=\n))|\n) # tailing blank line = $5 (?= \n* (\z | \2 ('.$marker_any.') [ \t]+)) }xm', array(&$this, '_processListItems_callback'), $list_str); @@ -1037,9 +1044,12 @@ class Markdown_Parser { $item = $matches[4]; $leading_line =& $matches[1]; $leading_space =& $matches[2]; + $tailing_blank_line =& $matches[5]; - if ($leading_line || preg_match('/\n{2,}/', $item)) { - $item = $this->runBlockGamut($this->outdent($item)); + if ($leading_line || $tailing_blank_line || + preg_match('/\n{2,}/', $item)) + { + $item = $this->runBlockGamut($this->outdent($item)."\n"); } else { # Recursion for sub-lists: @@ -1221,7 +1231,7 @@ class Markdown_Parser { $bq = preg_replace_callback('{(\s*
.+?
)}sx', array(&$this, '_DoBlockQuotes_callback2'), $bq); - return $this->hashBlock("
\n$bq\n
")."\n\n"; + return "\n". $this->hashBlock("
\n$bq\n
")."\n\n"; } function _doBlockQuotes_callback2($matches) { $pre = $matches[1]; @@ -1312,7 +1322,7 @@ class Markdown_Parser { '&', $text);; # Encode naked <'s - $text = preg_replace('{<(?![a-z/?\$!])}i', '<', $text); + $text = preg_replace('{<(?![a-z/?\$!%])}i', '<', $text); return $text; } @@ -1331,8 +1341,8 @@ class Markdown_Parser { function doAutoLinks($text) { - $text = preg_replace('{<((https?|ftp|dict):[^\'">\s]+)>}', - '\1', $text); + $text = preg_replace_callback('{<((https?|ftp|dict):[^\'">\s]+)>}', + array(&$this, '_doAutoLinks_url_callback'), $text); # Email addresses: $text = preg_replace_callback('{ @@ -1345,15 +1355,20 @@ class Markdown_Parser { ) > }xi', - array(&$this, '_doAutoLinks_callback'), $text); + array(&$this, '_doAutoLinks_email_callback'), $text); return $text; } - function _doAutoLinks_callback($matches) { + function _doAutoLinks_url_callback($matches) { + $url = $this->encodeAmpsAndAngles($matches[1]); + $link = "$url"; + return $this->hashSpan($link); + } + function _doAutoLinks_email_callback($matches) { $address = $matches[1]; $address = $this->unescapeSpecialChars($address); - $address = $this->encodeEmailAddress($address); - return $this->hashSpan($address); + $link = $this->encodeEmailAddress($address); + return $this->hashSpan($link); } @@ -1461,7 +1476,7 @@ class Markdown_Parser { $str = $parts[2]; # Skip the whole code span, pass as text token. - if (preg_match('/^(.*(?_doHeaders_attr($id =& $matches[2]); $block = "".$this->runSpanGamut($matches[1]).""; - return $this->hashBlock($block) . "\n\n"; + return "\n" . $this->hashBlock($block) . "\n\n"; } function _doHeaders_callback_setext_h2($matches) { $attr = $this->_doHeaders_attr($id =& $matches[2]); $block = "".$this->runSpanGamut($matches[1]).""; - return $this->hashBlock($block) . "\n\n"; + return "\n" . $this->hashBlock($block) . "\n\n"; } function _doHeaders_callback_atx($matches) { $level = strlen($matches[1]); $attr = $this->_doHeaders_attr($id =& $matches[3]); $block = "".$this->runSpanGamut($matches[2]).""; - return $this->hashBlock($block) . "\n\n"; + return "\n" . $this->hashBlock($block) . "\n\n"; } @@ -2671,7 +2686,9 @@ Version History See Readme file for details. -Extra 1.1.1 (21 Dec 2006) +Extra 1.1.2 (7 Feb 2007) + +Extra 1.1.1 (28 Dec 2006) Extra 1.1 (1 Dec 2006) @@ -2680,21 +2697,11 @@ Extra 1.0.1 (9 Dec 2005) Extra 1.0 (5 Sep 2005) -Author & Contributors ---------------------- - -Original Markdown by John Gruber - - -PHP port and extras by Michel Fortin - - - Copyright and License --------------------- PHP Markdown & Extra -Copyright (c) 2004-2006 Michel Fortin +Copyright (c) 2004-2007 Michel Fortin All rights reserved.