Created
August 2, 2012 12:50
-
-
Save julp/3236803 to your computer and use it in GitHub Desktop.
PHP: parsing Markdown with sundown extension and geshi for syntax highlighting
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
require_once(__DIR__ . '/geshi.php'); | |
class GeshiExtendedHTMLRender extends \Sundown\Render\HTML | |
{ | |
public function blockCode($code, $language) | |
{ | |
if (!$language) { | |
return '<pre><code>' . htmlspecialchars($code, NULL, 'UTF-8') . '</code></pre>'; | |
} | |
$geshi = new GeSHi($code, $language); | |
$geshi->set_language_path(__DIR__ . '/geshi/'); | |
$geshi->enable_classes(FALSE); // only for testing (avoid CSS) | |
return $geshi->parse_code(); | |
} | |
} | |
$md = new \Sundown\Markdown( | |
new GeshiExtendedHTMLRender, | |
array('autolink' => TRUE, 'fenced_code_blocks' => TRUE, 'filter_html' => TRUE, 'no_images' => TRUE) | |
); | |
$text = 'your text here'; # copy a README.md file from a random github repository for example | |
echo $md->render($text); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment