Fixed newlines inside `<pre>` and non-breaking spaces
authorAlexander Ebert <ebert@woltlab.com>
Fri, 13 Jan 2017 13:04:06 +0000 (14:04 +0100)
committerAlexander Ebert <ebert@woltlab.com>
Fri, 13 Jan 2017 13:04:13 +0000 (14:04 +0100)
wcfsetup/install/files/lib/system/html/node/AbstractHtmlNodeProcessor.class.php

index 34f88e3854dcccac6f98f80ddf89cb47146fbf04..8c90684a158dcb4d7f13cee0dab839dfd9e890a5 100644 (file)
@@ -53,9 +53,16 @@ abstract class AbstractHtmlNodeProcessor implements IHtmlNodeProcessor {
                $this->document = new \DOMDocument('1.0', 'UTF-8');
                $this->xpath = null;
                
+               $html = preg_replace_callback('~(<pre[^>]*>)(.*?)(</pre>)~s', function($matches) {
+                       return $matches[1] . preg_replace('~\r?\n~', '@@@WCF_PRE_LINEBREAK@@@', $matches[2]) . $matches[3];
+               }, $html);
+               
                // strip UTF-8 zero-width whitespace
                $html = preg_replace('~\x{200B}~u', '', $html);
                
+               // discard any non-breaking spaces
+               $html = str_replace('&nbsp;', ' ', $html);
+               
                // work-around for a libxml bug that causes a single space between
                // some inline elements to be dropped 
                $html = str_replace('> <', '>&nbsp;<', $html);
@@ -101,6 +108,9 @@ 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('&nbsp;', ' ', $html);