[REF] dev/core#3676 Add in html2text/html2text to replace usage of roundcube's versio...
authorSeamus Lee <seamuslee001@gmail.com>
Fri, 8 Jul 2022 05:52:21 +0000 (15:52 +1000)
committerSeamus Lee <seamuslee001@gmail.com>
Fri, 8 Jul 2022 05:52:21 +0000 (15:52 +1000)
CRM/Utils/String.php
composer.json
composer.lock
tests/phpunit/CRM/Utils/HtmlToTextTest.php

index 939ad2270adc7612929c7a31920177ec032770aa..93e96d05e05fd0cdf95d6440acf6136f5067c9ae 100644 (file)
@@ -437,10 +437,9 @@ class CRM_Utils_String {
    *   the converted string
    */
   public static function htmlToText($html) {
-    require_once 'html2text/rcube_html2text.php';
     $token_html = preg_replace('!\{([a-z_.]+)\}!i', 'token:{$1}', $html);
-    $converter = new rcube_html2text($token_html);
-    $token_text = $converter->get_text();
+    $converter = new \Html2Text\Html2Text($token_html, ['do_links' => 'table', 'width' => 75]);
+    $token_text = $converter->getText();
     $text = preg_replace('!token\:\{([a-z_.]+)\}!i', '{$1}', $token_text);
     return $text;
   }
index 58744d1822b50811143d78b278d8b6b26c8f3178..a3fb831692e3bce382c2d276ede64145dfe441eb 100644 (file)
@@ -93,7 +93,8 @@
     "ext-json": "*",
     "ezyang/htmlpurifier": "^4.13",
     "phpoffice/phpspreadsheet": "^1.18",
-    "symfony/polyfill-php73": "^1.23"
+    "symfony/polyfill-php73": "^1.23",
+    "html2text/html2text": "^4.3.1"
   },
   "scripts": {
     "post-install-cmd": [
       "adrienrn/php-mimetyper": {
         "Update gitignore to ensure that sites that manage via git don't miss out on the important db.json file": "https://patch-diff.githubusercontent.com/raw/adrienrn/php-mimetyper/pull/15.patch"
       },
+      "html2text/html2text": {
+        "Fix deprecation warning in php8.1 on html_entity_decode": "https://raw.githubusercontent.com/civicrm/civicrm-core/e758d20e9f613ca6c4cf652c23d2cd7e5d3af3ce/tools/scripts/composer/html2text_html2_text_php81_deprecation.patch"
+      },
       "pear/db": {
         "Apply CiviCRM Customisations for the pear:db package": "https://raw.githubusercontent.com/civicrm/civicrm-core/2ad420c394/tools/scripts/composer/pear_db_civicrm_changes.patch"
       },
index b84070d88f25201d9e05b02185275eba0fe3b57d..e2a62b99d829fc2833e2c7f0a2ad7dd6559faa45 100644 (file)
@@ -4,7 +4,7 @@
         "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
         "This file is @generated automatically"
     ],
-    "content-hash": "619a88e88f80e415abfc58a76082e9f5",
+    "content-hash": "6f116bb2d3eca13dde70ec793930d91f",
     "packages": [
         {
             "name": "adrienrn/php-mimetyper",
             ],
             "time": "2022-06-20T21:43:03+00:00"
         },
+        {
+            "name": "html2text/html2text",
+            "version": "4.3.1",
+            "source": {
+                "type": "git",
+                "url": "https://github.com/mtibben/html2text.git",
+                "reference": "61ad68e934066a6f8df29a3d23a6460536d0855c"
+            },
+            "dist": {
+                "type": "zip",
+                "url": "https://api.github.com/repos/mtibben/html2text/zipball/61ad68e934066a6f8df29a3d23a6460536d0855c",
+                "reference": "61ad68e934066a6f8df29a3d23a6460536d0855c",
+                "shasum": ""
+            },
+            "require-dev": {
+                "phpunit/phpunit": "~4"
+            },
+            "suggest": {
+                "ext-mbstring": "For best performance",
+                "symfony/polyfill-mbstring": "If you can't install ext-mbstring"
+            },
+            "type": "library",
+            "autoload": {
+                "psr-4": {
+                    "Html2Text\\": [
+                        "src/",
+                        "test/"
+                    ]
+                }
+            },
+            "notification-url": "https://packagist.org/downloads/",
+            "license": [
+                "GPL-2.0-or-later"
+            ],
+            "description": "Converts HTML to formatted plain text",
+            "support": {
+                "issues": "https://github.com/mtibben/html2text/issues",
+                "source": "https://github.com/mtibben/html2text/tree/4.3.1"
+            },
+            "time": "2020-04-16T23:44:31+00:00"
+        },
         {
             "name": "laminas/laminas-escaper",
             "version": "2.6.1",
index b7cef8c3d212cda94ccb2de0b37ac649e0f396ef..b895ed4fa77e5c0b9edefc49dff6496dab9d2031 100644 (file)
@@ -56,8 +56,8 @@ class CRM_Utils_HtmlToTextTest extends CiviUnitTestCase {
   public function testHtmlToText($html, $text) {
     $output = CRM_Utils_String::htmlToText($html);
     $this->assertEquals(
-      trim($output),
       trim($text),
+      trim($output),
       "Text Output did not match for $html"
     );
   }