Skip to content

Commit

Permalink
Fix code blocks that are indented and not fenced.
Browse files Browse the repository at this point in the history
  • Loading branch information
aarondfrancis committed Sep 18, 2021
1 parent ec7ba18 commit b320c3b
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/BlockManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,12 @@ protected function renderMarkdownCapturedBlocks()
$contents = file_get_contents($file);

// Gather up all of the <pre> elements.
$elements = $this->getCapturedGroup("/(<pre(?:.+)<\/pre>)/", $contents, $all = true);
$elements = array_merge(
// This one captures regular fenced code blocks.
$this->getCapturedGroup("/(<pre(?:.+)<\/pre>)/", $contents, $all = true),
// This one captures indented code blocks, which are weirdly different for some reason.
$this->getCapturedGroup("/(<pre><code>(?:.+)\n<\/code><\/pre>)/", $contents, $all = true)
);

foreach ($elements as $element) {
// These are Blade directives, which will be handled later.
Expand Down
1 change: 1 addition & 0 deletions tests/BaseTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ public function most_of_the_tests_are_here()
$this->assertSnapshotMatches('non-existent-id');
$this->assertSnapshotMatches('one-component');
$this->assertSnapshotMatches('two-components');
$this->assertSnapshotMatches('code-indents-work');
}

/** @test */
Expand Down
13 changes: 13 additions & 0 deletions tests/Site/source/code-indents-work.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
---
extends: _layouts.master
section: content
---

Some text before


<?php
test here!


Some text after
5 changes: 5 additions & 0 deletions tests/snapshots/code-indents-work.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<p>Some text before</p>

<pre><code class='torchlight' style=''><div class='line'>&lt;?php</div><div class='line'>test here!</div></code></pre>

<p>Some text after</p>

0 comments on commit b320c3b

Please sign in to comment.