Replaces several spaces to only one

This commit is contained in:
Christophe HENRY 2021-03-25 15:24:51 +01:00
parent 91abafdce0
commit c858b733f4
3 changed files with 77 additions and 69 deletions

View File

@ -254,6 +254,9 @@ class GemtextTranslate_html {
# Adds no-break space to stick the (EM/EN dashes) to words : aaaaaa bb. ==> aaaaaa $bb.
$text = mb_ereg_replace("([—–]) ([^.]+)\.", "\\1".self::NARROW_NO_BREAK_SPACE."\\2.", $text);
# Replaces several spaces (0x20) by only one
$text = preg_replace("/ +/", " ", $text);
}
}

View File

@ -11,11 +11,16 @@ function translateHtml($text): string {
final class translateToHtmlTest extends TestCase {
protected static function noSeveralSpaces($text): string {
# Replaces several spaces (0x20) by only one
return preg_replace("/ +/", " ", $text);
}
public function test_translate_gemtext_smallTextSets(): void {
$line1 = " Hello, how are you? ";
$line2 = " Nice to meet you! ";
$rline1 = rtrim($line1);
$rline2 = rtrim($line2);
$rline1 = self::noSeveralSpaces(rtrim($line1));
$rline2 = self::noSeveralSpaces(rtrim($line2));
$this->assertSame(
"",
translateHtml(null),