Created
March 25, 2013 13:11
-
-
Save ikkez/5236999 to your computer and use it in GitHub Desktop.
markdown Template Extension for F3
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
\Template::instance()->extend('markdown', '\ViewHelper::renderMarkdown'); | |
$f3->route('GET /test', function($f3) { | |
$f3->set('str','## foo'); | |
$f3->set('mdFile','path/to/readme.md'); | |
echo \Template::instance()->render('test.html'); | |
}); |
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
<markdown> | |
## headlines are cool | |
</markdown> | |
<markdown>{{@str}}</markdown> | |
<markdown src="{{@mdFile}}"></markdown> | |
<markdown> | |
**basepath** is: {{@BASE}} | |
</markdown> | |
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
class ViewHelper { | |
static function renderMarkdown($args) | |
{ | |
$tmp = \Template::instance(); | |
$md_string = (isset($args[0])) ? '"'.addslashes($tmp->token($args[0])).'"' : ''; | |
if (array_key_exists('@attrib', $args)) { | |
$attr = $args['@attrib']; | |
foreach ($attr as &$att) { | |
if (is_int(strpos($att, '@'))) | |
$att = $tmp->token($att); | |
else | |
$att = "'".$att."'"; | |
} | |
if (array_key_exists('src', $attr)) | |
$md_string = 'file_exists('.$attr['src'].') ? \Base::instance()->read('.$attr['src'].') : ""'; | |
} | |
$md = '<?php '. | |
'$md_content='.$md_string.'; '. | |
'echo \Markdown::instance()->convert($md_content);'. | |
' ?>'; | |
return $md; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment