Skip to content

Commit

Permalink
background plugin (#81)
Browse files Browse the repository at this point in the history
* background plugin

* changelog and fixed since tag

* upgrade doc

* Update UPGRADE.md

* Update UPGRADE.md

* Update CHANGELOG.md
  • Loading branch information
nadar authored Sep 14, 2023
1 parent 40e21fd commit b6cbc88
Show file tree
Hide file tree
Showing 9 changed files with 93 additions and 9 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ jobs:
fail-fast: false
matrix:
os: [ubuntu-latest]
php: ['7.2', '7.3', '7.4', '8.0', '8.1', '8.2']
php: ['7.2', '7.3', '7.4', '8.0', '8.1', '8.2', '8.3']

steps:
## checkout the repoistory
Expand All @@ -106,7 +106,7 @@ jobs:
## run unit tests
- name: PHP Unit tests for PHP
run: vendor/bin/phpunit --verbose --configuration actions.phpunit.xml
if: matrix.php == '8.2' || matrix.php == '8.1' || matrix.php == '8.0' || matrix.php == '7.4' || matrix.php == '7.3' || matrix.php == '7.2'
if: matrix.php == '8.3' || matrix.php == '8.2' || matrix.php == '8.1' || matrix.php == '8.0' || matrix.php == '7.4' || matrix.php == '7.3' || matrix.php == '7.2'

## unit test with coverage
- name: PHP Unit tests for PHP 7.2
Expand Down
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@ All notable changes to this project will be documented in this file.

This project adheres to [Semantic Versioning](http://semver.org/).

## 3.4.0 ()

> Please be aware that this release may impact the way Quill data is displayed in your frontend. Checkout the [upgrade document](UPGRADE.md) for more details.
+ [#80](https://github.com/nadar/quill-delta-parser/issues/80) Add missing background color listener (In this update, we have introduced a change where background color information from Quill JSON is now extracted and applied as the background color. This change may result in unexpected behavior if you had background color information present in your documents but it was not rendered correctly in previous versions. see [upgrade document](UPGRADE.md)

## 3.3.1 (24. March 2023)

+ [#78](https://github.com/nadar/quill-delta-parser/issues/78) Fixed a bug where lists with empty contents would break all output.
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ Certain listeners (image, video, color) produce a HTML output which maybe not su
$image = new Image();
$image->wrapper = '<img src="{src}" class="my-image" />';

// override the default plugin from the lexer:
// override the default listener behavior for image color:
$lexer = new Lexer($json);
$lexer->registerListener($image);
echo $lexer->render();
Expand Down
16 changes: 15 additions & 1 deletion UPGRADE.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,25 @@

This document will help you upgrading from a version into another. For more detailed informations about the breaking changes **click the issue detail link**, there you can see examples of how to change your code.

## from 3.3.x to 3.4

+ [#80](https://github.com/nadar/quill-delta-parser/issues/80) In this update, we have introduced a change where background color information from Quill JSON is now extracted and applied as the background color. This change may result in unexpected behavior if you had background color information present in your documents but it was not rendered correctly in previous versions. To restore the previous behavior and resolve any unexpected issues related to background color rendering, please follow these steps:

```php
$backgroundColor = new BackgroundColor();
$backgroundColor->ignore = true;

// override the default listener behavior for background color:
$lexer = new Lexer($json);
$lexer->registerListener($backgroundColor);
echo $lexer->render();
```

## from 2.x to 3.0

+ [#61](https://github.com/nadar/quill-delta-parser/pull/61) PHP 7.1 is official dropped in unit tests. The code should still work with PHP 7.1 until next major release.
+ [#60](https://github.com/nadar/quill-delta-parser/pull/60) Changed the behavior of `nadar\quill\listener\Link`. Property `$wrapper` has been removed and replaced by `$wrapperOpen`, `$wrapperMiddle` and `$wrapperClose`. If you are not overriding or have a customized setup the `Link` listenere, upgrading is safe.

## from 1.x to 2.0

+ [#18](https://github.com/nadar/quill-delta-parser/issues/18) The input values from are now safely encoded by default. This might be a problem when using script or other raw html code inside your text(quill delta). To achieve the same output as behavior as before set `$lexer->escapeInput = false`. This will turn off input encoding but is not recommend.
+ [#18](https://github.com/nadar/quill-delta-parser/issues/18) The input values from are now safely encoded by default. This might be a problem when using script or other raw html code inside your text(quill delta). To achieve the same output as behavior as before set `$lexer->escapeInput = false`. This will turn off input encoding but is not recommend.
2 changes: 2 additions & 0 deletions src/Lexer.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace nadar\quill;

use nadar\quill\listener\Align;
use nadar\quill\listener\BackgroundColor;
use nadar\quill\listener\Blockquote;
use nadar\quill\listener\Bold;
use nadar\quill\listener\CodeBlock;
Expand Down Expand Up @@ -148,6 +149,7 @@ public function loadBuiltinListeners()
$this->registerListener(new Bold());
$this->registerListener(new Italic());
$this->registerListener(new Color());
$this->registerListener(new BackgroundColor());
$this->registerListener(new Link());
$this->registerListener(new Video());
$this->registerListener(new Strike());
Expand Down
31 changes: 31 additions & 0 deletions src/listener/BackgroundColor.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php

namespace nadar\quill\listener;

use nadar\quill\InlineListener;
use nadar\quill\Line;

/**
* Convert background color attributes into span tag.
*
* @author Basil Suter <[email protected]>
* @since 3.4.0
*/
class BackgroundColor extends InlineListener
{
/**
* @var boolean If ignore is enabled, the colors won't apply. This can be use full if coloring is disabled in your quill editor
* but people copy past content from somewhere else which will then generate the color attribute.
*/
public $ignore = false;

/**
* {@inheritDoc}
*/
public function process(Line $line)
{
if (($color = $line->getAttribute('background'))) {
$this->updateInput($line, $this->ignore ? $line->getInput() : '<span style="background-color:'.$line->getLexer()->escape($color).'">'.$line->getInput().'</span>');
}
}
}
34 changes: 34 additions & 0 deletions tests/BackgroundColorTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?php
namespace nadar\quill\tests;

class BackgroundColorTest extends DeltaTestCase
{
public $json = <<<'JSON'
{
"ops": [
{
"attributes": {
"background": "#000000"
},
"insert": "xyz"
},
{
"insert": "\n"
},
{
"attributes": {
"background": "#fff"
},
"insert": "xyz"
},
{
"insert": "\n"
}
]
}
JSON;

public $html = <<<'EOT'
<p><span style="background-color:#000000">xyz</span></p><p><span style="background-color:#fff">xyz</span></p>
EOT;
}
1 change: 0 additions & 1 deletion tests/Issue55Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,6 @@ class Issue55Test extends DeltaTestCase
{
"attributes":{
"color":"#2d5c88",
"background":"#ffffff",
"link":"https://www.eyeartsguild.org.uk/"
},
"insert":"Eye Arts Guild"
Expand Down
6 changes: 2 additions & 4 deletions tests/Issue78Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@ class Issue78Test extends DeltaTestCase
"insert": "JUST A LIST",
"attributes": {
"bold": true,
"color": "#000000",
"background": "transparent"
"color": "#000000"
}
},
{
Expand All @@ -35,8 +34,7 @@ class Issue78Test extends DeltaTestCase
"insert": "New title",
"attributes": {
"bold": true,
"color": "#000000",
"background": "transparent"
"color": "#000000"
}
},
{
Expand Down

0 comments on commit b6cbc88

Please sign in to comment.