* * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace League\CommonMark\Tests\Functional\Extension\DefaultAttributes; use League\CommonMark\Environment\Environment; use League\CommonMark\Extension\CommonMark\CommonMarkCoreExtension; use League\CommonMark\Extension\CommonMark\Node\Block\BlockQuote; use League\CommonMark\Extension\CommonMark\Node\Block\Heading; use League\CommonMark\Extension\CommonMark\Node\Inline\Link; use League\CommonMark\Extension\DefaultAttributes\DefaultAttributesExtension; use League\CommonMark\Extension\Table\Table; use League\CommonMark\Extension\Table\TableExtension; use League\CommonMark\MarkdownConverter; use League\CommonMark\Node\Block\Paragraph; use PHPUnit\Framework\TestCase; final class DefaultAttributesExtensionTest extends TestCase { /** * @dataProvider provideTestCases * * @param array $config */ public function testExample(string $markdown, array $config, string $expectedHtml): void { $environment = new Environment($config); $environment->addExtension(new CommonMarkCoreExtension()); $environment->addExtension(new TableExtension()); $environment->addExtension(new DefaultAttributesExtension()); $converter = new MarkdownConverter($environment); $this->assertSame($expectedHtml, \rtrim($converter->convert($markdown)->getContent())); } /** * @return iterable */ public function provideTestCases(): iterable { $markdown = <<Hello World

Welcome to my blog!

About Me

I'm a nerd who loves the league/commonmark library.

HTML, ]; yield [ $markdown, [ 'default_attributes' => [], ], <<Hello World

Welcome to my blog!

About Me

I'm a nerd who loves the league/commonmark library.

HTML, ]; yield [ $markdown, [ 'default_attributes' => [ Paragraph::class => [ 'class' => ['text-center', 'font-comic-sans'], ], Link::class => [ 'class' => 'btn btn-link', 'target' => '_blank', ], Heading::class => [ 'class' => static function (Heading $node) { if ($node->getLevel() === 1) { return 'page-title'; } return null; }, ], ], ], <<Hello World

Welcome to my blog!

About Me

I'm a nerd who loves the league/commonmark library.

HTML, ]; // One last test to theme some Bootstrap 4 content yield [ << One touch of nature makes the whole world kin. ## My Favorites | Park | Location | Established | | ----------- | ----------------------- | ----------------- | | Yellowstone | Montana, Wyoming, Idaho | March 1, 1872 | | Yosemite | California | March 1, 1872 | | Zion | Utah | November 19, 1919 | MD , [ 'default_attributes' => [ Table::class => [ 'class' => ['table', 'table-responsive'], ], BlockQuote::class => [ 'class' => 'blockquote', ], Paragraph::class => [ 'class' => static function (Paragraph $paragraph) { if ($paragraph->previous() instanceof Heading && $paragraph->previous()->getLevel() === 1) { return 'lead'; } return null; }, ], ], ], <<U.S. National Parks

The United States has some amazing national parks.

As William Shakespeare once said:

One touch of nature makes the whole world kin.

My Favorites

Park Location Established
Yellowstone Montana, Wyoming, Idaho March 1, 1872
Yosemite California March 1, 1872
Zion Utah November 19, 1919
HTML, ]; } }