I'm trying to take markdown (generated from HTML) and strip out extra newlines that were only in the HTML for formatting purposes. I have a working example of the regex on https://regex101.com/r/dEhyN3/1 but when I convert it to PHP it's not working and I'm struggling to understand why.
public function squashEmptyLineBreaks(string $markdown) : string
{
return preg_replace('/
{2,}/', '
', $markdown);
}
Test:
/** @test */
public function verifySquashEmptyLineBreaks()
{
$original = <<<EOF
**Language**
- Added four languages: Italian, Portuguese (Brazil), Spanish (Mexico) and Chinese (Traditional)
**Bug fixes**
- Fixed camera jittering for passenger sitting on the back of a motorcycle with sidecar
EOF;
$expected = <<<EOF
**Language**
- Added four languages: Italian, Portuguese (Brazil), Spanish (Mexico) and Chinese (Traditional)
**Bug fixes**
- Fixed camera jittering for passenger sitting on the back of a motorcycle with sidecar
EOF;
$this->assertEquals($expected, $this->parsesMarkdown->headersNeverAtEndOfLine($original));
}
This test continues to fail and the output is unmodified. Am I crazy or am I overlooking something?