Skip to content
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
15 changes: 8 additions & 7 deletions src/Parser/BlockParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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)) {
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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++;

Expand Down Expand Up @@ -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']) {
Expand Down Expand Up @@ -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)
) {
Expand Down
64 changes: 64 additions & 0 deletions tests/TestCase/ConformanceFollowupsTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
<?php

declare(strict_types=1);

namespace Djot\Test\TestCase;

use Djot\DjotConverter;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\TestCase;

/**
* Empty-label references in quotes and whitespace-only lines in item code (as djot.js),
* and trailing tabs trimmed from cells (djot.js keeps them, see jgm/djot.js#176).
*/
class ConformanceFollowupsTest extends TestCase
{
#[DataProvider('casesProvider')]
public function testOutput(string $djot, string $expected): void
{
$this->assertSame($expected, (new DjotConverter())->convert($djot));
$this->assertSame($expected, (new DjotConverter(warnings: true))->convert($djot));
}

/**
* @return array<string, array{string, string}>
*/
public static function casesProvider(): array
{
return [
'reference definition with an empty label in a quote' => [
"> []: p\npara\n",
"<blockquote>\n</blockquote>\n<p>para</p>\n",
],
'reference definition with an empty label after quoted text' => [
"> x\n>\n> []: <u>\nr\n",
"<blockquote>\n<p>x</p>\n</blockquote>\n<p>r</p>\n",
],
'tab after an escaped space in a cell is trimmed' => [
"| a\\ \t|\n",
"<table>\n<tr>\n<td>a&nbsp;</td>\n</tr>\n</table>\n",
],
'tab and spaces after the text of a cell are trimmed' => [
"| a \t |\n",
"<table>\n<tr>\n<td>a</td>\n</tr>\n</table>\n",
],
'whitespace-only line in a raw block in a tight item' => [
"- ``` =html\n x\n \n y\n ```\n",
"<ul>\n<li>\nx\n \ny\n</li>\n</ul>\n",
],
'whitespace-only line in a code block in a tight item' => [
"- ```\n x\n \n ```\n",
"<ul>\n<li>\n<pre><code>x\n \n</code></pre>\n</li>\n</ul>\n",
],
'whitespace-only line in a code block in a loose item' => [
"- a\n\n ```\n x\n \n y\n ```\n",
"<ul>\n<li>\n<p>a</p>\n<pre><code>x\n \ny\n</code></pre>\n</li>\n</ul>\n",
],
'whitespace-only line in a raw block in a loose item' => [
"- a\n\n ``` =html\n x\n \n y\n ```\n",
"<ul>\n<li>\n<p>a</p>\nx\n \ny\n</li>\n</ul>\n",
],
];
}
}
Loading