Skip to content

Instantly share code, notes, and snippets.

@oelna
Created March 30, 2014 15:29
Show Gist options
  • Save oelna/9874443 to your computer and use it in GitHub Desktop.
Save oelna/9874443 to your computer and use it in GitHub Desktop.
A Parsedown wrapper to act as a drop-in replacement for PHP Markdown
<?php
/* makes the 'Markdown" function and the 'Markdown_Parser' class available to your scripts */
require( 'parsedown.php' );
@define( 'MARKDOWN_PARSER_CLASS', 'Markdown_Parser' );
@define( 'NEWLINE_TO_BREAK', true );
function Markdown($text) {
static $parser;
if (!isset($parser)) {
$parser_class = MARKDOWN_PARSER_CLASS;
$parser = new $parser_class;
}
return $parser->transform($text);
}
class Markdown_Parser extends Parsedown {
function transform($text) {
if(NEWLINE_TO_BREAK) self::set_breaks_enabled(true);
return self::parse($text);
}
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment