Skip to content

Commit 86fb4ad

Browse files
author
Alex Garrett-Smith
committed
Added data-lang attribute for CommonMark code block renderer
1 parent f7938f4 commit 86fb4ad

File tree

2 files changed

+3
-2
lines changed

2 files changed

+3
-2
lines changed

src/CommonMark/CodeBlockRenderer.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ public function render(Node $node, ChildNodeRendererInterface $childRenderer)
3838
if ($theme instanceof WithPre) {
3939
return $theme->preBefore() . $parsed . $theme->preAfter();
4040
} else {
41-
return '<pre>' . $parsed . '</pre>';
41+
return '<pre data-lang="' . $matches['language'] . '">' . $parsed . '</pre>';
4242
}
4343
}
4444
}

tests/CommonMark/CodeBlockRendererTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ class Foo {}
3232
```");
3333

3434
$this->assertStringContainsString('hl-keyword', $parsed->getContent());
35+
$this->assertStringContainsString('data-lang="php"', $parsed->getContent());
3536
}
3637

3738
public function test_commonmark_with_gutter(): void
@@ -52,7 +53,7 @@ class Foo {}
5253
TXT;
5354

5455
$expected = <<<'TXT'
55-
<pre><span class="hl-gutter ">10</span> <span class="hl-keyword">class</span> <span class="hl-type">Foo</span> {}</pre>
56+
<pre data-lang="php"><span class="hl-gutter ">10</span> <span class="hl-keyword">class</span> <span class="hl-type">Foo</span> {}</pre>
5657

5758
TXT;
5859

0 commit comments

Comments
 (0)