diff --git a/src/CommonMark/CodeBlockRenderer.php b/src/CommonMark/CodeBlockRenderer.php index 824cc43..7e23062 100644 --- a/src/CommonMark/CodeBlockRenderer.php +++ b/src/CommonMark/CodeBlockRenderer.php @@ -31,14 +31,16 @@ public function render(Node $node, ChildNodeRendererInterface $childRenderer) $this->highlighter->withGutter((int)$startAt); } - $parsed = $this->highlighter->parse($node->getLiteral(), $matches['language']); + $language = $matches['language'] ?? 'txt'; + + $parsed = $this->highlighter->parse($node->getLiteral(), $language); $theme = $this->highlighter->getTheme(); if ($theme instanceof WithPre) { return $theme->preBefore() . $parsed . $theme->preAfter(); } else { - return '
' . $parsed . ''; + return '
' . $parsed . ''; } } } diff --git a/tests/CommonMark/CodeBlockRendererTest.php b/tests/CommonMark/CodeBlockRendererTest.php index 4980089..fee5f81 100644 --- a/tests/CommonMark/CodeBlockRendererTest.php +++ b/tests/CommonMark/CodeBlockRendererTest.php @@ -82,6 +82,32 @@ public function test_commonmark_with_pre(): void
echo;
+TXT;
+
+ $this->assertSame($expected, $markdown->convert($input)->getContent());
+ }
+
+ public function test_commonmark_with_no_language(): void
+ {
+ $environment = new Environment();
+
+ $environment
+ ->addExtension(new CommonMarkCoreExtension())
+ ->addExtension(new FrontMatterExtension())
+ ->addRenderer(FencedCode::class, new CodeBlockRenderer());
+
+ $markdown = new MarkdownConverter($environment);
+
+ $input = <<<'TXT'
+```
+echo;
+```
+TXT;
+
+ $expected = <<<'TXT'
+echo; ++ TXT; $this->assertSame($expected, $markdown->convert($input)->getContent());