From 011f38c36f1ae36a1b2f8cbb3055c53c8dcf1cee Mon Sep 17 00:00:00 2001 From: Christophe HENRY Date: Thu, 4 Mar 2021 20:39:54 +0100 Subject: [PATCH] WIP --- htmgem.css | 141 +++++++++++++++++++++++++------------------------ htmgem.php | 26 +++------ tests/test.gmi | 4 +- 3 files changed, 83 insertions(+), 88 deletions(-) diff --git a/htmgem.css b/htmgem.css index 580f8ba..68fc1e6 100644 --- a/htmgem.css +++ b/htmgem.css @@ -1,101 +1,106 @@ html { - font-family: sans-serif; - font-size:1em; - color:#1E4147; - background-color:#fafafa; + font-family: sans-serif; + font-size:1rem; + color:#1E4147; + background-color:#fafafa; } body { - max-width: 1024px; - margin: auto; + max-width: 1024px; + margin: auto; } -p, ul { - margin-top: 0; - margin-bottom: 0.3em; - padding-top: 0; - padding-bottom: 0; +ul { + margin: 0.4rem 0; + padding: 0; } -h1,h2,h3{ - line-height:1.2; - color: #66f; - margin-top: 0; - margin-bottom: 0; - padding-top: 0; - padding-bottom: 0; +p, pre { + margin: 0 0 0.3rem; + padding: 0; } -h1 { - margin-top: 1em; - margin-bottom: 1em; +li { + margin: 0; + padding: 0; +} + +h1,h2,h3 { + line-height:1.2; + color: #66f; + margin: 0; + padding: 0; } blockquote { - background-color: #eee; - border-left: 3px solid #444; - margin: 1rem -1rem 1rem calc(-1rem - 3px); - padding: 1rem; -} - -ul, li { - padding: 0; + background-color: #eee; + border-left: 3px solid #444; + margin: 1rem -1rem 1rem calc(-1rem - 3px); + padding: 1rem; } a { - color:#820; - text-decoration: none; + margin: -1.35rem; + color:#820; + text-decoration: none; +} + +a:before { + content: "đź”— "; } a:visited { - color: #868; + color: #868; } pre { - background-color: #eee; - margin: 0 -1rem; - padding: 1rem; - overflow-x: auto; + background-color: #eee; + margin: 0 -1rem; + padding: 1rem; + overflow-x: auto; } @media only screen and (max-width: 1024px) { - body { - margin: 3em; - } - h1 { - font-size: 4em; - } - h2 { - font-size: 3.5em; - } - h3 { - font-size: 3em; - } - p, pre, ul { - font-size: 2.6em; - } + a { + margin: -4rem; + } + body { + margin: 3rem; + } + h1 { + font-size: 4rem; + } + h2 { + font-size: 3.5rem; + } + h3 { + font-size: 3rem; + } + p, pre, ul { + font-size: 2.6rem; + } } @media(prefers-color-scheme:dark) { - html { - background-color: #111; - color: #eee; - } + html { + background-color: #111; + color: #eee; + } - blockquote { - background-color: #000; - } + blockquote { + background-color: #000; + } - pre { - background-color: #222; - } - - a { - color: #0087BD; - } + pre { + background-color: #222; + } + + a { + color: #0087BD; + } - a:visited { - color: #802200; - } + a:visited { + color: #802200; + } } diff --git a/htmgem.php b/htmgem.php index 3b6fe26..74e7732 100644 --- a/htmgem.php +++ b/htmgem.php @@ -54,7 +54,7 @@ function markupPreg($instruction, $markup, &$text) { $output = preg_replace("#${instruction}(.+?)${instruction}#", "<{$markup}>$1", $output); # Replaces a remaining __ into "…" to the end of the line. - $output = preg_replace("#${instruction}(.+)#", "<{$markup}>$1", $output); + $output = preg_replace("#${instruction}(.+)?#", "<{$markup}>$1", $output); $text = $output; } @@ -66,8 +66,8 @@ function markupPreg($instruction, $markup, &$text) { */ function addTextAttributes(&$line) { markupPreg("__", "u", $line); - markupPreg("\*\*", "b", $line); - markupPreg("//", "i", $line); + markupPreg("\*\*", "strong", $line); + markupPreg("//", "em", $line); markupPreg("~~", "del", $line); } @@ -77,11 +77,7 @@ function addTextAttributes(&$line) { */ function htmlEscape(&$text) { $text = htmlspecialchars($text, ENT_HTML5, "UTF-8", false); -} - -function keepSpaces(&$text) { - # https://en.wikipedia.org/wiki/Whitespace_character#Unicode - $text = preg_replace("# #", "  ", $text); + $text = preg_replace("#\ ([?!;])#", " \$1", $text); # Espace fine insĂ©cable } $mode = null; @@ -106,23 +102,20 @@ 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; case 3: print("

".$text."

\n"); break; } } elseif ("=>" == $line2) { - preg_match("/^=>\s*([^\s]+)\s*(.*)$/", $line, $linkParts); + preg_match("/^=>\s*([^\s]+)(\s+(.*))?$/", $line, $linkParts); $url_link = $linkParts[1]; $url_label = $linkParts[2]; - if (empty($url_label)) { + if (empty(trim($url_label))) { $url_label = $url_link; } else { // the label is humain-made, apply formatting htmlEscape($url_label); - keepSpaces($url_label); - if ($mode_textAttributes) addTextAttributes($url_label); } print("

".$url_label."

\n"); } elseif ('"""' == $line3) { @@ -139,7 +132,7 @@ foreach ($fileLines as $line) { print("

 

\n"); else htmlEscape($quote); - keepSpaces($quote); + if ($mode_textAttributes) addTextAttributes($line); print("

".$quote."

\n"); } elseif ("*" == $line1 && "**" != $line2) { $mode = "ul"; @@ -147,7 +140,6 @@ foreach ($fileLines as $line) { continue; } else { htmlEscape($line); - keepSpaces($line); if ($mode_textAttributes) addTextAttributes($line); print("

$line

\n"); } @@ -157,7 +149,6 @@ foreach ($fileLines as $line) { print("\n"); } else { htmlEscape($line); - if ($mode_textAttributes) addTextAttributes($line); print($line."\n"); } } elseif ("quote"==$mode) { @@ -168,7 +159,6 @@ foreach ($fileLines as $line) { print("

 

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

".$quote."

\n"); } else { $mode=null; @@ -183,7 +173,7 @@ foreach ($fileLines as $line) { print("
  •  \n"); else htmlEscape($li); - keepSpaces($li); + addTextAttributes($li); print("
  • ".$li."\n"); } else { $mode = null; diff --git a/tests/test.gmi b/tests/test.gmi index 753c8c0..9d9fb42 100644 --- a/tests/test.gmi +++ b/tests/test.gmi @@ -35,7 +35,7 @@ Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium dolor => Link link with label =>Link_without_label =>Link link with label - +=>gemini://site.com gemini://site.com ### Links made of only dots, and spaces after => . @@ -61,7 +61,7 @@ At vero eos et accusamus et iusto odio dignissimos ducimus qui blanditiis praese """ ``` -Preformatted text with **bold**, //italic//, and so on… But still not HTML stuff. +Preformatted text with **bold**, //italic//, and so on… But still not HTML stuff. ``` # Quotations