Repository: nadar/quill-delta-parser (php)

Issue:
background color removed from html result
**Describe the bug**
The option for background color does not get processed.

**The delta code which generates the Problem**
Example:
```
 10 => array:1 [
      "insert" => """
        color.
        This has a 
        """
    ]
    11 => array:2 [
      "attributes" => array:1 [
        "background" => "#a10000"
      ]
      "insert" => "background "
    ]
    12 => array:1 [
      "insert" => """
        color.
        This is a list item
        """
    ]
```
**The expected html output the delta should produce**

Example:

```
This line has <span style="background-color: #0047b2">background</span>color.
```

**Expected behavior**
I expect the text to have a colored background instead of being removed from the result.

**Screenshots**
![image](https://github.com/nadar/quill-delta-parser/assets/4440749/e8e67c0a-12b0-4450-a176-55b227805229)

**Additional context**
```
quill = new Quill('#editor', {
                        placeholder: 'Compose an epic...',
                        modules: {
                            toolbar: [
                                ['bold', 'italic', 'underline', 'link'],
                                [
                                    { color: [ "#000000", "#e60000", "#ff9900", "#ffff00", "#008a00", "#0066cc", "#9933ff", "#ffffff", "#facccc", "#ffebcc", "#ffffcc", "#cce8cc", "#cce0f5", "#ebd6ff", "#bbbbbb", "#f06666", "#ffc266", "#ffff66", "#66b966", "#66a3e0", "#c285ff", "#888888", "#a10000", "#b26b00", "#b2b200", "#006100", "#0047b2", "#6b24b2", "#444444", "#5c0000", "#663d00", "#666600", "#003700", "#002966", "#3d1466", ] },
                                    { background: [ "#000000", "#e60000", "#ff9900", "#ffff00", "#008a00", "#0066cc", "#9933ff", "#ffffff", "#facccc", "#ffebcc", "#ffffcc", "#cce8cc", "#cce0f5", "#ebd6ff", "#bbbbbb", "#f06666", "#ffc266", "#ffff66", "#66b966", "#66a3e0", "#c285ff", "#888888", "#a10000", "#b26b00", "#b2b200", "#006100", "#0047b2", "#6b24b2", "#444444", "#5c0000", "#663d00", "#666600", "#003700", "#002966", "#3d1466", ] }
                                ],
                                [{ list: 'ordered' }, { list: 'bullet' }],
                                ['clean']
                            ]
                        },
                        theme: 'snow'
                    });
```


Pull request:
background plugin
closes #80 

Patch:
diff --git a/CHANGELOG.md b/CHANGELOG.md
index c31d9c2..2dde2e7 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -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.
diff --git a/README.md b/README.md
index 2391f02..dfc97e0 100644
--- a/README.md
+++ b/README.md
@@ -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();
diff --git a/UPGRADE.md b/UPGRADE.md
index c599d87..473fb6d 100644
--- a/UPGRADE.md
+++ b/UPGRADE.md
@@ -2,6 +2,20 @@
 
 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.
@@ -9,4 +23,4 @@ This document will help you upgrading from a version into another. For more deta
 
 ## 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.
\ No newline at end of file
++ [#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.
diff --git a/src/Lexer.php b/src/Lexer.php
index 4650249..bc73294 100644
--- a/src/Lexer.php
+++ b/src/Lexer.php
@@ -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;
@@ -148,6 +149,7 @@ class Lexer
         $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());
diff --git a/src/listener/BackgroundColor.php b/src/listener/BackgroundColor.php
new file mode 100644
index 0000000..a5bfc95
--- /dev/null
+++ b/src/listener/BackgroundColor.php
@@ -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 <basil@nadar.io>
+ * @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>');
+        }
+    }
+}


Test patch:
diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml
index 39f92ea..8551e9a 100644
--- a/.github/workflows/tests.yml
+++ b/.github/workflows/tests.yml
@@ -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 
@@ -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
diff --git a/tests/BackgroundColorTest.php b/tests/BackgroundColorTest.php
new file mode 100644
index 0000000..89fa279
--- /dev/null
+++ b/tests/BackgroundColorTest.php
@@ -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;
+}
diff --git a/tests/Issue55Test.php b/tests/Issue55Test.php
index 0f6be48..d0f2682 100644
--- a/tests/Issue55Test.php
+++ b/tests/Issue55Test.php
@@ -76,7 +76,6 @@ class Issue55Test extends DeltaTestCase
       {
          "attributes":{
             "color":"#2d5c88",
-            "background":"#ffffff",
             "link":"https://www.eyeartsguild.org.uk/"
          },
          "insert":"Eye Arts Guild"
diff --git a/tests/Issue78Test.php b/tests/Issue78Test.php
index b493c87..ac8ab62 100644
--- a/tests/Issue78Test.php
+++ b/tests/Issue78Test.php
@@ -12,8 +12,7 @@ class Issue78Test extends DeltaTestCase
             "insert": "JUST A LIST",
             "attributes": {
                 "bold": true,
-                "color": "#000000",
-                "background": "transparent"
+                "color": "#000000"
             }
         },
         {
@@ -35,8 +34,7 @@ class Issue78Test extends DeltaTestCase
             "insert": "New title",
             "attributes": {
                 "bold": true,
-                "color": "#000000",
-                "background": "transparent"
+                "color": "#000000"
             }
         },
         {