Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make it possible to add extension from the CommonMarkConverter class #1052

Open
wants to merge 1 commit into
base: 2.5
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/CommonMarkConverter.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

use League\CommonMark\Environment\Environment;
use League\CommonMark\Extension\CommonMark\CommonMarkCoreExtension;
use League\CommonMark\Extension\ExtensionInterface;

/**
* Converts CommonMark-compatible Markdown to HTML.
Expand All @@ -43,4 +44,9 @@

return $this->environment;
}

public function addExtension(ExtensionInterface $extension): void
{
$this->environment->addExtension($extension);

Check failure on line 50 in src/CommonMarkConverter.php

View workflow job for this annotation

GitHub Actions / PHPStan

Call to an undefined method League\CommonMark\Environment\EnvironmentInterface::addExtension().

Check failure on line 50 in src/CommonMarkConverter.php

View workflow job for this annotation

GitHub Actions / Psalm

UndefinedInterfaceMethod

src/CommonMarkConverter.php:50:29: UndefinedInterfaceMethod: Method League\CommonMark\Environment\EnvironmentInterface::addExtension does not exist (see https://psalm.dev/181)
}
}
15 changes: 15 additions & 0 deletions tests/unit/CommonMarkConverterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
use League\CommonMark\Environment\Environment;
use League\CommonMark\Exception\UnexpectedEncodingException;
use League\CommonMark\Extension\CommonMark\CommonMarkCoreExtension;
use League\CommonMark\Extension\Table\TableExtension;
use League\CommonMark\Util\HtmlFilter;
use PHPUnit\Framework\TestCase;

Expand Down Expand Up @@ -70,4 +71,18 @@ public function testGetEnvironmentReturnsMainEnvironmentClass(): void

$this->assertInstanceOf(Environment::class, $converter->getEnvironment());
}

public function testAddExtensionToEnvironment(): void
{
$converter = new CommonMarkConverter();

$environment = $converter->getEnvironment();

$this->assertCount(1, $environment->getExtensions());
$this->assertInstanceOf(CommonMarkCoreExtension::class, $environment->getExtensions()[0]);

$environment->addExtension(new TableExtension());
$this->assertCount(2, $environment->getExtensions());
$this->assertInstanceOf(TableExtension::class, $environment->getExtensions()[1]);
}
}
Loading