diff --git a/CHANGELOG.md b/CHANGELOG.md index a1a6f5d..b49971b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,7 +3,13 @@ Full changelog for PHP Quill Renderer -## v3.17.1 - 2019-03-xx +## v3.17.2 - 2019-03-09 + +* Additional work to fix [#117](https://github.com/deanblackborough/php-quill-renderer/issues/117), +allow through any empty insert, some are valid so for now just render what quill wants, I'll +add strict mode later to remove what I consider to be the redundant inserts. + +## v3.17.1 - 2019-03-07 * Fixed [#117](https://github.com/deanblackborough/php-quill-renderer/issues/117), compound deltas not aware of the fact that they can also be links. diff --git a/README.md b/README.md index 8557415..92b5e47 100644 --- a/README.md +++ b/README.md @@ -18,15 +18,11 @@ supported are listed in the table below, the goal is to eventually support every ## Planned features -The latest update, v3.16.0, took a while, after receiving many bug reports related -to mishandling of newlines I decided to do a minor refactor, mainly splitting the deltas -sooner. I'm hoping that by the v3.17.0 release I'll be done and can then concentrate on new features. - If you check the table below you will note that I don't support all of Quills features, that is definitely the plan, however, before I add support for new attributes I want to add a major new feature. -Plugins +#### Plugins I'm planning to add support for plugins, all the existing features will become plugins, therefore, based on your particular needs you will be able to disable plugins/deltas @@ -37,7 +33,7 @@ the known bugs and completed my planned refactoring I will start work on plugins in the v4 branch. I will continue to support v3 after the eventual release of v4, some features may -be backported, it very much depends on the particular feature. +be back-ported, it very much depends on the particular feature. ## Installation diff --git a/Tests/Api/BugTest.php b/Tests/Api/BugTest.php index 2823a3b..404b2cd 100644 --- a/Tests/Api/BugTest.php +++ b/Tests/Api/BugTest.php @@ -250,6 +250,40 @@ final class BugTest extends \PHPUnit\Framework\TestCase } ] }'; + private $delta_bug_117_links_deltas_with_attributes_take_2 = ' + { + "ops":[ + { + "attributes":{ + "italic":true, + "link":"https://www.amazon.com" + }, + "insert":"Space" + }, + { + "insert":" " + }, + { + "attributes":{ + "bold":true, + "link":"https://www.yahoo.com" + }, + "insert":"removed" + }, + { + "insert":" but shoudn\'t" + }, + { + "attributes":{ + "bold":true + }, + "insert":"." + }, + { + "insert":"\n" + } + ] + }'; private $expected_bug_external_3 = '

Lorem ipsum
@@ -279,7 +313,10 @@ final class BugTest extends \PHPUnit\Framework\TestCase

Some Text.

'; - private $expected_bug_117_links_deltas_with_attributes = '

The quick brown fox jumps over the lazy dog... Spaceremoved. + private $expected_bug_117_links_deltas_with_attributes = '

The quick brown fox jumps over the lazy dog... Space removed. +
+

'; + private $expected_bug_117_links_deltas_with_attributes_take_2 = '

Space removed but shoudn\'t.

'; @@ -407,4 +444,29 @@ public function testLinkDeltasWithAdditionalAttributes() __METHOD__ . ' link output incorrect' ); } + + /** + * Links with attributes not being created correctly, take 2, space issues + * Bug report https://github.com/deanblackborough/php-quill-renderer/issues/117 + * + * @return void + * @throws \Exception + */ + public function testLinkDeltasWithAdditionalAttributesTake2() + { + $result = null; + + try { + $quill = new QuillRender($this->delta_bug_117_links_deltas_with_attributes_take_2); + $result = $quill->render(); + } catch (\Exception $e) { + $this->fail(__METHOD__ . 'failure, ' . $e->getMessage()); + } + + $this->assertEquals( + $this->expected_bug_117_links_deltas_with_attributes_take_2, + trim($result), + __METHOD__ . ' link output incorrect' + ); + } } diff --git a/Tests/Combined/Html/HeaderTest.php b/Tests/Combined/Html/HeaderTest.php index 27cd1ad..1e411c6 100644 --- a/Tests/Combined/Html/HeaderTest.php +++ b/Tests/Combined/Html/HeaderTest.php @@ -14,15 +14,19 @@ final class HeaderTest extends \PHPUnit\Framework\TestCase private $delta_header_then_text = '{"ops":[{"insert":"This is a heading"},{"attributes":{"header":2},"insert":"\n"},{"insert":"\nNow some normal text.\n"}]}'; private $delta_header_then_text_then_header = '{"ops":[{"insert":"This is a heading"},{"attributes":{"header":2},"insert":"\n"},{"insert":"\nNow some normal text.\n\nNow another heading"},{"attributes":{"header":1},"insert":"\n"}]}'; - private $expected_header_then_text = "

This is a heading

-

Now some normal text. + private $expected_header_then_text = '

This is a heading

+


-

"; - private $expected_header_then_text_then_header = "

This is a heading

-

Now some normal text. +Now some normal text. +
+

'; + private $expected_header_then_text_then_header = '

This is a heading

+

+
+Now some normal text.

-

Now another heading

"; +

Now another heading

'; /** * Test a heading then plain text diff --git a/Tests/Combined/Html/ListTest.php b/Tests/Combined/Html/ListTest.php index 16b05f2..75b7903 100644 --- a/Tests/Combined/Html/ListTest.php +++ b/Tests/Combined/Html/ListTest.php @@ -33,7 +33,9 @@ final class ListTest extends \PHPUnit\Framework\TestCase
  • List item 2
  • List item 3
  • -

    This is another paragraph +

    +
    +This is another paragraph

    '; @@ -45,7 +47,9 @@ final class ListTest extends \PHPUnit\Framework\TestCase
  • List item 2
  • List item 3
  • -

    This is another paragraph. +

    +
    +This is another paragraph.

    '; diff --git a/Tests/Combined/Html/MixTest.php b/Tests/Combined/Html/MixTest.php index 9dbb8e1..e79b3e7 100644 --- a/Tests/Combined/Html/MixTest.php +++ b/Tests/Combined/Html/MixTest.php @@ -154,14 +154,22 @@ final class MixTest extends \PHPUnit\Framework\TestCase }'; private $expected_paragraph_after_two_headers = '

    Primary Header

    +

    +
    +

    Secondary header

    -

    A paragraph. +

    +
    +A paragraph.

    '; private $expected_list_and_header = ' +

    +
    +

    And now a HEADER

    '; private $expected_multiple_attributes = "

    Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed efficitur nibh tempor augue lobortis, nec eleifend velit venenatis. Nullam fringilla dui eget lectus mattis tincidunt.
    @@ -169,7 +177,10 @@ final class MixTest extends \PHPUnit\Framework\TestCase private $expected_multiple_unknown_attributes_image = '

    Text 1 assumenda Text 2.

    -

    Text 3.

    '; +

    + +

    +

    Text 3.

    '; /** * Test for issue #64, opening p tag between two opening headers diff --git a/src/Parser/Html.php b/src/Parser/Html.php index 700e348..0b8c27a 100644 --- a/src/Parser/Html.php +++ b/src/Parser/Html.php @@ -309,22 +309,19 @@ public function insert(array $quill) { $insert = $quill['insert']; - if (strlen(trim($insert)) > 0) { - - /** - * @var Delta - */ - $delta = new $this->class_delta_insert($insert, (array_key_exists('attributes', $quill) ? $quill['attributes'] : [])); - - if (preg_match("/[\n]{2,}/", $insert) !== 0) { - $delta->setClose(); - } else { - if (preg_match("/[\n]{1}/", $insert) !== 0) { - $delta->setNewLine(); - } + /** + * @var Delta + */ + $delta = new $this->class_delta_insert($insert, (array_key_exists('attributes', $quill) ? $quill['attributes'] : [])); + + if (preg_match("/[\n]{2,}/", $insert) !== 0) { + $delta->setClose(); + } else { + if (preg_match("/[\n]{1}/", $insert) !== 0) { + $delta->setNewLine(); } - - $this->deltas[] = $delta; } + + $this->deltas[] = $delta; } }