From 26a3254acb83171c7747d6b52e06473a0d800fcf Mon Sep 17 00:00:00 2001 From: Jack Tonkin Date: Thu, 3 Jul 2014 01:39:06 +0100 Subject: [PATCH] Add blockquote footer syntax for citations. --- Michelf/Markdown.php | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/Michelf/Markdown.php b/Michelf/Markdown.php index 0d370127..8dc3c2d4 100644 --- a/Michelf/Markdown.php +++ b/Michelf/Markdown.php @@ -2508,6 +2508,33 @@ protected function _doHeaders_callback_atx($matches) { } + protected function _doBlockQuotes_callback($matches) { + $bq = $matches[1]; + # trim one level of quoting - trim whitespace-only lines + $bq = preg_replace('/^[ ]*>[ ]?|^[ ]+$/m', '', $bq); + + # If final line of blockquote starts with -- treat it as a footer. + $split = preg_split('/\n *--(.*)\n$/', $bq, 0 , PREG_SPLIT_NO_EMPTY | PREG_SPLIT_DELIM_CAPTURE); + $bq = $split[0]; + $footer = isset($split[1]) ? $split[1] : NULL; + + $bq = $this->runBlockGamut($bq); # recurse + + if (isset($footer)) { + $footer = $this->runSpanGamut($footer); + $bq .= "\n"; + } + + $bq = preg_replace('/^/m', " ", $bq); + # These leading spaces cause problem with
 content,
+		# so we need to fix that:
+		$bq = preg_replace_callback('{(\s*
.+?
)}sx', + array($this, '_doBlockQuotes_callback2'), $bq); + + return "\n". $this->hashBlock("
\n$bq\n
")."\n\n"; + } + + protected function doTables($text) { # # Form HTML tables.