Skip to content

Instantly share code, notes, and snippets.

@n1k0
Created April 7, 2010 09:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save n1k0/358702 to your computer and use it in GitHub Desktop.
Save n1k0/358702 to your computer and use it in GitHub Desktop.
Mardown syntax rendering helper for the Symfony framework
<?php
require_once dirname(__FILE__).'/../vendor/php-markdown/markdown.php';
/**
* Markdown Symfony Helper, require PHP Markdown library: http://michelf.com/projects/php-markdown/
*
* The idea is to parse and render text written using the Markdown format directly from your
* Symfony templates.
*
* Sample usage:
*
* <?php set_markdown() ?>
* Heading
* =======
*
* Title 1
* -------
*
* Now let's there be [rock](http://en.wikipedia.org/wiki/Rock).
* <?php end_markdown() ?>
*
* The fun is coming now, it's already i18n ready:
*
* <?php set_markdown() ?>
* ### <?php echo __('This string will be first i18ned **then** markdown-parsed'); ?>
* <?php end_markdown() ?>
*
* Hint: Having the Mardown syntax rendered from the template on each request can be heavy; please
* consider caching your templates.
*/
/**
* Starts output buffering for Markdown content
*
*/
function set_markdown() {
ob_start();
ob_implicit_flush(0);
}
/**
* Renders buffered Markdown contents as HTML
*
* @return string
*/
function end_markdown()
{
echo Markdown(ob_get_clean());
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment