Title: Meta Markdown Gist Author: Nick Kempinski Date: April, 6 2014
Once upon a time, there was Nick!
<?php | |
class MetaMarkdown extends Markdown { | |
protected function meta($txt) { | |
$pattern = '/^([A-Za-z]+)\:\s*\t*(.+)$/m'; | |
//$pattern = '/^(.*)\:(?\s*)(?\t*)(.+)(\r\n|\n)/'; | |
//echo $txt; | |
$txt = preg_replace_callback( | |
'/^([A-Za-z]+)\:\s*\t*(.+)$/m', | |
function($expr) { | |
F3::instance()->set('meta.'.strtolower($expr[1]),$expr[2]); | |
return ""; | |
}, | |
$txt | |
); | |
return $txt; | |
} | |
function convert($txt) { | |
$txt = $this->meta($txt); | |
$txt=preg_replace_callback( | |
'/(<code.*?>.+?<\/code>|'. | |
'<[^>\n]+>|\([^\n\)]+\)|"[^"\n]+")|'. | |
'\\\\(.)/s', | |
function($expr) { | |
// Process escaped characters | |
return empty($expr[1])?$expr[2]:$expr[1]; | |
}, | |
$this->build(preg_replace('/\r\n|\r/',"\n",$txt)) | |
); | |
return $this->snip($txt); | |
} | |
} | |
?> |
Title: Meta Markdown Gist Author: Nick Kempinski Date: April, 6 2014
Once upon a time, there was Nick!
<?php | |
$file = F3::instance()->read('my-markdown.md'); | |
# Old Markdown | |
$html = Markdown::instance()->convert($file); | |
# Look for 'meta' | |
var_dump(F3::instance()->get('meta')); | |
# = NULL | |
# New & Improved Markdown | |
$meta_html = MetaMarkdown::instance()->convert($file); | |
# $html == $meta_html | |
# but now with added 'meta' | |
var_dump(F3::instance()->get('meta')); | |
# = { ["title"]=> string(18) "Meta Markdown Gist" ["author"]=> string(14) "Nick Kempinski" ["date"]=> string(13) "April, 6 2014" } | |
?> |