generated from spatie/package-skeleton-php
-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
79 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Wnx\CommonmarkMarkdownRenderer\Renderer\Inline; | ||
|
||
use League\CommonMark\Extension\TaskList\TaskListItemMarker; | ||
use League\CommonMark\Node\Node; | ||
use League\CommonMark\Renderer\ChildNodeRendererInterface; | ||
use League\CommonMark\Renderer\NodeRendererInterface; | ||
|
||
class TaskListItemMarkerRenderer implements NodeRendererInterface | ||
{ | ||
/** | ||
* @param TaskListItemMarker $node | ||
* | ||
* {@inheritDoc} | ||
* | ||
* @psalm-suppress MoreSpecificImplementedParamType | ||
*/ | ||
public function render(Node $node, ChildNodeRendererInterface $childRenderer) | ||
{ | ||
return sprintf('[%s]', $node->isChecked() ? 'x' : ' '); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Wnx\CommonmarkMarkdownRenderer\Tests\Renderer\Inline; | ||
|
||
use League\CommonMark\Extension\TaskList\TaskListItemMarker; | ||
use PHPUnit\Framework\TestCase; | ||
use Wnx\CommonmarkMarkdownRenderer\Renderer\Inline\TaskListItemMarkerRenderer; | ||
use Wnx\CommonmarkMarkdownRenderer\Tests\Support\FakeChildNodeRenderer; | ||
|
||
class TaskListItemMarkerRendererTest extends TestCase | ||
{ | ||
private TaskListItemMarkerRenderer $renderer; | ||
|
||
protected function setUp(): void | ||
{ | ||
$this->renderer = new TaskListItemMarkerRenderer(); | ||
} | ||
|
||
/** @test */ | ||
public function it_renders_unchecked_task_list_item() | ||
{ | ||
$node = new TaskListItemMarker(false); | ||
$fakeRenderer = new FakeChildNodeRenderer(); | ||
|
||
$result = $this->renderer->render($node, $fakeRenderer); | ||
|
||
$this->assertIsString($result); | ||
$this->assertEquals("[ ]", $result); | ||
} | ||
|
||
/** @test */ | ||
public function it_renders_checked_task_list_item() | ||
{ | ||
$node = new TaskListItemMarker(true); | ||
$fakeRenderer = new FakeChildNodeRenderer(); | ||
|
||
$result = $this->renderer->render($node, $fakeRenderer); | ||
|
||
$this->assertIsString($result); | ||
$this->assertEquals("[x]", $result); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters