PHP code example of curder / commonmark-extensions
1. Go to this page and download the library: Download curder/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/ */
curder / commonmark-extensions example snippets
echo "Hello, World!";
use League\CommonMark\Environment\Environment;
use League\CommonMark\Extension\CommonMark\CommonMarkCoreExtension;
use League\CommonMark\MarkdownConverter;
use Curder\CommonmarkExtensions\CodeGroupsExtension;
use Curder\CommonmarkExtensions\CustomContainersExtension;
use Curder\CommonmarkExtensions\HeadAnchorsExtension;
// 创建环境配置
$config = [];
// 创建环境并添加扩展
$environment = new Environment($config);
$environment->addExtension(new CommonMarkCoreExtension());
$environment->addExtension(new CodeGroupsExtension());
$environment->addExtension(new CustomContainersExtension());
$environment->addExtension(new HeadAnchorsExtension());
// 创建 Markdown 转换器
$converter = new MarkdownConverter($environment);
// 转换 Markdown 为 HTML
$html = $converter->convert($markdown)->getContent();