/commonmark-figure-extension

League\CommonMark extension for HTML diagrams and captions inspired by Markdig.

Primary LanguagePHPApache License 2.0Apache-2.0

Commonmark Figure Extension

League\CommonMarkextension for HTML diagrams and captions inspired by Markdig.

Installation

$ composer require jsw/commonmark-figure-extension

Usage

  • Fence the top and bottom of the sentence you want to be a figure with ^ like a code block
  • Continued text in bottom fence becomes figure caption
  • Even if the number of upper and lower ^ is different, it will be processed normally
$environment = new Environment();
$environment->addExtension(new CommonMarkCoreExtension());
            ->addExtension(new FitureExtension());

$converter = new MarkdownConverter($environment);

$markdown =<<<EOL
^^^
![example-image](https://example.com/image.jpg)
^^^ This is caption for image
EOL;

// <figure><p><img src="https://example.com/image.jpg" alt="example-image" /></p>
// <figcaption>This is caption for image</figcaption></figure>
echo $converter->convert($markdown);

License

Apache-v2