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

Commit

Permalink
v3.17.1
Browse files Browse the repository at this point in the history
* Correct CHANGELOG
* Fixed #109 again.
* Override getAttributes in Compound
  • Loading branch information
deanblackborough committed Mar 7, 2019
1 parent 73b8fca commit 0c5eea0
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 9 deletions.
6 changes: 4 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@ Full changelog for PHP Quill Renderer

## v3.17.1 - 2019-03-xx

* Fixed [#117](https://github.com/deanblackborough/php-quill-renderer/issues/117), compounds
deltas not aware they can also be links.
* Fixed [#117](https://github.com/deanblackborough/php-quill-renderer/issues/117), compound
deltas not aware of the fact that they can also be links.
* Fixed [#109](https://github.com/deanblackborough/php-quill-renderer/issues/109) again as it
appears I did not fix it correctly before.

## v3.17.0 - 2019-03-04

Expand Down
4 changes: 2 additions & 2 deletions Tests/Api/BugTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -156,8 +156,8 @@ final class BugTest extends \PHPUnit\Framework\TestCase
"attributes": {
"bold": true,
"link": "https://scrumpy.io"
},
"insert": "link"
},
"insert": "link"
},
{
"attributes": {
Expand Down
18 changes: 18 additions & 0 deletions src/Delta/Html/Compound.php
Original file line number Diff line number Diff line change
Expand Up @@ -150,4 +150,22 @@ public function render(): string

return $this->html;
}

/**
* Override the method to include the link in the attributes array if
* necessary as it will have be striped
*
* @return array
*/
public function getAttributes(): array
{
if ($this->isLink === false) {
return $this->attributes;
} else {
return array_merge(
['link' => $this->link],
$this->attributes
);
}
}
}
20 changes: 15 additions & 5 deletions src/Parser/Html.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,18 +73,20 @@ public function attributeList(array $quill)
array('ordered', 'bullet')
) === true
) {
$insert = $this->deltas[count($this->deltas) - 1]->getInsert();
$attributes = $this->deltas[count($this->deltas) - 1]->getAttributes();
$previous_index = count($this->deltas) - 1;

unset($this->deltas[count($this->deltas) - 1]);
$insert = $this->deltas[$previous_index]->getInsert();
$attributes = $this->deltas[$previous_index]->getAttributes();

unset($this->deltas[$previous_index]);

if (count($attributes) === 0) {
$this->deltas[] = new ListItem($insert, $quill['attributes']);
} else {
$delta = new ListItem("", $quill['attributes']);

foreach ($attributes as $attribute_name => $value) {
switch ($attribute_name) {
if (count($attributes) === 1) {
switch(key($attributes)) {
case Options::ATTRIBUTE_BOLD:
$delta->addChild(new Bold($insert));
break;
Expand Down Expand Up @@ -121,7 +123,15 @@ public function attributeList(array $quill)
default:
break;
}
} else {
$childDelta = new Compound($insert);
foreach ($attributes as $attribute => $value) {
$childDelta->setAttribute($attribute, $value);
}

$delta->addChild($childDelta);
}

$this->deltas[] = $delta;
}

Expand Down

0 comments on commit 0c5eea0

Please sign in to comment.