1. Go to this page and download the library: Download antonioprimera/md-parser 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/ */
use AntonioPrimera\Md\Facades\Md;
$html = Md::parse($markdownString);
class BasicMarkdownParser
{
public static function create(array $config = []): Parser
{
return new Parser(
inlineParsers: [
new ImageParser(), //this has to go before the LinkParser, because it uses a similar syntax
new LinkParser(),
new BoldParser(),
new ItalicParser(),
new LineBreakParser(), //this has to go last, because other parsers may use "|" in their syntax
],
blockParsers: [
new HeadingParser(['baseHeadingLevel' => $config['baseHeadingLevel'] ?? 2]),
new UnorderedListItemParser(),
new BlockQuoteParser(),
new ParagraphParser(),
],
config: $config
);
}
}
class EmptyBlockParser extends BlockParser
{
public function matches(string $text, array $parsedBlocks = []): bool
{
//this parser will match empty blocks (blocks that contain only whitespace)
return empty(trim($text));
}
public function parse(string $text, array &$parsedBlocks = []): string|MarkdownBlock|null
{
//instead of returning an empty string, we return a special class that will be styled with CSS
return '<p class="empty-block"></p>';
}
}
class HeroIconParser extends InlineParser
{
public function parse(string $text): string
{
$pattern = '/\[heroicon:(.+)\]/';
return preg_replace_callback($pattern, fn($matches) => "<i class='heroicon heroicon-$matches[1]'></i>", $text);
}
}