Skip to content
This repository has been archived by the owner on Sep 18, 2023. It is now read-only.

Commit

Permalink
Merge pull request #90 from deanblackborough/v3.13.1
Browse files Browse the repository at this point in the history
V3.13.1
  • Loading branch information
deanblackborough authored Jun 21, 2018
2 parents 76b70bd + 4f8c2b2 commit a46ff70
Show file tree
Hide file tree
Showing 8 changed files with 135 additions and 8 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@

Full changelog for PHP Quill Renderer

## v3.13.1 - 2018-06-22

* Lists no longer break if a list item contains formatted text, closes #89.
* Initial support for child deltas.

## v3.13.0 - 2018-06-14

* Added video support to HTML and Markdown parsers.
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ Header | Yes | Yes | Yes | Yes
Image | Yes | Yes | Yes | Yes
Video | No | No | Yes | Yes
List | Yes | Yes | Yes | Yes
Child lists | No | No | Planned | Planned
Child lists | No | No | In Development | In Development
Indent/Outdent | No| No | Planned | Planned
Text direction | No | No | Planned | N/A
Color | No | No | Planned | N/K
Expand Down
1 change: 0 additions & 1 deletion phpunit.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
convertWarningsToExceptions="true"
processIsolation="false"
stopOnFailure="false"
syntaxCheck="false"
>
<testsuites>
<testsuite name="tests">
Expand Down
41 changes: 41 additions & 0 deletions src/Delta/Delta.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,47 @@ abstract class Delta implements DeltaInterface
*/
protected $is_last_child = false;

/**
* @var Delta[] $children Child delta objects
*/
protected $children = [];

/**
* Add a child delta
*
* @param Delta $delta
*
* @return void
*/
public function addChild(Delta $delta): void
{
$this->children[] = $delta;
}

/**
* Return the child deltas
*
* @return Delta[]
*/
public function children(): array
{
return array_reverse($this->children);
}

/**
* Does the delta have any children
*
* @return boolean
*/
public function hasChildren(): bool
{
if (count($this->children) > 0) {
return true;
} else {
return false;
}
}

/**
* Is the delta a child?
*
Expand Down
11 changes: 10 additions & 1 deletion src/Delta/Html/ListItem.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,15 @@ public function parentTag(): ?string
*/
public function render(): string
{
return $this->renderSimpleTag($this->tag, $this->insert, true);
$html = "<{$this->tag}>";
if ($this->hasChildren() === true) {

foreach ($this->children() as $child) {
$html .= $child->render();
}
}
$html .= "{$this->insert}</{$this->tag}>\n";

return $html;
}
}
23 changes: 23 additions & 0 deletions src/Interfaces/DeltaInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,29 @@
*/
Interface DeltaInterface
{
/**
* Add a child delta
*
* @param Delta $delta
*
* @return void
*/
public function addChild(Delta $delta): void;

/**
* Return the child deltas
*
* @return Delta[]
*/
public function children(): array;

/**
* Does the delta have any children
*
* @return boolean
*/
public function hasChildren(): bool;

/**
* Is the delta a child?
*
Expand Down
23 changes: 18 additions & 5 deletions src/Parser/Html.php
Original file line number Diff line number Diff line change
Expand Up @@ -240,17 +240,30 @@ public function attributeList(array $quill)
$this->deltas[] = new ListItem($insert, $quill['attributes']);
$this->deltas = array_values($this->deltas);

$index = count($this->deltas) - 1;
$previous_index = $index -1;
$current_index = count($this->deltas) - 1;

for ($i = $current_index - 1; $i >= 0; $i--) {
$this_delta = $this->deltas[$i];
if ($this_delta->displayType() === Delta::DISPLAY_BLOCK || $this_delta->newLine() === true) {
break;
} else {
$this->deltas[$current_index]->addChild($this->deltas[$i]);
unset($this->deltas[$i]);
}
}

$this->deltas = array_values($this->deltas);
$current_index = count($this->deltas) - 1;
$previous_index = $current_index -1;

if ($previous_index < 0) {
$this->deltas[$index]->setFirstChild();
$this->deltas[$current_index]->setFirstChild();
} else {
if ($this->deltas[$previous_index]->isChild() === true) {
$this->deltas[$index]->setLastChild();
$this->deltas[$current_index]->setLastChild();
$this->deltas[$previous_index]->setLastChild(false);
} else {
$this->deltas[$index]->setFirstChild();
$this->deltas[$current_index]->setFirstChild();
}
}
}
Expand Down
37 changes: 37 additions & 0 deletions tests/attributes/html/ListTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,18 @@ final class ListTest extends \PHPUnit\Framework\TestCase
{
private $delta_ordered = '{"ops":[{"insert":"Item 1"},{"attributes":{"list":"ordered"},"insert":"\n"},{"insert":"Item 2"},{"attributes":{"list":"ordered"},"insert":"\n"},{"insert":"Item 3"},{"attributes":{"list":"ordered"},"insert":"\n"}]}';
private $delta_unordered = '{"ops":[{"insert":"Item 1"},{"attributes":{"list":"bullet"},"insert":"\n"},{"insert":"Item 2"},{"attributes":{"list":"bullet"},"insert":"\n"},{"insert":"Item 3"},{"attributes":{"list":"bullet"},"insert":"\n"}]}';
private $delta_list_with_attribute = '{
"ops":[
{"insert":"List item 1"},
{"attributes":{"list":"bullet"},"insert":"\n"},
{"insert":"List "},
{"attributes":{"bold":true},"insert":"item"},
{"insert":" 2"},
{"attributes":{"list":"bullet"},"insert":"\n"},
{"insert":"List item 2"},
{"attributes":{"list":"bullet"},"insert":"\n"}
]
}';

private $expected_ordered = '<ol>
<li>Item 1</li>
Expand All @@ -23,6 +35,11 @@ final class ListTest extends \PHPUnit\Framework\TestCase
<li>Item 1</li>
<li>Item 2</li>
<li>Item 3</li>
</ul>';
private $expected_list_with_attribute = '<ul>
<li>List item 1</li>
<li>List <strong>item</strong> 2</li>
<li>List item 2</li>
</ul>';

/**
Expand Down Expand Up @@ -64,4 +81,24 @@ public function testListBullet()

$this->assertEquals($this->expected_unordered, trim($result), __METHOD__ . ' Unordered list failure');
}

/**
* Unordered list
*
* @return void
* @throws \Exception
*/
public function testListWithAttribute()
{
$result = null;

try {
$quill = new QuillRender($this->delta_list_with_attribute);
$result = $quill->render();
} catch (\Exception $e) {
$this->fail(__METHOD__ . 'failure, ' . $e->getMessage());
}

$this->assertEquals($this->expected_list_with_attribute, trim($result), __METHOD__ . ' Unordered list failure');
}
}

0 comments on commit a46ff70

Please sign in to comment.