mirror of
https://tildegit.org/sbgodin/HtmGem.git
synced 2023-08-25 13:53:12 +02:00
Don't compress spaces for preformated text
This commit is contained in:
parent
5d74578efc
commit
731aa3bda2
@ -254,12 +254,14 @@ class GemtextTranslate_html {
|
|||||||
|
|
||||||
# Adds no-break space to stick the (EM/EN dashes) to words : aaaaaa – bb. ==> aaaaaa –$bb.
|
# 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);
|
$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) {
|
public function translate($textDecoration=true) {
|
||||||
$output = "";
|
$output = "";
|
||||||
foreach ($this->parsedGemtext as $node) {
|
foreach ($this->parsedGemtext as $node) {
|
||||||
@ -267,6 +269,7 @@ class GemtextTranslate_html {
|
|||||||
switch($mode) {
|
switch($mode) {
|
||||||
case "":
|
case "":
|
||||||
$text = $node["text"];
|
$text = $node["text"];
|
||||||
|
self::spacesCompress($text);
|
||||||
self::htmlPrepare($text);
|
self::htmlPrepare($text);
|
||||||
if ($textDecoration) self::addTextDecoration($text);
|
if ($textDecoration) self::addTextDecoration($text);
|
||||||
$output .= "<p>$text</p>\n";
|
$output .= "<p>$text</p>\n";
|
||||||
@ -274,6 +277,7 @@ class GemtextTranslate_html {
|
|||||||
case "*":
|
case "*":
|
||||||
$output .= "<ul>\n";
|
$output .= "<ul>\n";
|
||||||
foreach ($node["texts"] as $text) {
|
foreach ($node["texts"] as $text) {
|
||||||
|
self::spacesCompress($text);
|
||||||
self::htmlPrepare($text);
|
self::htmlPrepare($text);
|
||||||
if ($textDecoration) self::addTextDecoration($text);
|
if ($textDecoration) self::addTextDecoration($text);
|
||||||
$output .= "<li>$text\n";
|
$output .= "<li>$text\n";
|
||||||
@ -288,6 +292,7 @@ class GemtextTranslate_html {
|
|||||||
case ">":
|
case ">":
|
||||||
$output .= "<blockquote>\n";
|
$output .= "<blockquote>\n";
|
||||||
foreach ($node["texts"] as $text) {
|
foreach ($node["texts"] as $text) {
|
||||||
|
self::spacesCompress($text);
|
||||||
self::htmlPrepare($text);
|
self::htmlPrepare($text);
|
||||||
if ($textDecoration) self::addTextDecoration($text);
|
if ($textDecoration) self::addTextDecoration($text);
|
||||||
$output .= "<p>$text</p>\n";
|
$output .= "<p>$text</p>\n";
|
||||||
@ -299,8 +304,10 @@ class GemtextTranslate_html {
|
|||||||
$linkText = $node["text"];
|
$linkText = $node["text"];
|
||||||
if (empty($linkText)) {
|
if (empty($linkText)) {
|
||||||
$linkText = $link;
|
$linkText = $link;
|
||||||
|
self::spacesCompress($linkText);
|
||||||
self::htmlPrepare($linkText);
|
self::htmlPrepare($linkText);
|
||||||
} else {
|
} else {
|
||||||
|
self::spacesCompress($linkText);
|
||||||
// Don't double encode, just escapes quotes, "<" and ">".
|
// Don't double encode, just escapes quotes, "<" and ">".
|
||||||
// So "I'm>" becomes "I'>". The & remains untouched.
|
// So "I'm>" becomes "I'>". The & remains untouched.
|
||||||
$link = htmlspecialchars($link, ENT_HTML5|ENT_QUOTES, "UTF-8", false);
|
$link = htmlspecialchars($link, ENT_HTML5|ENT_QUOTES, "UTF-8", false);
|
||||||
@ -314,17 +321,20 @@ class GemtextTranslate_html {
|
|||||||
break;
|
break;
|
||||||
case "#":
|
case "#":
|
||||||
$title = $node["title"];
|
$title = $node["title"];
|
||||||
|
self::spacesCompress($linkText);
|
||||||
self::htmlPrepare($title);
|
self::htmlPrepare($title);
|
||||||
if (empty($this->pageTitle)) $this->pageTitle = $title;
|
if (empty($this->pageTitle)) $this->pageTitle = $title;
|
||||||
$output .= "<h1>$title</h1>\n";
|
$output .= "<h1>$title</h1>\n";
|
||||||
break;
|
break;
|
||||||
case "##":
|
case "##":
|
||||||
$title = $node["title"];
|
$title = $node["title"];
|
||||||
|
self::spacesCompress($linkText);
|
||||||
self::htmlPrepare($title);
|
self::htmlPrepare($title);
|
||||||
$output .= "<h2>$title</h2>\n";
|
$output .= "<h2>$title</h2>\n";
|
||||||
break;
|
break;
|
||||||
case "###":
|
case "###":
|
||||||
$title = $node["title"];
|
$title = $node["title"];
|
||||||
|
self::spacesCompress($linkText);
|
||||||
self::htmlPrepare($title);
|
self::htmlPrepare($title);
|
||||||
$output .= "<h3>$title</h3>\n";
|
$output .= "<h3>$title</h3>\n";
|
||||||
break;
|
break;
|
||||||
|
Loading…
Reference in New Issue
Block a user