diff --git a/CHANGELOG.md b/CHANGELOG.md index c562fc4..a1a6f5d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/Tests/Api/BugTest.php b/Tests/Api/BugTest.php index 23e4370..2823a3b 100644 --- a/Tests/Api/BugTest.php +++ b/Tests/Api/BugTest.php @@ -156,8 +156,8 @@ final class BugTest extends \PHPUnit\Framework\TestCase "attributes": { "bold": true, "link": "https://scrumpy.io" - }, - "insert": "link" + }, + "insert": "link" }, { "attributes": { diff --git a/src/Delta/Html/Compound.php b/src/Delta/Html/Compound.php index 5ed58cc..bc53ee4 100644 --- a/src/Delta/Html/Compound.php +++ b/src/Delta/Html/Compound.php @@ -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 + ); + } + } } diff --git a/src/Parser/Html.php b/src/Parser/Html.php index 11bc4e3..700e348 100644 --- a/src/Parser/Html.php +++ b/src/Parser/Html.php @@ -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; @@ -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; }