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

[11.x] Adds support for Markdown extensions to the Stringable class. #51932

Merged
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
5 changes: 3 additions & 2 deletions src/Illuminate/Support/Stringable.php
Original file line number Diff line number Diff line change
Expand Up @@ -454,11 +454,12 @@ public function lower()
* Convert GitHub flavored Markdown into HTML.
*
* @param array $options
* @param array $extensions
* @return static
*/
public function markdown(array $options = [])
public function markdown(array $options = [], array $extensions = [])
{
return new static(Str::markdown($this->value, $options));
return new static(Str::markdown($this->value, $options, $extensions));
}

/**
Expand Down
14 changes: 14 additions & 0 deletions tests/Support/SupportStringableTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
use Illuminate\Support\Collection;
use Illuminate\Support\HtmlString;
use Illuminate\Support\Stringable;
use League\CommonMark\Environment\EnvironmentBuilderInterface;
use League\CommonMark\Extension\ExtensionInterface;
use PHPUnit\Framework\TestCase;

class SupportStringableTest extends TestCase
Expand Down Expand Up @@ -1130,6 +1132,18 @@ public function testMarkdown()
{
$this->assertEquals("<p><em>hello world</em></p>\n", $this->stringable('*hello world*')->markdown());
$this->assertEquals("<h1>hello world</h1>\n", $this->stringable('# hello world')->markdown());

$extension = new class implements ExtensionInterface
{
public bool $configured = false;

public function register(EnvironmentBuilderInterface $environment): void
{
$this->configured = true;
}
};
$this->stringable('# hello world')->markdown([], [$extension]);
$this->assertTrue($extension->configured);
}

public function testInlineMarkdown()
Expand Down