PHP code example of semmelsamu / commonmark-extensions

1. Go to this page and download the library: Download semmelsamu/commonmark-extensions 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/ */

    

semmelsamu / commonmark-extensions example snippets


use League\CommonMark\Environment\Environment;

// Create the converter environment:
$environment = new Environment($config);

// Add the extensions you wish:
$environment->addExtension(new CommonmarkExtension());

// Go forth and convert you some Markdown!
$converter = new MarkdownConverter($environment);

use Semmelsamu\CommonmarkExtensions\Callout\CalloutExtension;

$config = [
    "callout" => [
        "render_icon" => fn(string) => string;
    ],
    // other configuration ...
]

use Semmelsamu\CommonmarkExtensions\CodeHighlighting\CodeHighlightingExtension;

use Semmelsamu\CommonmarkExtensions\LaTex\LaTexExtension;

use Semmelsamu\CommonmarkExtensions\Wikilink\WikilinkExtension;

$config = [
    'wikilink' => [
        'resolve' => fn (string) => string
    ],
    [
    'slug_normalizer' => [
        'unique' => false,
    ]
]

use Semmelsamu\CommonmarkExtensions\WikilinkEmbed\WikilinkEmbedExtension;

$config = [
    'wikilink_embed' => [
        'resolve' => fn(string) => string
    ]
];

/**
 * Don't forget to also add this renderer to your environment:
 * `$environment->addRenderer(new WikilinkEmbedImageRenderer())`
 */
class WikilinkEmbedImageRenderer implements NodeRendererInterface
{
    public function render(Node $node, ChildNodeRendererInterface $childRenderer)
    {
        Embed::assertInstanceOf($node);

        if (!preg_match('/\.(jpg|jpeg|png|gif)$/i', $src)) {
            // Not an image, let this embed be handled by some other renderer
            return null;
        }

        $attributes = ['href' => $node->src];

        if ($node->caption) {
            $attributes['alt'] = $node->caption;
        }

        return new HtmlElement(
            'image',
            $attributes
        );
    }
}