parsedown-extra
parsedown-extra copied to clipboard
Feature Request: Meta Data
MultiMark and Python-Markdown specify a way to include meta data such as author name, email, license and title. That is useful in html-output especially for thinks like this:
<html><head>
<title><?php echo isset($meta['title']); ?></title>
<meta charset="UTF-8">
<meta class="anchor" name="author" content="<?php echo $meta['author'];?>">
<meta class="anchor" name="date" content="<?php echo $meta['date']; ?>">
I have shoehorn meta data retrival like this:
$metare = '~^( ?[\-#=_\.])?[ ]{0,3}([A-Za-z0-9][A-Za-z0-9_-]*):\s*(.*?)$~';
$metamore = '~^( ?[\-#=_\.])?[ ]{4,}(.*?)$~';
$metastart = '~^[\-#=_/\.]{3,}(\s.*?)$~';
$meta = array(); // Will contain the meta data
$resttext = '';
$parsedown = new ParsedownExtra();
foreach ( $lines as $id => $line ) ) {
if( preg_match($metare, $line, $match) ) {
$key = strtolower( $match[2] );
$meta[$key] = $match[3];
unset($lines[$id]);
}
elseif( isset($key) && preg_match($metamore, $line, $match) ) {
$meta[$key] .= $match[2];
unset($lines[$id]);
}
else break;
}
// ...
$output = $parsedown->text($resttext);
However, I didn't take the time to look at the extension mechanism of Parsedown, so I suspect there is a better way.
:+1: