Weird interaction of code block with other block parsers #1008
-
Version(s) affected2.4.1 DescriptionIn JanStanleyWatt/commonmark-figure-extension#13 I've added a failing test for the figure extension, using it will truncate leading spaces in the code block. I understand this is a bug report on a different repo, but debugging this issue it seems (to me) it's a bug in core, the parser there doesn't seem to be doing anything obviously wrong and it's using the core features to do what it needs to. When debugging the child code block node, it already has the whitespace truncated when it's being rendered, and the extension is not doing the parsing there. Any hints would be appreciated, cheers! How to reproduce |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
It looks like the That method is called when the parser engine is checking to see whether that block continues onto the next line. In this case, Applying this change should fix things: diff --git a/src/Parser/FigureParser.php b/src/Parser/FigureParser.php
index d512cb4..e9838c7 100644
--- a/src/Parser/FigureParser.php
+++ b/src/Parser/FigureParser.php
@@ -63,9 +63,8 @@ final class FigureParser extends AbstractBlockContinueParser implements BlockCon
public function tryContinue(Cursor $cursor, BlockContinueParserInterface $activeBlockParser): ?BlockContinue
{
- $cursor->advanceToNextNonSpaceOrTab();
-
- if ('^' === $cursor->getCurrentCharacter()) {
+ if ('^' === $cursor->getNextNonSpaceCharacter()) {
+ $cursor->advanceToNextNonSpaceOrTab();
if (null !== $cursor->match('/^\^{3,}/u') && !$cursor->isAtEnd()) {
$this->caption = $cursor->getRemainder();
}
|
Beta Was this translation helpful? Give feedback.
It looks like the
FigureParser
is consuming all of the leading whitespace in thetryContinue()
method:https://github.com/JanStanleyWatt/commonmark-figure-extension/blob/1a1efd0f89197e90dcf87e58977cc064ed13e603/src/Parser/FigureParser.php#L64-L77
That method is called when the parser engine is checking to see whether that block continues onto the next line. In this case,
FigureParser
"consumes" all of that leading whitespace before the child code block even gets a chance to inspect that line.Applying this change should fix things: