diff --git a/app/Entities/Tools/PageContent.php b/app/Entities/Tools/PageContent.php index f60971b8b..91de94211 100644 --- a/app/Entities/Tools/PageContent.php +++ b/app/Entities/Tools/PageContent.php @@ -5,6 +5,9 @@ use DOMDocument; use DOMNodeList; use DOMXPath; use League\CommonMark\CommonMarkConverter; +use League\CommonMark\Environment; +use League\CommonMark\Extension\Table\TableExtension; +use League\CommonMark\Extension\TaskList\TaskListExtension; class PageContent { @@ -45,7 +48,10 @@ class PageContent */ protected function markdownToHtml(string $markdown): string { - $converter = new CommonMarkConverter(); + $environment = Environment::createCommonMarkEnvironment(); + $environment->addExtension(new TableExtension()); + $environment->addExtension(new TaskListExtension()); + $converter = new CommonMarkConverter([], $environment); return $converter->convertToHtml($markdown); } diff --git a/tests/Entity/PageContentTest.php b/tests/Entity/PageContentTest.php index 51a8568bf..857645823 100644 --- a/tests/Entity/PageContentTest.php +++ b/tests/Entity/PageContentTest.php @@ -420,4 +420,45 @@ class PageContentTest extends TestCase $page->refresh(); $this->assertEquals('"Hello & welcome"', $page->text); } + + public function test_page_markdown_table_rendering() + { + $this->asEditor(); + $page = Page::query()->first(); + + $content = '| Syntax | Description | +| ----------- | ----------- | +| Header | Title | +| Paragraph | Text |'; + $this->put($page->getUrl(), [ + 'name' => $page->name, 'markdown' => $content, + 'html' => '', 'summary' => '' + ]); + + $page->refresh(); + $this->assertStringContainsString('', $page->html); + + $pageView = $this->get($page->getUrl()); + $pageView->assertElementExists('.page-content table tbody td'); + } + + public function test_page_markdown_task_list_rendering() + { + $this->asEditor(); + $page = Page::query()->first(); + + $content = '- [ ] Item a +- [x] Item b'; + $this->put($page->getUrl(), [ + 'name' => $page->name, 'markdown' => $content, + 'html' => '', 'summary' => '' + ]); + + $page->refresh(); + $this->assertStringContainsString('input', $page->html); + $this->assertStringContainsString('type="checkbox"', $page->html); + + $pageView = $this->get($page->getUrl()); + $pageView->assertElementExists('.page-content input[type=checkbox]'); + } }