From b2d5ecf990f14c3b068be9df7e830cd76cdd001e Mon Sep 17 00:00:00 2001 From: Christophe HENRY Date: Tue, 2 Mar 2021 23:35:53 +0100 Subject: [PATCH] WIP --- .gitignore | 1 + TODO | 1 + htmgem.php | 16 +++++++++++++--- tests/test.gmi | 13 ++++++++++++- 4 files changed, 27 insertions(+), 4 deletions(-) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..1377554 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +*.swp diff --git a/TODO b/TODO index bc1ca73..60ba624 100644 --- a/TODO +++ b/TODO @@ -11,3 +11,4 @@ * On links indicate whether it's on Gemini or Www or image. * Command line API for script and testing. * Manage bold, italic, underline on one physical line. +* Prevent infinite loop if errors occurs with reDo diff --git a/htmgem.php b/htmgem.php index da9cf04..7103a65 100644 --- a/htmgem.php +++ b/htmgem.php @@ -39,12 +39,22 @@ echo(<< EOL); +function addTextAttributes($line) { + $output = $line; + $output = preg_replace("#__([^_]+)(?:__)?#", "\$1", $output); + $output = preg_replace("#//([^/]+)(?://)?#", "\$1", $output); + $output = preg_replace("#~~([^~]+)(?:~~)?#", "\$1", $output); + $output = preg_replace("#\*\*([^\*]+)(?:\*\*)?#", "\$1", $output); + return $output; +} + $mode = null; foreach ($fileLines as $line) { $reDo = true; $line1 = substr($line, 0, 1); $line2 = substr($line, 0, 2); $line3 = substr($line, 0, 3); + $line = htmlspecialchars($line, ENT_HTML5, "UTF-8", false); while ($reDo) { $reDo = false; # Change in modes need to redo one loop as they can’t handle the case if (is_null($mode)) { @@ -77,12 +87,12 @@ foreach ($fileLines as $line) { print("

 

\n"); else print("

".$quoteParts[1]."

\n"); - } elseif ("*" == $line1) { + } elseif ("*" == $line1 && "**" != $line2) { $mode = "ul"; $reDo = true; print("