diff --git a/lib-htmgem.php b/lib-htmgem.php index d0a0cf6..2a2cb80 100644 --- a/lib-htmgem.php +++ b/lib-htmgem.php @@ -254,12 +254,14 @@ 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); } } + protected static function spacesCompress(&$text) { + # Replaces several spaces (0x20) by only one + $text = preg_replace("/ +/", " ", $text); + } + public function translate($textDecoration=true) { $output = ""; foreach ($this->parsedGemtext as $node) { @@ -267,6 +269,7 @@ class GemtextTranslate_html { switch($mode) { case "": $text = $node["text"]; + self::spacesCompress($text); self::htmlPrepare($text); if ($textDecoration) self::addTextDecoration($text); $output .= "
$text
\n"; @@ -274,6 +277,7 @@ class GemtextTranslate_html { case "*": $output .= "\n"; foreach ($node["texts"] as $text) { + self::spacesCompress($text); self::htmlPrepare($text); if ($textDecoration) self::addTextDecoration($text); $output .= "$text
\n"; @@ -299,8 +304,10 @@ class GemtextTranslate_html { $linkText = $node["text"]; if (empty($linkText)) { $linkText = $link; + self::spacesCompress($linkText); self::htmlPrepare($linkText); } else { + self::spacesCompress($linkText); // Don't double encode, just escapes quotes, "<" and ">". // So "I'm>" becomes "I'>". The & remains untouched. $link = htmlspecialchars($link, ENT_HTML5|ENT_QUOTES, "UTF-8", false); @@ -314,17 +321,20 @@ class GemtextTranslate_html { break; case "#": $title = $node["title"]; + self::spacesCompress($linkText); self::htmlPrepare($title); if (empty($this->pageTitle)) $this->pageTitle = $title; $output .= "$title
\n"; break; case "##": $title = $node["title"]; + self::spacesCompress($linkText); self::htmlPrepare($title); $output .= "$title
\n"; break; case "###": $title = $node["title"]; + self::spacesCompress($linkText); self::htmlPrepare($title); $output .= "$title
\n"; break;