Added in table + tasklist markdown rendering
For parity with markdown-it renderer. Added tests to cover. For #2452
This commit is contained in:
parent
47e3ef1be2
commit
831f441879
2 changed files with 48 additions and 1 deletions
|
@ -5,6 +5,9 @@ use DOMDocument;
|
||||||
use DOMNodeList;
|
use DOMNodeList;
|
||||||
use DOMXPath;
|
use DOMXPath;
|
||||||
use League\CommonMark\CommonMarkConverter;
|
use League\CommonMark\CommonMarkConverter;
|
||||||
|
use League\CommonMark\Environment;
|
||||||
|
use League\CommonMark\Extension\Table\TableExtension;
|
||||||
|
use League\CommonMark\Extension\TaskList\TaskListExtension;
|
||||||
|
|
||||||
class PageContent
|
class PageContent
|
||||||
{
|
{
|
||||||
|
@ -45,7 +48,10 @@ class PageContent
|
||||||
*/
|
*/
|
||||||
protected function markdownToHtml(string $markdown): string
|
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);
|
return $converter->convertToHtml($markdown);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -420,4 +420,45 @@ class PageContentTest extends TestCase
|
||||||
$page->refresh();
|
$page->refresh();
|
||||||
$this->assertEquals('"Hello & welcome"', $page->text);
|
$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('</tbody>', $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]');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue