Fix converting of Wordpress messages
authorMarcel Werk <burntime@woltlab.com>
Wed, 20 Jul 2022 11:44:29 +0000 (13:44 +0200)
committerMarcel Werk <burntime@woltlab.com>
Wed, 20 Jul 2022 11:44:29 +0000 (13:44 +0200)
Improved converting of paragraphs and quotes.

files/lib/system/exporter/WordPress3xExporter.class.php

index cc2cea539f58fc98a517f42afd9ae00724432f27..8b72302af315c6f78e0e08051cb945ea8acf44e7 100644 (file)
@@ -4,6 +4,7 @@ namespace wcf\system\exporter;
 
 use wcf\data\article\Article;
 use wcf\system\database\util\PreparedStatementConditionBuilder;
+use wcf\system\html\input\HtmlInputProcessor;
 use wcf\system\importer\ImportHandler;
 use wcf\system\WCF;
 use wcf\util\StringUtil;
@@ -665,8 +666,6 @@ class WordPress3xExporter extends AbstractExporter
      */
     private static function fixMessage($string)
     {
-        $string = \str_replace("\n", "<br />\n", StringUtil::unifyNewlines($string));
-
         // replace media
         $string = \preg_replace_callback(
             '~<img class="([^"]*wp-image-(\d+)[^"]*)".*?>~is',
@@ -702,6 +701,17 @@ class WordPress3xExporter extends AbstractExporter
             $string
         );
 
+        $processor = new HtmlInputProcessor();
+        $processor->process($string, 'com.woltlab.wcf.article.content');
+        $string = $processor->getHtml();
+
+        $string = \str_replace("</p>", "</p><p><br></p>", $string);
+        /* Remove trailing linebreak in quotes */
+        $string = \preg_replace("~<p><br></p>(?=\s*</blockquote>)~", '', $string);
+
+        $string = \str_replace("<blockquote>", "<woltlab-quote>", $string);
+        $string = \str_replace("</blockquote>", "</woltlab-quote>", $string);
+
         return $string;
     }
 }