This commit is contained in:
Christophe HENRY 2021-03-04 20:39:54 +01:00
parent fcfa98f5d6
commit 011f38c36f
3 changed files with 83 additions and 88 deletions

View File

@ -1,101 +1,106 @@
html { html {
font-family: sans-serif; font-family: sans-serif;
font-size:1em; font-size:1rem;
color:#1E4147; color:#1E4147;
background-color:#fafafa; background-color:#fafafa;
} }
body { body {
max-width: 1024px; max-width: 1024px;
margin: auto; margin: auto;
} }
p, ul { ul {
margin-top: 0; margin: 0.4rem 0;
margin-bottom: 0.3em; padding: 0;
padding-top: 0;
padding-bottom: 0;
} }
h1,h2,h3{ p, pre {
line-height:1.2; margin: 0 0 0.3rem;
color: #66f; padding: 0;
margin-top: 0;
margin-bottom: 0;
padding-top: 0;
padding-bottom: 0;
} }
h1 { li {
margin-top: 1em; margin: 0;
margin-bottom: 1em; padding: 0;
}
h1,h2,h3 {
line-height:1.2;
color: #66f;
margin: 0;
padding: 0;
} }
blockquote { blockquote {
background-color: #eee; background-color: #eee;
border-left: 3px solid #444; border-left: 3px solid #444;
margin: 1rem -1rem 1rem calc(-1rem - 3px); margin: 1rem -1rem 1rem calc(-1rem - 3px);
padding: 1rem; padding: 1rem;
}
ul, li {
padding: 0;
} }
a { a {
color:#820; margin: -1.35rem;
text-decoration: none; color:#820;
text-decoration: none;
}
a:before {
content: "🔗 ";
} }
a:visited { a:visited {
color: #868; color: #868;
} }
pre { pre {
background-color: #eee; background-color: #eee;
margin: 0 -1rem; margin: 0 -1rem;
padding: 1rem; padding: 1rem;
overflow-x: auto; overflow-x: auto;
} }
@media only screen and (max-width: 1024px) { @media only screen and (max-width: 1024px) {
body { a {
margin: 3em; margin: -4rem;
} }
h1 { body {
font-size: 4em; margin: 3rem;
} }
h2 { h1 {
font-size: 3.5em; font-size: 4rem;
} }
h3 { h2 {
font-size: 3em; font-size: 3.5rem;
} }
p, pre, ul { h3 {
font-size: 2.6em; font-size: 3rem;
} }
p, pre, ul {
font-size: 2.6rem;
}
} }
@media(prefers-color-scheme:dark) { @media(prefers-color-scheme:dark) {
html { html {
background-color: #111; background-color: #111;
color: #eee; color: #eee;
} }
blockquote { blockquote {
background-color: #000; background-color: #000;
} }
pre { pre {
background-color: #222; background-color: #222;
} }
a { a {
color: #0087BD; color: #0087BD;
} }
a:visited { a:visited {
color: #802200; color: #802200;
} }
} }

View File

@ -54,7 +54,7 @@ function markupPreg($instruction, $markup, &$text) {
$output = preg_replace("#${instruction}(.+?)${instruction}#", "<{$markup}>$1</{$markup}>", $output); $output = preg_replace("#${instruction}(.+?)${instruction}#", "<{$markup}>$1</{$markup}>", $output);
# Replaces a remaining __ into "<i>…</i>" to the end of the line. # Replaces a remaining __ into "<i>…</i>" to the end of the line.
$output = preg_replace("#${instruction}(.+)#", "<{$markup}>$1</{$markup}>", $output); $output = preg_replace("#${instruction}(.+)?#", "<{$markup}>$1</{$markup}>", $output);
$text = $output; $text = $output;
} }
@ -66,8 +66,8 @@ function markupPreg($instruction, $markup, &$text) {
*/ */
function addTextAttributes(&$line) { function addTextAttributes(&$line) {
markupPreg("__", "u", $line); markupPreg("__", "u", $line);
markupPreg("\*\*", "b", $line); markupPreg("\*\*", "strong", $line);
markupPreg("//", "i", $line); markupPreg("//", "em", $line);
markupPreg("~~", "del", $line); markupPreg("~~", "del", $line);
} }
@ -77,11 +77,7 @@ function addTextAttributes(&$line) {
*/ */
function htmlEscape(&$text) { function htmlEscape(&$text) {
$text = htmlspecialchars($text, ENT_HTML5, "UTF-8", false); $text = htmlspecialchars($text, ENT_HTML5, "UTF-8", false);
} $text = preg_replace("#\ ([?!;])#", "&#8239;\$1", $text); # Espace fine insécable
function keepSpaces(&$text) {
# https://en.wikipedia.org/wiki/Whitespace_character#Unicode
$text = preg_replace("# #", "&puncsp;&puncsp;", $text);
} }
$mode = null; $mode = null;
@ -106,23 +102,20 @@ foreach ($fileLines as $line) {
$h_level = strlen($sharps[1]); $h_level = strlen($sharps[1]);
$text = $sharps[2]; $text = $sharps[2];
htmlEscape($text); htmlEscape($text);
keepSpaces($text);
switch ($h_level) { switch ($h_level) {
case 1: print("<h1>".$text."</h1>\n"); break; case 1: print("<h1>".$text."</h1>\n"); break;
case 2: print("<h2>".$text."</h2>\n"); break; case 2: print("<h2>".$text."</h2>\n"); break;
case 3: print("<h3>".$text."</h3>\n"); break; case 3: print("<h3>".$text."</h3>\n"); break;
} }
} elseif ("=>" == $line2) { } elseif ("=>" == $line2) {
preg_match("/^=>\s*([^\s]+)\s*(.*)$/", $line, $linkParts); preg_match("/^=>\s*([^\s]+)(\s+(.*))?$/", $line, $linkParts);
$url_link = $linkParts[1]; $url_link = $linkParts[1];
$url_label = $linkParts[2]; $url_label = $linkParts[2];
if (empty($url_label)) { if (empty(trim($url_label))) {
$url_label = $url_link; $url_label = $url_link;
} else { } else {
// the label is humain-made, apply formatting // the label is humain-made, apply formatting
htmlEscape($url_label); htmlEscape($url_label);
keepSpaces($url_label);
if ($mode_textAttributes) addTextAttributes($url_label);
} }
print("<p><a href='".$url_link."'>".$url_label."</a></p>\n"); print("<p><a href='".$url_link."'>".$url_label."</a></p>\n");
} elseif ('"""' == $line3) { } elseif ('"""' == $line3) {
@ -139,7 +132,7 @@ foreach ($fileLines as $line) {
print("<p>&nbsp;</p>\n"); print("<p>&nbsp;</p>\n");
else else
htmlEscape($quote); htmlEscape($quote);
keepSpaces($quote); if ($mode_textAttributes) addTextAttributes($line);
print("<p>".$quote."</p>\n"); print("<p>".$quote."</p>\n");
} elseif ("*" == $line1 && "**" != $line2) { } elseif ("*" == $line1 && "**" != $line2) {
$mode = "ul"; $mode = "ul";
@ -147,7 +140,6 @@ foreach ($fileLines as $line) {
continue; continue;
} else { } else {
htmlEscape($line); htmlEscape($line);
keepSpaces($line);
if ($mode_textAttributes) addTextAttributes($line); if ($mode_textAttributes) addTextAttributes($line);
print("<p>$line</p>\n"); print("<p>$line</p>\n");
} }
@ -157,7 +149,6 @@ foreach ($fileLines as $line) {
print("</pre>\n"); print("</pre>\n");
} else { } else {
htmlEscape($line); htmlEscape($line);
if ($mode_textAttributes) addTextAttributes($line);
print($line."\n"); print($line."\n");
} }
} elseif ("quote"==$mode) { } elseif ("quote"==$mode) {
@ -168,7 +159,6 @@ foreach ($fileLines as $line) {
print("<p>&nbsp;</p>\n"); print("<p>&nbsp;</p>\n");
else else
htmlEscape($quote); htmlEscape($quote);
keepSpaces($quote);
print("<p>".$quote."</p>\n"); print("<p>".$quote."</p>\n");
} else { } else {
$mode=null; $mode=null;
@ -183,7 +173,7 @@ foreach ($fileLines as $line) {
print("<li>&nbsp;\n"); print("<li>&nbsp;\n");
else else
htmlEscape($li); htmlEscape($li);
keepSpaces($li); addTextAttributes($li);
print("<li>".$li."\n"); print("<li>".$li."\n");
} else { } else {
$mode = null; $mode = null;

View File

@ -35,7 +35,7 @@ Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium dolor
=> Link link with label => Link link with label
=>Link_without_label =>Link_without_label
=>Link link with label =>Link link with label
=>gemini://site.com gemini://site.com
### Links made of only dots, and spaces after ### 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 <b>HTML stuff. Preformatted text with **bold**, //italic//, and so on… But still not <b>HTML</b> stuff.
``` ```
# Quotations # Quotations