Compare commits

...

3 Commits

5 changed files with 94 additions and 84 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);
}
}
@ -283,10 +286,13 @@ class GemtextTranslate_html {
$output .= "<pre>\n$text\n</pre>\n";
break;
case ">":
$text = implode("\n", $node["texts"]);
$output .= "<blockquote>\n";
foreach ($node["texts"] as $text) {
self::htmlPrepare($text);
if ($textDecoration) self::addTextDecoration($text);
$output .= "<blockquote>\n$text\n</blockquote>\n";
$output .= "<p>$text</p>\n";
}
$output .= "</blockquote>\n";
break;
case "=>":
$link = $node["link"];

View File

@ -5,6 +5,5 @@ $fileName = $argv[1];
require_once dirname(__FILE__)."/../../lib-htmgem.php";
$text = file_get_contents($fileName);
$parsedGemtext = \htmgem\gemtextParser($text);
$gt_gemtext = new \htmgem\GemtextTranslate_gemtext($parsedGemtext);
$gt_gemtext = new \htmgem\GemtextTranslate_gemtext($text);
echo strval($gt_gemtext);

View File

@ -1,27 +1,27 @@
<p>This text is made of empty quotes&#8239;:</p>
<blockquote>
&nbsp;
<p>&nbsp;</p>
</blockquote>
<p>&nbsp;</p>
<p>Quotes with one word:</p>
<blockquote>
one
<p>one</p>
</blockquote>
<p>Quotes with two words:</p>
<blockquote>
A B
<p>A B</p>
</blockquote>
<p>&nbsp;</p>
<p>Several quotes&#8239;:</p>
<blockquote>
1
2
3
<p>1</p>
<p>2</p>
<p>3</p>
</blockquote>
<p>&nbsp;</p>
<p>Quotes with an empty one in between:</p>
<blockquote>
1
3
<p>1</p>
<p>&nbsp;</p>
<p>3</p>
</blockquote>

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),