From 18d5b7d518cf6359dff7c8eb0b086cf659306e30 Mon Sep 17 00:00:00 2001 From: Christophe HENRY Date: Mon, 8 Mar 2021 15:44:55 +0100 Subject: [PATCH] Adds alt/title attribute to preformatted text --- TODO | 1 - htmgem.php | 10 +++++++++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/TODO b/TODO index 9f1a952..e2251c7 100644 --- a/TODO +++ b/TODO @@ -1,7 +1,6 @@ * manage url encoding: The filename fetched on disk may differ from that was asked by URL. * check /etc/passwd not accessible: Perform sanity checks against unauthorized access. * manage 404: Display better errors. -* HTML: alt texts on pre and quote * HTML: On links indicate whether it's on Gemini or Www or image. * a way to get the source of a page, using urlrewriting * options to activate the text decoration diff --git a/htmgem.php b/htmgem.php index cd4a612..d07f7bc 100644 --- a/htmgem.php +++ b/htmgem.php @@ -140,8 +140,15 @@ foreach ($fileLines as $line) { continue; } } elseif ("```" == $line3) { + if (preg_match("/^```\s*(.*)$/", $line, $matches)) { + $alt_text = trim(@$matches[1]); + if (!(empty($alt_text))) { + echo "
\n";
+                    } else {
+                        echo "
\n";
+                    }
+                }
                 $mode="pre";
-                echo "
\n";
             } elseif (">" == $line1) {
                 $mode = "quote";
                 preg_match("/^>\s*(.*)$/", $line, $quoteParts);
@@ -228,6 +235,7 @@ echo <<$page_title