@@ -275,7 +275,7 @@ protected function mergeReplaceLines(string $oldLine, string $newLine): string
275
275
);
276
276
}
277
277
278
- return \str_replace ([ "\r\n" , "\r" , "\n" ], ' <br> ' , $ mergedLine );
278
+ return $ this -> fixReplaceLineHtml ( $ mergedLine );
279
279
}
280
280
281
281
/**
@@ -391,4 +391,36 @@ protected function fixLinesForNoClosure(array &$lines, array $closures): void
391
391
}
392
392
}
393
393
}
394
+
395
+ /**
396
+ * Perform some special fixes for the "replace"-type output HTML.
397
+ *
398
+ * @param string $string the string
399
+ */
400
+ protected function fixReplaceLineHtml (string $ string ): string
401
+ {
402
+ static $ rules ;
403
+
404
+ if (!isset ($ rules )) {
405
+ $ delL = \preg_quote (RendererConstant::HTML_CLOSURES_DEL [0 ], '/ ' );
406
+ $ delR = \preg_quote (RendererConstant::HTML_CLOSURES_DEL [1 ], '/ ' );
407
+ $ insL = \preg_quote (RendererConstant::HTML_CLOSURES_INS [0 ], '/ ' );
408
+ $ insR = \preg_quote (RendererConstant::HTML_CLOSURES_INS [1 ], '/ ' );
409
+
410
+ $ rules = [
411
+ // move leading "\n" to be out of closures
412
+ "/ {$ delL }([ \r\n]++)/uS " => '$1 ' . RendererConstant::HTML_CLOSURES_DEL [0 ],
413
+ "/ {$ insL }([ \r\n]++)/uS " => '$1 ' . RendererConstant::HTML_CLOSURES_INS [0 ],
414
+ // move trailing "\n" to be out of closures
415
+ "/([ \r\n]++) {$ delR }/uS " => RendererConstant::HTML_CLOSURES_DEL [1 ] . '$1 ' ,
416
+ "/([ \r\n]++) {$ insR }/uS " => RendererConstant::HTML_CLOSURES_INS [1 ] . '$1 ' ,
417
+ ];
418
+ }
419
+
420
+ foreach ($ rules as $ pattern => $ replace ) {
421
+ $ string = \preg_replace ($ pattern , $ replace , $ string );
422
+ }
423
+
424
+ return \str_replace (["\r\n" , "\r" , "\n" ], '<br> ' , $ string );
425
+ }
394
426
}
0 commit comments