File tree Expand file tree Collapse file tree 5 files changed +64
-0
lines changed
tests/Integration/View/Components Expand file tree Collapse file tree 5 files changed +64
-0
lines changed Original file line number Diff line number Diff line change 1717 "giggsey/libphonenumber-for-php-lite" : " ^9.0" ,
1818 "guzzlehttp/guzzle" : " ^7.8.2" ,
1919 "laminas/laminas-diactoros" : " ^3.3" ,
20+ "league/commonmark" : " ^2.7" ,
2021 "league/flysystem" : " ^3.29.1" ,
2122 "monolog/monolog" : " ^3.7.0" ,
2223 "nette/php-generator" : " ^4.1.6" ,
Original file line number Diff line number Diff line change 99 "tempest/container" : " dev-main" ,
1010 "tempest/validation" : " dev-main" ,
1111 "tempest/clock" : " dev-main" ,
12+ "league/commonmark" : " ^2.7" ,
1213 "symfony/cache" : " ^7.2"
1314 },
1415 "autoload" : {
Original file line number Diff line number Diff line change 1+ <?php
2+
3+ /**
4+ * @var string|null $content The markdown content from a variable
5+ */
6+
7+ use League \CommonMark \MarkdownConverter ;
8+ use Tempest \View \Slot ;
9+
10+ use function Tempest \get ;
11+
12+ $ content ??= $ slots [Slot::DEFAULT ]->content ?? '' ;
13+ $ markdown = get (MarkdownConverter::class);
14+ $ parsed = $ markdown ->convert ($ content )->getContent ();
15+ ?>
16+
17+ {!! $parsed !!}
Original file line number Diff line number Diff line change 1+ <?php
2+
3+ namespace Tempest \View ;
4+
5+ use League \CommonMark \Environment \Environment ;
6+ use League \CommonMark \Extension \CommonMark \CommonMarkCoreExtension ;
7+ use League \CommonMark \MarkdownConverter ;
8+ use Tempest \Container \Container ;
9+ use Tempest \Container \Initializer ;
10+ use Tempest \Container \Singleton ;
11+
12+ final class MarkdownInitializer implements Initializer
13+ {
14+ #[Singleton]
15+ public function initialize (Container $ container ): MarkdownConverter
16+ {
17+ return new MarkdownConverter (new Environment ()->addExtension (new CommonMarkCoreExtension ()));
18+ }
19+ }
Original file line number Diff line number Diff line change 1+ <?php
2+
3+ namespace Integration \View \Components ;
4+
5+ use Tests \Tempest \Integration \FrameworkIntegrationTestCase ;
6+
7+ final class MarkdownComponentTest extends FrameworkIntegrationTestCase
8+ {
9+ public function test_render_markdown_as_content (): void
10+ {
11+ $ html = $ this ->render (<<<'HTML'
12+ <x-markdown># hi</x-markdown>
13+ HTML);
14+
15+ $ this ->assertSame ('<h1>hi</h1> ' , $ html );
16+ }
17+
18+ public function test_render_markdown_as_variable (): void
19+ {
20+ $ html = $ this ->render (<<<'HTML'
21+ <x-markdown :content="$text"></x-markdown>
22+ HTML, text: '# hi ' );
23+
24+ $ this ->assertSame ('<h1>hi</h1> ' , $ html );
25+ }
26+ }
You can’t perform that action at this time.
0 commit comments