File tree Expand file tree Collapse file tree 3 files changed +41
-0
lines changed Expand file tree Collapse file tree 3 files changed +41
-0
lines changed Original file line number Diff line number Diff line change @@ -358,6 +358,10 @@ protected function clean($str)
358358 return $ str ;
359359 }
360360
361+ // remove white space before closing tags
362+ $ str = mb_eregi_replace ("'\s+> " , "'> " , $ str );
363+ $ str = mb_eregi_replace ('"\s+> ' , '"> ' , $ str );
364+
361365 // clean out the \n\r
362366 $ replace = ' ' ;
363367 if ($ this ->options ->get ('preserveLineBreaks ' )) {
Original file line number Diff line number Diff line change @@ -295,4 +295,11 @@ public function testMultipleSingleQuotes()
295295 $ dom ->load ("<a title='Ain't this the best' href= \"http://www.example.com \">Hello</a> " );
296296 $ this ->assertEquals ("Ain't this the best " , $ dom ->getElementsByTag ('a ' )[0 ]->title );
297297 }
298+
299+ public function testBeforeClosingTag ()
300+ {
301+ $ dom = new Dom ;
302+ $ dom ->load ("<div class= \"stream-container \" > <div class= \"stream-item js-new-items-bar-container \"> </div> <div class= \"stream \"> " );
303+ $ this ->assertEquals ("<div class= \"stream-container \"> <div class= \"stream-item js-new-items-bar-container \"> </div> <div class= \"stream \"></div></div> " , (string ) $ dom );
304+ }
298305}
Original file line number Diff line number Diff line change 1+ <?php
2+
3+ use PHPHtmlParser \Dom ;
4+
5+ class PreserveLineBreaks extends PHPUnit_Framework_TestCase {
6+
7+ public function testPreserveLineBreakTrue ()
8+ {
9+ $ dom = new Dom ;
10+ $ dom ->setOptions ([
11+ 'preserveLineBreaks ' => true ,
12+ ]);
13+ $ dom ->load ("<div class= \"stream-container \">
14+ <div class= \"stream-item js-new-items-bar-container \"> </div> <div class= \"stream \"> " );
15+
16+ $ this ->assertEquals ("<div class= \"stream-container \"> \n<div class= \"stream-item js-new-items-bar-container \"> </div> <div class= \"stream \"></div></div> " , (string ) $ dom );
17+ }
18+
19+ public function testPreserveLineBreakBeforeClosingTag ()
20+ {
21+ $ dom = new Dom ;
22+ $ dom ->setOptions ([
23+ 'preserveLineBreaks ' => true ,
24+ ]);
25+ $ dom ->load ("<div class= \"stream-container \"
26+ ><div class= \"stream-item js-new-items-bar-container \"> </div> <div class= \"stream \"> " );
27+
28+ $ this ->assertEquals ("<div class= \"stream-container \"><div class= \"stream-item js-new-items-bar-container \"> </div> <div class= \"stream \"></div></div> " , (string ) $ dom );
29+ }
30+ }
You can’t perform that action at this time.
0 commit comments