From 40e21fd139ee29b48f3931cf00507879473bc1c3 Mon Sep 17 00:00:00 2001 From: nadar Date: Fri, 24 Mar 2023 18:57:30 +0100 Subject: [PATCH] prepare test for issue #78 (#79) * prepare test for issue #78 * handle empty line, fix wrong test from issue #53 * changelog --- CHANGELOG.md | 4 +++ composer.lock | 15 +++++---- src/listener/Lists.php | 59 +++++++++++++++++++++------------- tests/Issue53Test.php | 2 +- tests/Issue53TestFixedTest.php | 26 +++++++++++++++ tests/Issue78Test.php | 52 ++++++++++++++++++++++++++++++ 6 files changed, 128 insertions(+), 30 deletions(-) create mode 100644 tests/Issue53TestFixedTest.php create mode 100644 tests/Issue78Test.php diff --git a/CHANGELOG.md b/CHANGELOG.md index 6b49d80..c31d9c2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,10 @@ All notable changes to this project will be documented in this file. This project adheres to [Semantic Versioning](http://semver.org/). +## 3.3.1 (24. March 2023) + ++ [#78](https://github.com/nadar/quill-delta-parser/issues/78) Fixed a bug where lists with empty contents would break all output. + ## 3.3.0 (10. March 2023) + [#77](https://github.com/nadar/quill-delta-parser/pull/77) Allow method chaining for `registerListener()` and `overwriteListener()`. diff --git a/composer.lock b/composer.lock index 0f0c2b4..4cca5b9 100644 --- a/composer.lock +++ b/composer.lock @@ -806,16 +806,16 @@ }, { "name": "phpstan/phpstan", - "version": "1.10.6", + "version": "1.10.7", "source": { "type": "git", "url": "https://github.com/phpstan/phpstan.git", - "reference": "50d089a3e0904b0fe7e2cf2d4fd37d427d64235a" + "reference": "b10ceb526d9607903c5b2673f1fc8775dbe48975" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phpstan/phpstan/zipball/50d089a3e0904b0fe7e2cf2d4fd37d427d64235a", - "reference": "50d089a3e0904b0fe7e2cf2d4fd37d427d64235a", + "url": "https://api.github.com/repos/phpstan/phpstan/zipball/b10ceb526d9607903c5b2673f1fc8775dbe48975", + "reference": "b10ceb526d9607903c5b2673f1fc8775dbe48975", "shasum": "" }, "require": { @@ -844,8 +844,11 @@ "static analysis" ], "support": { + "docs": "https://phpstan.org/user-guide/getting-started", + "forum": "https://github.com/phpstan/phpstan/discussions", "issues": "https://github.com/phpstan/phpstan/issues", - "source": "https://github.com/phpstan/phpstan/tree/1.10.6" + "security": "https://github.com/phpstan/phpstan/security/policy", + "source": "https://github.com/phpstan/phpstan-src" }, "funding": [ { @@ -861,7 +864,7 @@ "type": "tidelift" } ], - "time": "2023-03-09T16:55:12+00:00" + "time": "2023-03-16T15:24:20+00:00" }, { "name": "phpunit/php-code-coverage", diff --git a/src/listener/Lists.php b/src/listener/Lists.php index 80e8dab..f55245e 100644 --- a/src/listener/Lists.php +++ b/src/listener/Lists.php @@ -49,24 +49,33 @@ public function process(Line $line) public function render(Lexer $lexer) { $isOpen = false; + $isEmpty = false; $listTag = null; foreach ($this->picks() as $pick) { $first = $this->getFirstLine($pick); - // while from first to the pick line and store content in buffer - $buffer = null; - $first->while(static function (&$index, Line $line) use (&$buffer, $pick) { - ++$index; - $buffer.= $line->getInput(); - $line->setDone(); - if ($index == $pick->line->getIndex()) { - return false; - } - }); - // defines whether this attribute list element is the last one of a list serie. $isLast = false; + // if this is an empty line .... the first attribute contains the list information, otherwise + // the first line contains content. + if ($first->getAttribute(self::ATTRIBUTE_LIST)) { + $isEmpty = true; + } + + // while from first to the pick line and store content in buffer + $buffer = null; + if (!$isEmpty) { + $first->while(static function (&$index, Line $line) use (&$buffer, $pick) { + ++$index; + $buffer.= $line->getInput(); + $line->setDone(); + if ($index == $pick->line->getIndex()) { + return false; + } + }); + } + // go to the next element with endlinew and check if it contains a list type until then $hasNextInside = false; $pick->line->whileNext(static function (Line $line) use (&$hasNextInside) { @@ -113,19 +122,23 @@ public function render(Lexer $lexer) } }); - $output .= '
  • '; - $output .= $buffer; - - if ($nextIndent > $pick->line->getAttribute('indent', 0)) { - $output .= '<'.$this->getListAttribute($pick).'>'.PHP_EOL; - } elseif ($nextIndent < $pick->line->getAttribute('indent', 0)) { - $output .= '
  • getListAttribute($pick).'>'.PHP_EOL; - $closeGap = $pick->line->getAttribute('indent', 0) - $nextIndent; - if ($closeGap > 1) { - $output .= 'getListAttribute($pick).'>'.PHP_EOL; - } + if ($isEmpty) { + $output .= '
  • '; } else { - $output.= ''.PHP_EOL; + $output .= '
  • '; + $output .= $buffer; + + if ($nextIndent > $pick->line->getAttribute('indent', 0)) { + $output .= '<'.$this->getListAttribute($pick).'>'.PHP_EOL; + } elseif ($nextIndent < $pick->line->getAttribute('indent', 0)) { + $output .= '
  • getListAttribute($pick).'>'.PHP_EOL; + $closeGap = $pick->line->getAttribute('indent', 0) - $nextIndent; + if ($closeGap > 1) { + $output .= 'getListAttribute($pick).'>'.PHP_EOL; + } + } else { + $output.= ''.PHP_EOL; + } } // close the opening OL/UL tag if: diff --git a/tests/Issue53Test.php b/tests/Issue53Test.php index 3a55826..0f39507 100644 --- a/tests/Issue53Test.php +++ b/tests/Issue53Test.php @@ -20,6 +20,6 @@ class Issue53Test extends DeltaTestCase JSON; public $html = <<<'EOT' - +

    Bullet point content

    EOT; } diff --git a/tests/Issue53TestFixedTest.php b/tests/Issue53TestFixedTest.php new file mode 100644 index 0000000..e0b3c3a --- /dev/null +++ b/tests/Issue53TestFixedTest.php @@ -0,0 +1,26 @@ +
  • Bullet point content
  • +EOT; +} diff --git a/tests/Issue78Test.php b/tests/Issue78Test.php new file mode 100644 index 0000000..b493c87 --- /dev/null +++ b/tests/Issue78Test.php @@ -0,0 +1,52 @@ +JUST A LIST


    New title


    +EOT; +} \ No newline at end of file