Skip to content

Commit

Permalink
Use GithubFlavoredMarkdownConverted to enable further rendering (#5)
Browse files Browse the repository at this point in the history
Use GithubFlavoredMarkdownConverter to enable rendering of tables and lists. 

Closes #4
  • Loading branch information
juripetersen authored May 12, 2021
1 parent 1f28fc7 commit 45dc00f
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/Markdown/CommonMarkRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
42 changes: 42 additions & 0 deletions tests/Unit/CommonMarkTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 = '<table>';

$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 = '<table class="mb-2">';

$this->assertStringcontainsString($result, Markdown::parse($toParse));
}

/** @test */
public function it_can_parse_lists()
{
$toParse = '* First item
* Second item
* Third item
* Fourth item';

$result = '<ul>
<li>First item</li>
<li>Second item</li>
<li>Third item</li>
<li>Fourth item</li>
</ul>';

$this->assertStringcontainsString($result, Markdown::parse($toParse));
}
}

0 comments on commit 45dc00f

Please sign in to comment.