Skip to content

Commit

Permalink
[11.x] Adds support for Markdown extensions to the Stringable class. (
Browse files Browse the repository at this point in the history
#51932)

* [11.x] Adds support for Markdown extensions to the `Stringable` class.

* [11.x] Adds support for Markdown extensions to the `Stringable` class.
  • Loading branch information
lukeraymonddowning authored Jun 28, 2024
1 parent 7b78fd3 commit fc4a157
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
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

0 comments on commit fc4a157

Please sign in to comment.