Skip to content

Commit 96d1c2e

Browse files
committed
Fix indented code.
1 parent a4fa691 commit 96d1c2e

File tree

3 files changed

+40
-4
lines changed

3 files changed

+40
-4
lines changed

CHANGELOG.md

+5
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@
22

33
## Unreleased
44

5+
## 0.5.2 - 2021-09-26
6+
7+
### Fixed
8+
- Indented code works correctly now.
9+
510
## 0.5.1 - 2021-09-06
611

712
### Changed

src/BaseExtension.php

+13-4
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
namespace Torchlight\Commonmark;
44

55
use Illuminate\Support\Str;
6-
use League\CommonMark\Block\Element\IndentedCode;
76
use League\CommonMark\Event\DocumentParsedEvent;
87
use League\CommonMark\Util\Xml;
98
use Torchlight\Block;
@@ -170,8 +169,12 @@ protected function getContent($node)
170169
*/
171170
protected function getInfo($node)
172171
{
173-
if (!$this->isCodeNode($node) || $node instanceof IndentedCode) {
174-
return null;
172+
if (!$this->isCodeNode($node)) {
173+
return [];
174+
}
175+
176+
if (!is_callable([$node, 'getInfoWords'])) {
177+
return [];
175178
}
176179

177180
$infoWords = $node->getInfoWords();
@@ -185,7 +188,13 @@ protected function getInfo($node)
185188
*/
186189
protected function getLanguage($node)
187190
{
188-
$language = $this->getInfo($node)[0];
191+
$info = $this->getInfo($node);
192+
193+
if (empty($info)) {
194+
return null;
195+
}
196+
197+
$language = $info[0];
189198

190199
return $language ? Xml::escape($language, true) : null;
191200
}

tests/BaseRendererTest.php

+22
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,28 @@ public function can_set_theme()
118118
});
119119
}
120120

121+
/** @test */
122+
public function indented_code_doesnt_fail()
123+
{
124+
$markdown = <<<'EOT'
125+
before
126+
127+
<div>test</div>
128+
129+
after
130+
EOT;
131+
132+
Http::fake();
133+
134+
$this->render($markdown);
135+
136+
Http::assertSent(function ($request) {
137+
return $request['blocks'][0]['language'] === null
138+
&& $request['blocks'][0]['code'] === '<div>test</div>';
139+
});
140+
}
141+
142+
121143
/** @test */
122144
public function can_load_file()
123145
{

0 commit comments

Comments
 (0)