Created
April 7, 2010 09:40
-
-
Save n1k0/358702 to your computer and use it in GitHub Desktop.
Mardown syntax rendering helper for the Symfony framework
This file contains hidden or 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 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