@@ -182,6 +182,40 @@ describe('html-to-text', function () {
182182 expect ( convert ( html , { preserveNewlines : true } ) ) . to . equal ( expected ) ;
183183 } ) ;
184184
185+ it ( 'should produce equal results regardless of newline position between blocks' , function ( ) {
186+ const newlineOutside = '<p>A</p>\n<p>B</p>' ;
187+ const newlineInside = '<p>A</p><p>\nB</p>' ;
188+ const r1 = convert ( newlineOutside , { preserveNewlines : true } ) ;
189+ const r2 = convert ( newlineInside , { preserveNewlines : true } ) ;
190+ expect ( r1 ) . to . equal ( r2 ) ;
191+ } ) ;
192+
193+ it ( 'should produce equal results for preserved newlines and BR tags' , function ( ) {
194+ const nlHtml = '<p>A</p>\n<p>B</p><p>\nC</p>' ;
195+ const brHtml = '<p>A</p><br/><p>B</p><p><br/>C</p>' ;
196+ const nlResult = convert ( nlHtml , { preserveNewlines : true } ) ;
197+ const brResult = convert ( brHtml ) ;
198+ expect ( nlResult ) . to . equal ( brResult ) ;
199+ } ) ;
200+
201+ it ( 'should account for trailing/leading linebreaks of adjacent blocks equally' , function ( ) {
202+ const html = '<p>A</p>\n<div>B</div>\n<div>C</div>\n<p>D</p>' ;
203+ const newlineInside = 'A\n\n\nB\n\nC\n\n\nD' ;
204+ expect ( convert ( html , { preserveNewlines : true } ) ) . to . equal ( newlineInside ) ;
205+ } ) ;
206+
207+ it ( 'should work with multiple linebreaks and in presence of whitespaces' , function ( ) {
208+ const html = '<p>A</p> \n \n <p>B</p>' ;
209+ const newlineInside = 'A\n\n\n\nB' ;
210+ expect ( convert ( html , { preserveNewlines : true } ) ) . to . equal ( newlineInside ) ;
211+ } ) ;
212+
213+ it ( 'should have no special behavior in presence of words among linebreaks' , function ( ) {
214+ const html = '<p>A</p> \n B \n <p>C</p>' ;
215+ const newlineInside = 'A\n\n\nB\n\n\nC' ;
216+ expect ( convert ( html , { preserveNewlines : true } ) ) . to . equal ( newlineInside ) ;
217+ } ) ;
218+
185219 } ) ;
186220
187221 describe ( 'unicode and html entities' , function ( ) {
0 commit comments