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
5 changes: 4 additions & 1 deletion phpcs.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@

<exclude-pattern>*/vendor/*</exclude-pattern>

<rule ref="PhpCollective"/>
<rule ref="PhpCollective">
<!-- Conflicts with Universal.WhiteSpace.AnonClassKeywordSpacing which PhpCollective enables -->
<exclude name="PSR12.Classes.AnonClassDeclaration.SpaceAfterKeyword"/>
</rule>

<rule ref="SlevomatCodingStandard.Functions.RequireTrailingCommaInDeclaration"/>
<rule ref="SlevomatCodingStandard.Functions.RequireTrailingCommaInClosureUse"/>
Expand Down
8 changes: 8 additions & 0 deletions src/Parser/BlockParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -1500,6 +1500,14 @@ protected function tryParseList(Node $parent, array $lines, int $start): ?int
if ($itemInfo !== null && $itemInfo['type'] === $listInfo['type'] && $itemInfo['marker'] === $listInfo['marker'] && $sameStyle) {
break;
}
// After a blank line, content dropping back to base indent
// starts a new block outside the list - let parent handle it.
if ($sawBlankLine) {
$lastItemHadBlankAfter = true;
$brokeForParentContent = true;

break;
}
// Content at base indent that's not a matching list marker
// Check if it's a block element - if so, end list content collection
// Use isBlockElementStart() which detects blocks regardless of mode
Expand Down
2 changes: 1 addition & 1 deletion tests/TestCase/Extension/HeadingReferenceExtensionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ public function testHeadingWithNoTextIsIgnored(): void

public function testUserAuthoredLinkWithMatchingPlaceholderIsNotRewritten(): void
{
$extension = new class ('heading-ref') extends HeadingReferenceExtension {
$extension = new class('heading-ref') extends HeadingReferenceExtension {
protected function generatePlaceholderPrefix(): string
{
return 'collision-placeholder-';
Expand Down
35 changes: 35 additions & 0 deletions tests/TestCase/NestedBlocksInListsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -633,4 +633,39 @@ public function testIssue83CodeBlockCase(): void
// Should NOT be inline code
$this->assertStringNotContainsString('<p><code>', $result);
}

/**
* After a nested block inside a list item and a blank line, an
* unindented paragraph must terminate the list rather than being
* absorbed as a sub-item of the previous list item.
*
* @see https://github.com/php-collective/djot-php/issues/176
*/
public function testIssue176UnindentedParagraphAfterNestedCodeBlockEndsList(): void
{
$djot = <<<'DJOT'
1. Item 1
2. Item 2

```
Example
```

New list:

* New item 1
* New item 2
DJOT;

$result = $this->converter->convert($djot);

$this->assertStringContainsString('</ol>', $result);
// The "New list:" paragraph must appear after the ordered list closes.
$olClose = strpos($result, '</ol>');
$paragraph = strpos($result, '<p>New list:</p>');
$this->assertNotFalse($paragraph);
$this->assertGreaterThan($olClose, $paragraph);
// And the following bullet list must be a sibling, not nested in <li>.
$this->assertMatchesRegularExpression('#</ol>\s*<p>New list:</p>\s*<ul>#', $result);
}
}
Loading