diff --git a/TODO b/TODO index 60ba624..93e9ce8 100644 --- a/TODO +++ b/TODO @@ -10,5 +10,3 @@ * Use first h1 as the HTML page title on get in config? * 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.css b/htmgem.css index 8b9cf75..d77519f 100644 --- a/htmgem.css +++ b/htmgem.css @@ -11,13 +11,19 @@ body { } p { - margin-bottom: 0; - padding-bottom: 0; + margin-top: 0; + margin-bottom: 1em; + padding-top: 0; + padding-bottom: 0; } h1,h2,h3{ line-height:1.2; color: #66f; + margin-top: 0; + margin-bottom: 0; + padding-top: 0; + padding-bottom: 0; } h1 { @@ -33,9 +39,9 @@ blockquote { } ul { - margin-left: 0; - padding-left: 0; - padding-bottom: 1em; + margin: 0; + margin-bottom: 1em; + padding: 0; } li { diff --git a/htmgem.php b/htmgem.php index 3ba9d62..aff3a6a 100644 --- a/htmgem.php +++ b/htmgem.php @@ -87,15 +87,20 @@ function keepSpaces(&$text) { $mode = null; $mode_textAttributes = true; foreach ($fileLines as $line) { - $reDo = true; - $line1 = substr($line, 0, 1); - $line2 = substr($line, 0, 2); - $line3 = substr($line, 0, 3); - while ($reDo) { - $reDo = false; # Change in modes need to redo one loop as they can’t handle the case + $reDoCount = 0; + while (true) { + if ($reDoCount>1) die("Too many loops"); + $reDoCount += 1; + $line1 = substr($line, 0, 1); // $line can be modified + $line2 = substr($line, 0, 2); // in the meantime. + $line3 = substr($line, 0, 3); if (is_null($mode)) { if (empty($line)) { print("

 

\n"); + } elseif (b"\xEF\xBB\xBF" == $line3) { + # Removes the BOM + $line = substr($line, 3); + continue; } elseif ("#" == $line1) { preg_match("/^(#{1,3})\s*(.*)/", $line, $sharps); $h_level = strlen($sharps[1]); @@ -136,8 +141,8 @@ foreach ($fileLines as $line) { print("

".$quote."

\n"); } elseif ("*" == $line1 && "**" != $line2) { $mode = "ul"; - $reDo = true; print("\n"); - $reDo = true; + continue; } } + break; // Do one loop, except if required } }