]> git.mxchange.org Git - friendica.git/blobdiff - src/Content/Text/HTML.php
Merge pull request #10493 from annando/api
[friendica.git] / src / Content / Text / HTML.php
index c77b84db8ab47a485f7219cdea899c2dfc673d11..51515137e56ddd00f3d576e93f4998b7652bf025 100644 (file)
@@ -1,6 +1,6 @@
 <?php
 /**
- * @copyright Copyright (C) 2020, Friendica
+ * @copyright Copyright (C) 2010-2021, the Friendica project
  *
  * @license GNU AGPL version 3 or any later version
  *
@@ -605,6 +605,10 @@ class HTML
                // Collecting all links
                $urls = self::collectURLs($message);
 
+               if (empty($message)) {
+                       return '';
+               }
+
                @$doc->loadHTML($message, LIBXML_HTML_NODEFDTD);
 
                self::tagToBBCode($doc, 'html', [], '', '');
@@ -1003,20 +1007,26 @@ class HTML
                        '_blank' => true,
                ]);
 
-               /* Uncomment to debug HTMLPurifier behavior
-               $config->set('Core.CollectErrors', true);
-               $config->set('Core.MaintainLineNumbers', true);
-               */
+               $config->set('AutoFormat.RemoveEmpty.Predicate', [
+                       'colgroup' => [],        // |
+                       'th'       => [],        // |
+                       'td'       => [],        // |
+                       'iframe'   => ['src'],   // ↳ Default HTMLPurify values
+                       'i'        => ['class'], // Allows forkawesome icons
+               ]);
+
+               // Uncomment to debug HTMLPurifier behavior
+               //$config->set('Core.CollectErrors', true);
+               //$config->set('Core.MaintainLineNumbers', true);
 
                $HTMLPurifier = new \HTMLPurifier($config);
 
                $text = $HTMLPurifier->purify($text);
 
                /** @var \HTMLPurifier_ErrorCollector $errorCollector */
-               /* Uncomment to debug HTML Purifier behavior
-               $errorCollector = $HTMLPurifier->context->get('ErrorCollector');
-               var_dump($errorCollector->getRaw());
-               */
+               // Uncomment to debug HTML Purifier behavior
+               //$errorCollector = $HTMLPurifier->context->get('ErrorCollector');
+               //var_dump($errorCollector->getRaw());
 
                return $text;
        }