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 #116 from deanblackborough/v3.17.0
Browse files Browse the repository at this point in the history
v3.17.0
  • Loading branch information
deanblackborough authored Mar 4, 2019
2 parents 68cb793 + 77a8ad8 commit 859bd43
Show file tree
Hide file tree
Showing 17 changed files with 479 additions and 216 deletions.
14 changes: 14 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,20 @@

Full changelog for PHP Quill Renderer

## v3.17.0 - 2019-03-04

* Handle custom color attribute in a better way, assign to style attribute if sensible,
thank you [Alex](https://github.com/AlexFence). Accepted PR as is, only handles colour,
will extend feature in v3.18.0.
* Fixed [#108](https://github.com/deanblackborough/php-quill-renderer/issues/108),
links within headers not correctly rendering, headers now support child deltas.
* Fixed [#109](https://github.com/deanblackborough/php-quill-renderer/issues/109),
not correctly closing paragraphs or detecting list type change.
* Removed the `ParserSplitInterface` interface, no use anymore.
* Changed which class implements `ParserAttributeInterface` interface.
* Removed redundant methods from parsers.
* Code formatting and comment corrections.

## v3.16.0 - 2019-02-28

* Reworked the parser, split deltas much sooner to try and simplify some of the later logic.
Expand Down
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,9 @@ for use under the MIT License (MIT).
* [raphaelsaunier](https://github.com/raphaelsaunier) [Issue #87] - Newlines proceeding inserts ignored, bug location.
* [Basil](https://github.com/nadar) [Issue #101] - Newline only inserts being ignored by parser.
* [Lee Hesselden](https://github.com/on2) [PR #104] - Color delta to allowing spans with a style:color="#xxx" definition. (Feature will be extended by [Issue #106])
* [Alex](https://github.com/AlexFence) [PR112] - Custom attributes assigned to style attribute if sensible.
* [davidraijmakers](https://github.com/davidraijmakers) [#Issue #108] - Children not supported with headers.
* [philippkuehn](https://github.com/philippkuehn) [#Issue #109] - Multiple list output incorrect and paragraphs not being closed.

## Coding standard credit

Expand Down
266 changes: 264 additions & 2 deletions Tests/Api/BugTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,202 @@
final class BugTest extends \PHPUnit\Framework\TestCase
{
private $delta_bug_external_3 = '{"ops":[{"insert":"Lorem ipsum\nLorem ipsum\n\nLorem ipsum\n"}]}';
private $delta_bug_108_link_within_header = '
{
"ops":[
{
"insert":"This is a "
},
{
"attributes":{
"link":"https://link.com"
},
"insert":"header"
},
{
"insert":", it has a link within it."
},
{
"attributes":{
"header":2
},
"insert":"\n"
}
]
}';
private $delta_bug_108_link_end_of_header = '
{
"ops":[
{
"insert":"This is a header, with a link at the "
},
{
"attributes":{
"link":"https://link.com"
},
"insert":"end"
},
{
"attributes":{
"header":2
},
"insert":"\n"
}
]
}';
private $delta_bug_109_list_outout_incorrect = '
{
"ops": [
{
"insert": "Headline 1"
},
{
"attributes": {
"header": 1
},
"insert": "\n"
},
{
"insert": "Some text. "
},
{
"attributes": {
"bold": true
},
"insert": "Bold Text"
},
{
"insert": ". "
},
{
"attributes": {
"italic": true
},
"insert": "Italic Text"
},
{
"insert": ". "
},
{
"attributes": {
"italic": true,
"bold": true
},
"insert": "Bold and italic Text"
},
{
"insert": ". Here is a "
},
{
"attributes": {
"link": "https://scrumpy.io"
},
"insert": "Link"
},
{
"insert": ". \nHeadline 2"
},
{
"attributes": {
"header": 2
},
"insert": "\n"
},
{
"insert": "ordered list item"
},
{
"attributes": {
"list": "ordered"
},
"insert": "\n"
},
{
"insert": "ordered list item"
},
{
"attributes": {
"list": "ordered"
},
"insert": "\n"
},
{
"insert": "ordered list item"
},
{
"attributes": {
"list": "ordered"
},
"insert": "\n"
},
{
"insert": "unordered list item"
},
{
"attributes": {
"list": "bullet"
},
"insert": "\n"
},
{
"insert": "unordered list item with "
},
{
"attributes": {
"bold": true,
"link": "https://scrumpy.io"
},
"insert": "link"
},
{
"attributes": {
"list": "bullet"
},
"insert": "\n"
},
{
"insert": "unordered list item"
},
{
"attributes": {
"list": "bullet"
},
"insert": "\n"
},
{
"insert": "Some Text.\n"
}
]
}';

private $expected_bug_external_3 = "<p>Lorem ipsum
private $expected_bug_external_3 = '<p>Lorem ipsum
<br />
Lorem ipsum
</p>
<p>Lorem ipsum
<br />
</p>";
</p>';
private $expected_bug_108_link_within_header = '<h2>This is a <a href="https://link.com">header</a>, it has a link within it.</h2>';
private $expected_bug_108_link_end_of_header = '<h2>This is a header, with a link at the <a href="https://link.com">end</a></h2>';
private $expected_bug_109_list_outout_incorrect = '<h1>Headline 1</h1>
<p>Some text. <strong>Bold Text</strong>. <em>Italic Text</em>. <em><strong>Bold and italic Text</strong></em>. Here is a <a href="https://scrumpy.io">Link</a>.
<br />
</p>
<h2>Headline 2</h2>
<ol>
<li>ordered list item</li>
<li>ordered list item</li>
<li>ordered list item</li>
</ol>
<ul>
<li>unordered list item</li>
<li>unordered list item with <a href="https://scrumpy.io">link</a><strong>link</strong></li>
<li>unordered list item</li>
</ul>
<p>Some Text.
<br />
</p>';

/**
* Newlines still proving to be an issue
Expand All @@ -46,4 +233,79 @@ public function testNewlinesNotGeneratingNewParagraph()
__METHOD__ . ' newline issues, no new paragraph'
);
}

/**
* Link within a header
* Bug report https://github.com/deanblackborough/php-quill-renderer/issues/108
*
* @return void
* @throws \Exception
*/
public function testLinkWithinAHeader()
{
$result = null;

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

$this->assertEquals(
$this->expected_bug_108_link_within_header,
trim($result),
__METHOD__ . ' link with header'
);
}

/**
* Link at the end of a header
* Bug report https://github.com/deanblackborough/php-quill-renderer/issues/108
*
* @return void
* @throws \Exception
*/
public function testLinkAtEndOfHeader()
{
$result = null;

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

$this->assertEquals(
$this->expected_bug_108_link_end_of_header,
trim($result),
__METHOD__ . ' link at end of header'
);
}

/**
* Link at the end of a header
* Bug report https://github.com/deanblackborough/php-quill-renderer/issues/108
*
* @return void
* @throws \Exception
*/
public function testIncorrectListOutput()
{
$result = null;

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

$this->assertEquals(
$this->expected_bug_109_list_outout_incorrect,
trim($result),
__METHOD__ . ' list output incorrect'
);
}
}
29 changes: 29 additions & 0 deletions Tests/Combined/Html/BoldColorTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php

namespace DBlackborough\Quill\Tests\Attributes\Html;

require __DIR__ . '../../../../vendor/autoload.php';

use DBlackborough\Quill\Render as QuillRender;

final class BoldColorTest extends \PHPUnit\Framework\TestCase
{
private $delta_bold_text = '{"ops":[{"attributes":{"color":"#66b966","bold":true},"insert":"My Text"}]}';

private $expected_href = '<p><strong style="color: #66b966">My Text</strong></p>';

public function testBoldColor()
{
$result = null;

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

$this->assertEquals($this->expected_href, trim($result), __METHOD__ . ' BoldColorText');
}
}

24 changes: 24 additions & 0 deletions src/Delta/Delta.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,20 @@ public function hasChildren(): bool
}
}

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

/**
* Is the delta a child?
*
Expand Down Expand Up @@ -164,6 +178,16 @@ public function setLastChild(bool $value = true): Delta
return $this;
}

/**
* Set the insert string
*
* @param string $insert
*/
public function setInsert(string $insert)
{
$this->insert = $insert;
}

/**
* Escape the given insert string
*
Expand Down
6 changes: 5 additions & 1 deletion src/Delta/Html/Compound.php
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,11 @@ public function render(): string

$element_attributes = '';
foreach ($this->element_attributes as $attribute => $value) {
$element_attributes .= "{$attribute}=\"{$value}\" ";
if ($attribute == "color") {
$element_attributes .= "style=\"{$attribute}: $value\"";
} else {
$element_attributes .= "{$attribute}=\"{$value}\" ";
}
}

foreach ($this->tags as $i => $tag) {
Expand Down
Loading

0 comments on commit 859bd43

Please sign in to comment.