PHP code example of nessworthy / parsedown-extension-manager

1. Go to this page and download the library: Download nessworthy/parsedown-extension-manager 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/ */

    

nessworthy / parsedown-extension-manager example snippets




use \Nessworthy\ParsedownExtensionManager\Parsedown;

/**
 * This is an implementation of the "Add Inline Element"  example in the parsedown docs.
 * @see https://github.com/erusev/parsedown/wiki/Tutorial:-Create-Extensions#add-inline-element
 */
class ExampleInlineExtension implements \Nessworthy\ParsedownExtensionManager\ParsedownInlineExtension
{
    public function getStartingCharacter(): string
    {
        return '{';
    }
    
    public function run(array $excerpt): ?array
    {
        if (preg_match('/^{c:([#\w]\w+)}(.*?){\/c}/', $excerpt['text'], $matches)) {
            return [
                'extent' => strlen($matches[0]), 
                'element' => [
                    'name' => 'span',
                    'text' => $matches[2],
                    'attributes' => [
                        'style' => 'color: ' . $matches[1],
                    ],
                ],

            ];
        }
        
        return null;
    }
}




// Create your Parsedown instance.
$parsedown = new \Nessworthy\ParsedownExtensionManager\Parsedown();

// Register your Parsedown extensions.
$parsedown->registerInlineExtension(new ExampleInlineExtension());

// Use Parsedown as you normally would!
$parsedown->parse('Hello {c:#FF00000}world{/c}!');
// "<p>Hello <span style="color: #FF0000">world!</span></p>