Skip to content

Instantly share code, notes, and snippets.

@julp
Created August 2, 2012 12:50
Show Gist options
  • Save julp/3236803 to your computer and use it in GitHub Desktop.
Save julp/3236803 to your computer and use it in GitHub Desktop.
PHP: parsing Markdown with sundown extension and geshi for syntax highlighting
<?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