parsedown-extra icon indicating copy to clipboard operation
parsedown-extra copied to clipboard

Feature Request: Meta Data

Open con-f-use opened this issue 8 years ago • 1 comments

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.

con-f-use avatar Mar 24 '16 23:03 con-f-use

:+1:

qwertygc avatar Apr 01 '16 13:04 qwertygc