Skip to content

Commit 40e21fd

Browse files
authored
prepare test for issue #78 (#79)
* prepare test for issue #78 * handle empty line, fix wrong test from issue #53 * changelog
1 parent ea08502 commit 40e21fd

File tree

6 files changed

+128
-30
lines changed

6 files changed

+128
-30
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@ All notable changes to this project will be documented in this file.
44

55
This project adheres to [Semantic Versioning](http://semver.org/).
66

7+
## 3.3.1 (24. March 2023)
8+
9+
+ [#78](https://github.com/nadar/quill-delta-parser/issues/78) Fixed a bug where lists with empty contents would break all output.
10+
711
## 3.3.0 (10. March 2023)
812

913
+ [#77](https://github.com/nadar/quill-delta-parser/pull/77) Allow method chaining for `registerListener()` and `overwriteListener()`.

composer.lock

Lines changed: 9 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/listener/Lists.php

Lines changed: 36 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -49,24 +49,33 @@ public function process(Line $line)
4949
public function render(Lexer $lexer)
5050
{
5151
$isOpen = false;
52+
$isEmpty = false;
5253
$listTag = null;
5354
foreach ($this->picks() as $pick) {
5455
$first = $this->getFirstLine($pick);
5556

56-
// while from first to the pick line and store content in buffer
57-
$buffer = null;
58-
$first->while(static function (&$index, Line $line) use (&$buffer, $pick) {
59-
++$index;
60-
$buffer.= $line->getInput();
61-
$line->setDone();
62-
if ($index == $pick->line->getIndex()) {
63-
return false;
64-
}
65-
});
66-
6757
// defines whether this attribute list element is the last one of a list serie.
6858
$isLast = false;
6959

60+
// if this is an empty line .... the first attribute contains the list information, otherwise
61+
// the first line contains content.
62+
if ($first->getAttribute(self::ATTRIBUTE_LIST)) {
63+
$isEmpty = true;
64+
}
65+
66+
// while from first to the pick line and store content in buffer
67+
$buffer = null;
68+
if (!$isEmpty) {
69+
$first->while(static function (&$index, Line $line) use (&$buffer, $pick) {
70+
++$index;
71+
$buffer.= $line->getInput();
72+
$line->setDone();
73+
if ($index == $pick->line->getIndex()) {
74+
return false;
75+
}
76+
});
77+
}
78+
7079
// go to the next element with endlinew and check if it contains a list type until then
7180
$hasNextInside = false;
7281
$pick->line->whileNext(static function (Line $line) use (&$hasNextInside) {
@@ -113,19 +122,23 @@ public function render(Lexer $lexer)
113122
}
114123
});
115124

116-
$output .= '<li>';
117-
$output .= $buffer;
118-
119-
if ($nextIndent > $pick->line->getAttribute('indent', 0)) {
120-
$output .= '<'.$this->getListAttribute($pick).'>'.PHP_EOL;
121-
} elseif ($nextIndent < $pick->line->getAttribute('indent', 0)) {
122-
$output .= '</li></'.$this->getListAttribute($pick).'></li>'.PHP_EOL;
123-
$closeGap = $pick->line->getAttribute('indent', 0) - $nextIndent;
124-
if ($closeGap > 1) {
125-
$output .= '</'.$this->getListAttribute($pick).'></li>'.PHP_EOL;
126-
}
125+
if ($isEmpty) {
126+
$output .= '<li></li>';
127127
} else {
128-
$output.= '</li>'.PHP_EOL;
128+
$output .= '<li>';
129+
$output .= $buffer;
130+
131+
if ($nextIndent > $pick->line->getAttribute('indent', 0)) {
132+
$output .= '<'.$this->getListAttribute($pick).'>'.PHP_EOL;
133+
} elseif ($nextIndent < $pick->line->getAttribute('indent', 0)) {
134+
$output .= '</li></'.$this->getListAttribute($pick).'></li>'.PHP_EOL;
135+
$closeGap = $pick->line->getAttribute('indent', 0) - $nextIndent;
136+
if ($closeGap > 1) {
137+
$output .= '</'.$this->getListAttribute($pick).'></li>'.PHP_EOL;
138+
}
139+
} else {
140+
$output.= '</li>'.PHP_EOL;
141+
}
129142
}
130143

131144
// close the opening OL/UL tag if:

tests/Issue53Test.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,6 @@ class Issue53Test extends DeltaTestCase
2020
JSON;
2121

2222
public $html = <<<'EOT'
23-
<ul><li>Bullet point content</li></ul>
23+
<ul><li></li></ul><p>Bullet point content</p>
2424
EOT;
2525
}

tests/Issue53TestFixedTest.php

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?php
2+
namespace nadar\quill\tests;
3+
4+
class Issue53TestFixedTest extends DeltaTestCase
5+
{
6+
public $json = <<<'JSON'
7+
{"ops":[
8+
{
9+
"insert": "Bullet point content"
10+
},
11+
{
12+
"attributes": {
13+
"list": {
14+
"depth": 0,
15+
"type": "bullet"
16+
}
17+
},
18+
"insert": "\n"
19+
}
20+
]}
21+
JSON;
22+
23+
public $html = <<<'EOT'
24+
<ul><li>Bullet point content</li></ul>
25+
EOT;
26+
}

tests/Issue78Test.php

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
<?php
2+
3+
namespace nadar\quill\tests;
4+
5+
class Issue78Test extends DeltaTestCase
6+
{
7+
public $json = <<<'JSON'
8+
{
9+
"ops":
10+
[
11+
{
12+
"insert": "JUST A LIST",
13+
"attributes": {
14+
"bold": true,
15+
"color": "#000000",
16+
"background": "transparent"
17+
}
18+
},
19+
{
20+
"insert": "\n",
21+
"attributes": {
22+
"align": "center"
23+
}
24+
},
25+
{
26+
"insert": "\n\n",
27+
"attributes": {
28+
"list": "ordered"
29+
}
30+
},
31+
{
32+
"insert": "\n"
33+
},
34+
{
35+
"insert": "New title",
36+
"attributes": {
37+
"bold": true,
38+
"color": "#000000",
39+
"background": "transparent"
40+
}
41+
},
42+
{
43+
"insert": "\n\n"
44+
}
45+
]
46+
}
47+
JSON;
48+
49+
public $html = <<<'EOT'
50+
<p style="text-align: center;"><span style="color:#000000"><strong>JUST A LIST</strong></span></p><ol><li></li><li></li></ol><p><br></p><p><span style="color:#000000"><strong>New title</strong></span></p><p><br></p>
51+
EOT;
52+
}

0 commit comments

Comments
 (0)