From 04a7fe7484f773546988b840de52bacc6dcb65c6 Mon Sep 17 00:00:00 2001 From: Christophe HENRY Date: Wed, 3 Mar 2021 16:40:22 +0100 Subject: [PATCH] Text markups work --- htmgem.php | 21 ++++++++++++++------- tests/test.gmi | 6 +++--- 2 files changed, 17 insertions(+), 10 deletions(-) diff --git a/htmgem.php b/htmgem.php index 31c4639..527cb4e 100644 --- a/htmgem.php +++ b/htmgem.php @@ -75,12 +75,13 @@ function addTextAttributes(&$line) { * Escapes the HTML entities yet contained in the Gemtext, keeps multiple spaces. * @param $text1, $text2 texts to process */ -function htmlEscape(&$text1, &$text2=null) { - $text1 = htmlspecialchars($text1, ENT_HTML5, "UTF-8", false); +function htmlEscape(&$text) { + $text = htmlspecialchars($text, ENT_HTML5, "UTF-8", false); +} +function keepSpaces(&$text) { # https://en.wikipedia.org/wiki/Whitespace_character#Unicode - $text1 = preg_replace("# #", "  ", $text1); #TODO: a way to not touch single spaces as " " > " " - if (!is_null($text2)) return htmlEscape($text2); + $text = preg_replace("# #", "  ", $text); } $mode = null; @@ -100,6 +101,7 @@ foreach ($fileLines as $line) { $h_level = strlen($sharps[1]); $text = $sharps[2]; htmlEscape($text); + keepSpaces($text); switch ($h_level) { case 1: print("

".$text."

\n"); break; case 2: print("

".$text."

\n"); break; @@ -110,12 +112,14 @@ foreach ($fileLines as $line) { $url_link = $linkParts[1]; $url_label = $linkParts[2]; if (empty($url_label)) $url_label = $url_link; - htmlEscape($url_link, $url_label); + htmlEscape($url_link); + keepSpaces($url_link); + htmlEscape($url_label); + keepSpaces($url_label); if ($mode_textAttributes) addTextAttributes($url_label); print("

".$url_label."

\n"); } elseif ('"""' == $line3) { $mode_textAttributes = !$mode_textAttributes; - $reDo = true; } elseif ("```" == $line3) { $mode="pre"; print("
\n");
@@ -128,6 +132,7 @@ foreach ($fileLines as $line) {
                     print("

 

\n"); else htmlEscape($quote); + keepSpaces($quote); print("

".$quote."

\n"); } elseif ("*" == $line1 && "**" != $line2) { $mode = "ul"; @@ -135,6 +140,7 @@ foreach ($fileLines as $line) { print("