PHP code example of trianity / mparser

1. Go to this page and download the library: Download trianity/mparser library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

trianity / mparser example snippets




use Trianity\Mparser\Content;
use Trianity\Mparser\ContentParser;

$raw = <<<'MARKDOWN'
---
title: Content Title
description: My Description
custom: custom
---
## Testing
MARKDOWN;

$content = new Content($raw);
$content->parse(new ContentParser(), true);

echo $content->readBodyHtml(); // <h2>Testing</h2>
echo $content->frontMatterGet('title'); // Content Title

$content->frontMatterHas('title');
$content->frontMatterGet('title', 'Default title');
$content->frontMatterSet('title', 'New title');
$content->getAsArray('tags');



use Trianity\Mparser\ContentParser;
use Trianity\Mparser\CustomTagParser;

final class CalloutTagParser implements CustomTagParser
{
    public function parse(string $tag_value): string
    {
        return '<aside>'.htmlspecialchars($tag_value, ENT_QUOTES, 'UTF-8').'</aside>';
    }
}

$parser = new ContentParser();
$parser->addCustomTagParser('callout', new CalloutTagParser());