From 6bab821ca7f4c72236b593d25bc1da44f0760a99 Mon Sep 17 00:00:00 2001 From: Alexander Ebert Date: Thu, 19 Jan 2017 13:05:30 +0100 Subject: [PATCH] Improved `
` linebreak fix

---
 .../node/AbstractHtmlNodeProcessor.class.php     | 16 +++++++++++++---
 1 file changed, 13 insertions(+), 3 deletions(-)

diff --git a/wcfsetup/install/files/lib/system/html/node/AbstractHtmlNodeProcessor.class.php b/wcfsetup/install/files/lib/system/html/node/AbstractHtmlNodeProcessor.class.php
index 8c90684a15..fa7d012de3 100644
--- a/wcfsetup/install/files/lib/system/html/node/AbstractHtmlNodeProcessor.class.php
+++ b/wcfsetup/install/files/lib/system/html/node/AbstractHtmlNodeProcessor.class.php
@@ -76,6 +76,19 @@ abstract class AbstractHtmlNodeProcessor implements IHtmlNodeProcessor {
 		// would conflict with already existing entities when reverting them.
 		@$this->document->loadHTML('' . $html . '');
 		
+		// fix the `
` linebreaks again
+		$pres = $this->document->getElementsByTagName('pre');
+		for ($i = 0, $length = $pres->length; $i < $length; $i++) {
+			/** @var \DOMElement $pre */
+			$pre = $pres[$i];
+			/** @var \DOMNode $node */
+			foreach ($pre->childNodes as $node) {
+				if ($node->nodeType === XML_TEXT_NODE && mb_strpos($node->textContent, '@@@WCF_PRE_LINEBREAK@@@') !== false) {
+					$node->nodeValue = str_replace('@@@WCF_PRE_LINEBREAK@@@', "\n", $node->textContent);
+				}
+			}
+		}
+		
 		$this->nodeData = [];
 	}
 	
@@ -108,9 +121,6 @@ abstract class AbstractHtmlNodeProcessor implements IHtmlNodeProcessor {
 			
 		}
 		
-		// restore line breaks inside code
-		$html = str_replace('@@@WCF_PRE_LINEBREAK@@@', "\n", $html);
-		
 		// work-around for a libxml bug that causes a single space between
 		// some inline elements to be dropped
 		$html = str_replace(' ', ' ', $html);
-- 
2.20.1