Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 51 additions & 0 deletions Michelf/MarkdownExtra.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 <pre> content,
# so we need to fix that:
$bq = preg_replace_callback('{(\s*<pre>.+?</pre>)}sx',
array(&$this, '_doBlockQuotes_callback2'), $bq);

if(!empty($class)) {
$attr = $this->doExtraAttributes('blockquote', $class);
return "\n". $this->hashBlock("<blockquote{$attr}>\n$bq\n</blockquote>")."\n\n";
} else {
return "\n". $this->hashBlock("<blockquote>\n$bq\n</blockquote>")."\n\n";
}
}

}


Expand Down