PHP code example of mozex / commonmark-routes

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

    

mozex / commonmark-routes example snippets


use League\CommonMark\Environment\Environment;
use League\CommonMark\CommonMarkConverter;
use Mozex\CommonMarkRoutes\RoutesExtension;

$converter = new CommonMarkConverter($environment);
$converter->getEnvironment()->addExtension(new RoutesExtension());

echo $converter->convert("[Home](route('home'))");
// Output: <p><a href="https://domain.com">Home</a></p>

echo $converter->convert("[Home](<route('home')>)");
// Output: <p><a href="https://domain.com">Home</a></p>

echo $converter->convert("[route('home')](route('home'))");
// Output: <p><a href="https://domain.com">https://domain.com</a></p>

echo $converter->convert("[<route('home')>](<route('home')>)");
// Output: <p><a href="https://domain.com">https://domain.com</a></p>

echo $converter->convert("[Home](route('home', absolute: false))");
// Output: <p><a href="/">Home</a></p>

echo $converter->convert("[Product](route('product', 3))");
// Output: <p><a href="https://domain.com/product/3">Product</a></p>

echo $converter->convert("[Features](route('home', ['id' => 'features']))");
// Output: <p><a href="https://domain.com?id=features">Features</a></p>

echo $converter->convert("[Features](route('home', ['id' => 'features'], false))");
// Output: <p><a href="/?id=features">Features</a></p>

echo $converter->convert("[route('home', ['id' => 'features'], false)](route('home', ['id' => 'features'], false))");
// Output: <p><a href="/?id=features">/?id=features</a></p>

/*
 * These extensions should be added to the markdown environment. A valid
 * extension implements League\CommonMark\Extension\ExtensionInterface
 *
 * More info: https://commonmark.thephpleague.com/2.4/extensions/overview/
 */
'extensions' => [
    Mozex\CommonMarkRoutes\RoutesExtension::class,
],