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-04 20:39:54 +01:00
parent fcfa98f5d6
commit 011f38c36f
3 changed files with 83 additions and 88 deletions

View File

@ -1,6 +1,6 @@
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;
} }
@ -10,25 +10,26 @@ body {
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;
p, pre {
margin: 0 0 0.3rem;
padding: 0;
}
li {
margin: 0;
padding: 0;
} }
h1,h2,h3 { h1,h2,h3 {
line-height:1.2; line-height:1.2;
color: #66f; color: #66f;
margin-top: 0; margin: 0;
margin-bottom: 0; padding: 0;
padding-top: 0;
padding-bottom: 0;
}
h1 {
margin-top: 1em;
margin-bottom: 1em;
} }
blockquote { blockquote {
@ -38,15 +39,16 @@ blockquote {
padding: 1rem; padding: 1rem;
} }
ul, li {
padding: 0;
}
a { a {
margin: -1.35rem;
color:#820; color:#820;
text-decoration: none; text-decoration: none;
} }
a:before {
content: "🔗 ";
}
a:visited { a:visited {
color: #868; color: #868;
} }
@ -59,20 +61,23 @@ pre {
} }
@media only screen and (max-width: 1024px) { @media only screen and (max-width: 1024px) {
a {
margin: -4rem;
}
body { body {
margin: 3em; margin: 3rem;
} }
h1 { h1 {
font-size: 4em; font-size: 4rem;
} }
h2 { h2 {
font-size: 3.5em; font-size: 3.5rem;
} }
h3 { h3 {
font-size: 3em; font-size: 3rem;
} }
p, pre, ul { p, pre, ul {
font-size: 2.6em; font-size: 2.6rem;
} }
} }

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