Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Align Renderer more with CommonMark Spec #18

Draft
wants to merge 9 commits into
base: main
Choose a base branch
from
Draft
2 changes: 1 addition & 1 deletion src/Renderer/Block/HtmlBlockRenderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public function render(Node $node, ChildNodeRendererInterface $childRenderer): s

$htmlInput = $this->config->get('html_input');

return HtmlFilter::filter($node->getLiteral(), $htmlInput);
return HtmlFilter::filter($node->getLiteral() . "\n", $htmlInput);
}

public function setConfiguration(ConfigurationInterface $configuration): void
Expand Down
6 changes: 6 additions & 0 deletions src/Renderer/Block/IndentedCodeRenderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,12 @@ public function render(Node $node, ChildNodeRendererInterface $childRenderer): s

$content = [];
foreach (explode("\n", $node->getLiteral()) as $line) {
if ($line === '') {
$content[] = null;

continue;
}

$content[] = " {$line}";
}

Expand Down
7 changes: 6 additions & 1 deletion src/Renderer/Block/ListItemRenderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,12 @@ private function addBulletChar(ListData $listData, string $content): string
{
switch ($listData->type) {
case ListBlock::TYPE_BULLET:
return "{$listData->bulletChar} {$content}";
// Subtract 1 character from $listData->padding if the value is greater than 0.
// The one character represents the bullet character.
$padding = $listData->padding > 0 ? $listData->padding - 1 : 1;
$padding = str_repeat(' ', $padding);

return "{$listData->bulletChar}{$padding}{$content}";
case ListBlock::TYPE_ORDERED:
switch ($listData->delimiter) {
case ListBlock::DELIM_PAREN:
Expand Down
2 changes: 1 addition & 1 deletion tests/Renderer/Block/FencedCodeRendererTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public function it_renders_fenced_code(array $fencedArgs, string $expected): voi
$this->assertEquals($expected, $result);
}

public function provide_fenced_code(): array
public static function provide_fenced_code(): array
{
return [
'tilde as char' => [
Expand Down
3 changes: 2 additions & 1 deletion tests/Renderer/Block/HtmlBlockRendererTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public function it_renders_paragraph(): void
$result = $this->renderer->render($block, $fakeRenderer);

$this->assertIsString($result);
$this->assertEquals('<!-- This is a comment -->', $result);
$this->assertEquals("<!-- This is a comment -->\n", $result);
}

#[Test]
Expand All @@ -56,6 +56,7 @@ public function it_renders_cdata_html(): void
<![CDATA[
<h1>Hello World</h1>
]]>

HTML, $result);
}

Expand Down
14 changes: 14 additions & 0 deletions tests/Renderer/MarkdownRendererTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,20 @@ public function it_parses_and_renders_kitchen_sink(): void
$this->assertEquals($contentKitchenSinkExpected, $result);
}

#[Test]
public function it_parses_and_renders_commonmark_sample_file(): void
{
$sample = file_get_contents(__DIR__ . '/../stubs/sample.md');

$document = $this->parser->parse($sample);

$result = $this->renderer->renderDocument($document)->getContent();

// file_put_contents(__DIR__ . '/../stubs/sample-result.md', $result);

// $this->assertEquals($sample, $result);
}

#[Test]
public function it_parses_kitchen_sink_and_parsing_the_result_again_returns_the_same_result(): void
{
Expand Down
Loading
Loading