diff --git a/Michelf/MarkdownExtra.php b/Michelf/MarkdownExtra.php index 267bf16d..e8a9c20d 100644 --- a/Michelf/MarkdownExtra.php +++ b/Michelf/MarkdownExtra.php @@ -34,6 +34,57 @@ class MarkdownExtra extends \Michelf\_MarkdownExtra_TmpImpl { # Temporarily, the implemenation is in the _MarkdownExtra_TmpImpl class. # See note above. + /** + * @param string $file + * + * @throws \InvalidArgumentException + * @return string + */ + public function transformFile( $file ) { + if(file_exists($file)) { + + return $this->transform(file_get_contents($file)); + + } + throw new \InvalidArgumentException("File {$file} does not exist"); + } + + /** + * @param array $matches + * + * @return string + */ + protected function _doBlockQuotes_callback($matches) { + $bq = $matches[1]; + + # trim one level of quoting - trim whitespace-only lines + $bq = preg_replace('/^[ ]*>[ ]?|^[ ]+$/m', '', $bq); + + $class = ""; + // check class + if(preg_match('/^\{([\.a-z\-\_\#\ ]+?)\}$/m', $bq, $bqm)) { + $class = $bqm[1]; + // remove first line + + $bq = implode("\n", array_slice(explode("\n", $bq), 1)); + } + + $bq = $this->runBlockGamut($bq); # recurse + + $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); + + if(!empty($class)) { + $attr = $this->doExtraAttributes('blockquote', $class); + return "\n". $this->hashBlock("\n$bq\n")."\n\n"; + } else { + return "\n". $this->hashBlock("\n$bq\n")."\n\n"; + } + } + }