From 45dc00f31eba2d492dc41e3572f836c567204627 Mon Sep 17 00:00:00 2001 From: Juri Petersen <43411515+juripetersen@users.noreply.github.com> Date: Wed, 12 May 2021 14:22:42 +0200 Subject: [PATCH] Use GithubFlavoredMarkdownConverted to enable further rendering (#5) Use GithubFlavoredMarkdownConverter to enable rendering of tables and lists. Closes #4 --- src/Markdown/CommonMarkRepository.php | 6 ++-- tests/Unit/CommonMarkTest.php | 42 +++++++++++++++++++++++++++ 2 files changed, 45 insertions(+), 3 deletions(-) diff --git a/src/Markdown/CommonMarkRepository.php b/src/Markdown/CommonMarkRepository.php index 77f53e6..38940ba 100644 --- a/src/Markdown/CommonMarkRepository.php +++ b/src/Markdown/CommonMarkRepository.php @@ -2,16 +2,16 @@ namespace VV\Markdown\Markdown; -use League\CommonMark\CommonMarkConverter; +use League\CommonMark\GithubFlavoredMarkdownConverter; class CommonMarkRepository implements MarkdownRepository { - public CommonMarkConverter $parser; + public GithubFlavoredMarkdownConverter $parser; public string $style = 'default'; public function __construct(array $config) { - $this->parser = new CommonMarkConverter($config); + $this->parser = new GithubFlavoredMarkdownConverter($config); } public function parse(string $content): string diff --git a/tests/Unit/CommonMarkTest.php b/tests/Unit/CommonMarkTest.php index cad47b0..4cd6c0d 100644 --- a/tests/Unit/CommonMarkTest.php +++ b/tests/Unit/CommonMarkTest.php @@ -37,4 +37,46 @@ public function it_can_add_a_html_class_to_a_paragraph() $this->assertStringcontainsString($result, Markdown::parse($toParse)); } + + /** @test */ + public function it_can_parse_tables() + { + $toParse = 'th | th(center) | th(right) +---|:----------:|----------: +td | td | td'; + $result = ''; + + $this->assertStringcontainsString($result, Markdown::parse($toParse)); + } + + /** @test */ + public function it_can_add_a_css_class_to_a_table() + { + config()->set('markdown.styles.default.table', 'mb-2'); + + $toParse = 'th | th(center) | th(right) +---|:----------:|----------: +td | td | td'; + $result = '
'; + + $this->assertStringcontainsString($result, Markdown::parse($toParse)); + } + + /** @test */ + public function it_can_parse_lists() + { + $toParse = '* First item +* Second item +* Third item +* Fourth item'; + + $result = ''; + + $this->assertStringcontainsString($result, Markdown::parse($toParse)); + } }