<?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>
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.