1
0
mirror of https://tildegit.org/sbgodin/HtmGem.git synced 2023-08-25 13:53:12 +02:00
This commit is contained in:
Christophe HENRY 2021-03-03 23:37:20 +01:00
parent 3af022aee9
commit 307d31d1f5
3 changed files with 27 additions and 17 deletions

2
TODO
View File

@ -10,5 +10,3 @@
* Use first h1 as the HTML page title on get in config? * Use first h1 as the HTML page title on get in config?
* On links indicate whether it's on Gemini or Www or image. * On links indicate whether it's on Gemini or Www or image.
* Command line API for script and testing. * Command line API for script and testing.
* Manage bold, italic, underline on one physical line.
* Prevent infinite loop if errors occurs with reDo

View File

@ -11,13 +11,19 @@ body {
} }
p { p {
margin-bottom: 0; margin-top: 0;
padding-bottom: 0; margin-bottom: 1em;
padding-top: 0;
padding-bottom: 0;
} }
h1,h2,h3{ h1,h2,h3{
line-height:1.2; line-height:1.2;
color: #66f; color: #66f;
margin-top: 0;
margin-bottom: 0;
padding-top: 0;
padding-bottom: 0;
} }
h1 { h1 {
@ -33,9 +39,9 @@ blockquote {
} }
ul { ul {
margin-left: 0; margin: 0;
padding-left: 0; margin-bottom: 1em;
padding-bottom: 1em; padding: 0;
} }
li { li {

View File

@ -87,15 +87,20 @@ function keepSpaces(&$text) {
$mode = null; $mode = null;
$mode_textAttributes = true; $mode_textAttributes = true;
foreach ($fileLines as $line) { foreach ($fileLines as $line) {
$reDo = true; $reDoCount = 0;
$line1 = substr($line, 0, 1); while (true) {
$line2 = substr($line, 0, 2); if ($reDoCount>1) die("Too many loops");
$line3 = substr($line, 0, 3); $reDoCount += 1;
while ($reDo) { $line1 = substr($line, 0, 1); // $line can be modified
$reDo = false; # Change in modes need to redo one loop as they cant handle the case $line2 = substr($line, 0, 2); // in the meantime.
$line3 = substr($line, 0, 3);
if (is_null($mode)) { if (is_null($mode)) {
if (empty($line)) { if (empty($line)) {
print("<p>&nbsp;</p>\n"); print("<p>&nbsp;</p>\n");
} elseif (b"\xEF\xBB\xBF" == $line3) {
# Removes the BOM
$line = substr($line, 3);
continue;
} elseif ("#" == $line1) { } elseif ("#" == $line1) {
preg_match("/^(#{1,3})\s*(.*)/", $line, $sharps); preg_match("/^(#{1,3})\s*(.*)/", $line, $sharps);
$h_level = strlen($sharps[1]); $h_level = strlen($sharps[1]);
@ -136,8 +141,8 @@ foreach ($fileLines as $line) {
print("<p>".$quote."</p>\n"); print("<p>".$quote."</p>\n");
} elseif ("*" == $line1 && "**" != $line2) { } elseif ("*" == $line1 && "**" != $line2) {
$mode = "ul"; $mode = "ul";
$reDo = true;
print("<ul>\n"); print("<ul>\n");
continue;
} else { } else {
htmlEscape($line); htmlEscape($line);
keepSpaces($line); keepSpaces($line);
@ -164,9 +169,9 @@ foreach ($fileLines as $line) {
keepSpaces($quote); keepSpaces($quote);
print("<p>".$quote."</p>\n"); print("<p>".$quote."</p>\n");
} else { } else {
print("</blockquote>\n");
$mode=null; $mode=null;
$reDo=true; print("</blockquote>\n");
continue;
} }
} elseif ("ul"==$mode) { } elseif ("ul"==$mode) {
if ("*" == $line1 && "**" != $line2) { if ("*" == $line1 && "**" != $line2) {
@ -181,9 +186,10 @@ foreach ($fileLines as $line) {
} else { } else {
$mode = null; $mode = null;
print("</ul>\n"); print("</ul>\n");
$reDo = true; continue;
} }
} }
break; // Do one loop, except if required
} }
} }