diff --git a/src/Parser/BlockParser.php b/src/Parser/BlockParser.php index dd3e1a0..70bcbac 100644 --- a/src/Parser/BlockParser.php +++ b/src/Parser/BlockParser.php @@ -1670,7 +1670,7 @@ protected function startsHeadingBlock(string $line): bool return false; } if ( - preg_match('/^\[[^\]]+\]:(?:[ \t]+\S*)?[ \t]*$/', $line) + preg_match('/^\[[^\]]*\]:(?:[ \t]+\S*)?[ \t]*$/', $line) || $this->fencedBlockParser->parseCodeFenceOpener($line) !== null || $this->fencedBlockParser->parseDivFenceOpener($line) !== null || $this->listParser->parseListItemMarker($line) !== null @@ -1948,7 +1948,7 @@ private function trackBlockQuoteLine(string $line, array &$state, array &$contai $rest = substr($line, $pos); if ( $reference !== null && $pos > $reference['indent'] && $rest !== '' - && !preg_match('/^\[[^\]]+\]:(?=[ \t]|$)/', $rest) && !$this->startsNewBlock($rest) + && !preg_match('/^\[[^\]]*\]:(?=[ \t]|$)/', $rest) && !$this->startsNewBlock($rest) ) { $containers[] = $reference; @@ -1986,7 +1986,7 @@ private function trackBlockQuoteLine(string $line, array &$state, array &$contai return true; } - if (preg_match('/^\[[^\]]+\]:(?:[ \t]+\S*)?[ \t]*$/', $rest)) { + if (preg_match('/^\[[^\]]*\]:(?:[ \t]+\S*)?[ \t]*$/', $rest)) { // A footnote definition holds blocks of its own, and the list parser reads a // definition's indented lines its own way; leave both to the flat tracker. if (str_starts_with($rest, '[^') || in_array('item', array_column($containers, 'type'), true)) { @@ -2054,7 +2054,7 @@ private function opensBlock(string $line): bool return $this->isQuotePrefixAt($trimmed, 0) || preg_match('/^#{1,6}(?:[ \t]|$)/', $trimmed) === 1 || preg_match('/^(?:\*\[|\[\^)[^\]]+\]:(?=[ \t]|$)/', $trimmed) === 1 - || preg_match('/^\[[^\]]+\]:(?:[ \t]+\S*)?[ \t]*$/', $trimmed) === 1 + || preg_match('/^\[[^\]]*\]:(?:[ \t]+\S*)?[ \t]*$/', $trimmed) === 1 || $this->fencedBlockParser->parseCodeFenceOpener($trimmed) !== null || $this->fencedBlockParser->parseDivFenceOpener($trimmed) !== null || $this->leavesNoParagraph($trimmed) @@ -2547,7 +2547,7 @@ protected function tryParseList(Node $parent, array $lines, int $start, ?array $ if (IndentationHelper::isBlankLine($subLine)) { $subLines[] = ''; $subLineMap[] = $this->sourceLineFor($lineMap, $i); - $subRaw[] = ''; + $subRaw[] = $subLine; $sawBlankLine = true; $i++; @@ -2742,7 +2742,8 @@ protected function tryParseList(Node $parent, array $lines, int $start, ?array $ if (!$itemState['inFence'] && !$itemState['inComment'] && $itemDivFences === []) { break; } - $itemLines[] = ''; + // Keep the spaces past the content column: a raw or code block shows them. + $itemLines[] = IndentationHelper::stripLeadingIndent($nextLine, $contentIndent); $itemLineMap[] = $this->sourceLineFor($lineMap, $i); $this->trackDefinitionLazyState('', $itemState, $itemDivFences, $itemQuoteDepth); if (!$itemState['paragraphOpen']) { @@ -3107,7 +3108,7 @@ protected function tryParseList(Node $parent, array $lines, int $start, ?array $ $firstLine = ltrim($itemLines[0], ' '); if ( $parseItemLinesAsBlocks || $this->isBlockElementStart($firstLine) - || preg_match('/^\[[^\]]+\]:(?:[ \t]+\S*)?[ \t]*$/', $firstLine) + || preg_match('/^\[[^\]]*\]:(?:[ \t]+\S*)?[ \t]*$/', $firstLine) // A marker-line `{...}` may be a block attribute for the lines below. || preg_match('/^\{.*\}[ \t]*$/', $firstLine) ) { diff --git a/tests/TestCase/ConformanceFollowupsTest.php b/tests/TestCase/ConformanceFollowupsTest.php new file mode 100644 index 0000000..dbb28c0 --- /dev/null +++ b/tests/TestCase/ConformanceFollowupsTest.php @@ -0,0 +1,64 @@ +assertSame($expected, (new DjotConverter())->convert($djot)); + $this->assertSame($expected, (new DjotConverter(warnings: true))->convert($djot)); + } + + /** + * @return array + */ + public static function casesProvider(): array + { + return [ + 'reference definition with an empty label in a quote' => [ + "> []: p\npara\n", + "
\n
\n

para

\n", + ], + 'reference definition with an empty label after quoted text' => [ + "> x\n>\n> []: \nr\n", + "
\n

x

\n
\n

r

\n", + ], + 'tab after an escaped space in a cell is trimmed' => [ + "| a\\ \t|\n", + "\n\n\n\n
a 
\n", + ], + 'tab and spaces after the text of a cell are trimmed' => [ + "| a \t |\n", + "\n\n\n\n
a
\n", + ], + 'whitespace-only line in a raw block in a tight item' => [ + "- ``` =html\n x\n \n y\n ```\n", + "\n", + ], + 'whitespace-only line in a code block in a tight item' => [ + "- ```\n x\n \n ```\n", + "\n", + ], + 'whitespace-only line in a code block in a loose item' => [ + "- a\n\n ```\n x\n \n y\n ```\n", + "\n", + ], + 'whitespace-only line in a raw block in a loose item' => [ + "- a\n\n ``` =html\n x\n \n y\n ```\n", + "\n", + ], + ]; + } +}