Skip to content

Commit e1e2c7c

Browse files
stijnsternadar
authored andcommitted
Fixes issues with nadar#30 Issue with multiple ul-li lists where ul-li list contains only one item (nadar#33)
* add failing test case for multiple bulletlists with only one bullet * create an opening ul/ol tag when none have been created before * fix indentation and typo in comments * add failing test case for multiple bulletlists with only one bullet create an opening ul/ol tag when none have been created before fix indentation and typo in comments * improved inline documentation and added a change log entry
1 parent 3454418 commit e1e2c7c

File tree

3 files changed

+91
-7
lines changed

3 files changed

+91
-7
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+
## 2.4.0
8+
9+
+ [#30](https://github.com/nadar/quill-delta-parser/issues/30) List opening tag process has been simplified in order to support single bullet lists.
10+
711
## 2.3.0 (23. October 2019)
812

913
+ Add override functionality to links, allowing to customise their wrapper.

src/listener/Lists.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ public function render(Lexer $lexer)
7575
if ($hasNextInside) {
7676
$isLast = true;
7777
}
78-
78+
7979
$output = null;
8080

8181
// this makes sure that when two list types are after each other (OL and UL)
@@ -85,17 +85,17 @@ public function render(Lexer $lexer)
8585
$isOpen = false;
8686
}
8787

88-
// create the opining OL/UL tag if:
89-
// a. its not already open AND $isLast is false (which means not the last element)
90-
// b. or its the first the pick inside the picked elements list https://github.com/nadar/quill-delta-parser/issues/8
91-
if ((!$isOpen && !$isLast) || (!$isOpen && $pick->isFirst())) {
88+
// create the opening OL/UL tag
89+
// opening tag process has been simplified, see https://github.com/nadar/quill-delta-parser/pull/33
90+
// and https://github.com/nadar/quill-delta-parser/issues/30
91+
if (!$isOpen) {
9292
$output .= '<'.$this->getListAttribute($pick).'>';
9393
$isOpen = true;
9494
}
9595

9696
// write the li element.
9797
$output.= '<li>' . $buffer .'</li>';
98-
98+
9999
// close the opening OL/UL tag if:
100100
// a. its the last element and the tag is opened.
101101
// b. or its the last element in the picked list.
@@ -128,7 +128,7 @@ protected function getListAttribute(Pick $pick)
128128
if ($pick->type == self::LIST_TYPE_BULLET) {
129129
return 'ul';
130130
}
131-
131+
132132
// prevent html injection in case the attribute is user input
133133
throw new Exception('The provided list type "'.$pick->type.'" is not a known list type (ordered or bullet).');
134134
}

tests/ListSingleBulletsTest.php

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
<?php
2+
3+
namespace nadar\quill\tests;
4+
5+
class ListSingleBullets extends DeltaTestCase
6+
{
7+
public $json = <<<'JSON'
8+
[
9+
{
10+
"insert": "line 1\nbullet 1 - 1"
11+
},
12+
{
13+
"attributes": {
14+
"list": "bullet"
15+
},
16+
"insert": "\n"
17+
},
18+
{
19+
"insert": "line 2\nbullet 2 - 1"
20+
},
21+
{
22+
"attributes": {
23+
"list": "bullet"
24+
},
25+
"insert": "\n"
26+
},
27+
{
28+
"insert": "line 3\nbullet 3 - 1"
29+
},
30+
{
31+
"attributes": {
32+
"list": "bullet"
33+
},
34+
"insert": "\n"
35+
},
36+
{
37+
"insert": "line 4\nbullet 4 - 1"
38+
},
39+
{
40+
"attributes": {
41+
"list": "bullet"
42+
},
43+
"insert": "\n"
44+
},
45+
{
46+
"insert": "bullet 4 - 2"
47+
},
48+
{
49+
"attributes": {
50+
"list": "bullet"
51+
},
52+
"insert": "\n"
53+
},
54+
{
55+
"insert": "line 5\n"
56+
}
57+
]
58+
JSON;
59+
60+
public $html = <<<'EOT'
61+
<p>line 1</p>
62+
<ul>
63+
<li>bullet 1 - 1</li>
64+
</ul>
65+
<p>line 2</p>
66+
<ul>
67+
<li>bullet 2 - 1</li>
68+
</ul>
69+
<p>line 3</p>
70+
<ul>
71+
<li>bullet 3 - 1</li>
72+
</ul>
73+
<p>line 4</p>
74+
<ul>
75+
<li>bullet 4 - 1</li>
76+
<li>bullet 4 - 2</li>
77+
</ul>
78+
<p>line 5</p>
79+
EOT;
80+
}

0 commit comments

Comments
 (0)