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

fix: correctly consume the child block, with example fenced code block #13

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/Parser/FigureParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,9 @@ public function tryStart(Cursor $cursor, MarkdownParserStateInterface $parserSta

public function tryContinue(Cursor $cursor, BlockContinueParserInterface $activeBlockParser): ?BlockContinue
{
$cursor->advanceToNextNonSpaceOrTab();
if ('^' === $cursor->getNextNonSpaceCharacter()) {
$cursor->advanceToNextNonSpaceOrTab();

if ('^' === $cursor->getCurrentCharacter()) {
if (null !== $cursor->match('/^\^{3,}/u') && !$cursor->isAtEnd()) {
$this->caption = $cursor->getRemainder();
}
Expand Down
37 changes: 37 additions & 0 deletions tests/FigureTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -162,4 +162,41 @@ public function testDifferentNumberOfSymbolsWithFigureCaption()
$this->assertSame($expect_1, $actual_1, 'Case with more upper is failed');
$this->assertSame($expect_2, $actual_2, 'Case with more lower is failed');
}

public function testFigureWithCodeBlockRetainsIndent()
{
$environment = new Environment();

$environment->addExtension(new CommonMarkCoreExtension())
->addExtension(new FigureExtension());

$converter = new MarkdownConverter($environment);

$expect = <<<EOL
<figure><pre><code>if (condition) {
doSomething();
dkarlovi marked this conversation as resolved.
Show resolved Hide resolved
}
// comment behind whitespace
dkarlovi marked this conversation as resolved.
Show resolved Hide resolved
// comment with whitespace
// comment with trailing whitespace
</code></pre></figure>

EOL;

$actual_md = <<<EOL
^^^
```
if (condition) {
doSomething();
}
// comment behind whitespace
// comment with whitespace
// comment with trailing whitespace
```
^^^
EOL;
$actual = $converter->convert($actual_md)->getContent();

$this->assertSame($expect, $actual);
}
}