File tree Expand file tree Collapse file tree 2 files changed +38
-7
lines changed
Expand file tree Collapse file tree 2 files changed +38
-7
lines changed Original file line number Diff line number Diff line change @@ -436,7 +436,8 @@ protected function convertPre(&$text)
436436 {
437437 // get the content of PRE element
438438 while (preg_match ('/<pre[^>]*>(.*)<\/pre>/ismU ' , $ text , $ matches )) {
439- $ this ->preContent = $ matches [1 ];
439+ // Replace br tags with newlines to prevent the search-and-replace callback from killing whitespace
440+ $ this ->preContent = preg_replace ('/(<br\b[^>]*>)/i ' , "\n" , $ matches [1 ]);
440441
441442 // Run our defined tags search-and-replace with callback
442443 $ this ->preContent = preg_replace_callback (
Original file line number Diff line number Diff line change 44
55class PreTest extends \PHPUnit_Framework_TestCase
66{
7- public function testPre ()
7+ public function preDataProvider ()
88 {
9- $ html =<<<'EOT'
9+ return array (
10+ 'Basic pre ' => array (
11+ 'html ' => <<<EOT
1012<p>Before</p>
1113<pre>
1214
@@ -17,9 +19,9 @@ public function testPre()
1719
1820</pre>
1921<p>After</p>
20- EOT;
21-
22- $ expected = <<<' EOT'
22+ EOT
23+ ,
24+ ' expected ' => <<<EOT
2325Before
2426
2527Foo bar baz
@@ -28,8 +30,36 @@ public function testPre()
2830
2931After
3032
31- EOT;
33+ EOT
34+ ,
35+ ),
36+ 'br in pre ' => array (
37+ 'html ' => <<<EOT
38+ <pre>
39+ some<br /> indented<br /> text<br /> on<br /> several<br /> lines<br />
40+ </pre>
41+ EOT
42+ ,
43+ 'expected ' => <<<EOT
44+ some
45+ indented
46+ text
47+ on
48+ several
49+ lines
50+
3251
52+ EOT
53+ ,
54+ ),
55+ );
56+ }
57+
58+ /**
59+ * @dataProvider preDataProvider
60+ */
61+ public function testPre ($ html , $ expected )
62+ {
3363 $ html2text = new Html2Text ($ html );
3464 $ this ->assertEquals ($ expected , $ html2text ->getText ());
3565 }
You can’t perform that action at this time.
0 commit comments