* Website: https://gist.github.com/jbroadway/2836900
* License: MIT
*/
class Slimdown {
public static $rules = array (
'/(? '\1', // links
'/(\*\*|__)(.*?)\1/' => '\2', // bold
'/(\*|_)(.*?)\1/' => '\2', // emphasis
'/\~\~(.*?)\~\~/' => '\1', // del
'/\:\"(.*?)\"\:/' => '\1
', // quote
'/`(.*?)`/' => '\1
', // inline code
'/(?:!\[([^\[]+)\]\(([^\)]+)\))/' => '',
'/==(.*?)==/' => '\1',
);
/**
* Add a rule.
*/
public static function add_rule ($regex, $replacement) {
self::$rules[$regex] = $replacement;
}
/**
* Render some Markdown into HTML.
*/
public static function render ($text) {
$text = "\n" . $text . "\n";
foreach (self::$rules as $regex => $replacement) {
if (is_callable ( $replacement)) {
$text = preg_replace_callback ($regex, $replacement, $text);
} else {
$text = preg_replace ($regex, $replacement, $text);
}
}
return trim ($text);
}
}