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,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;
}
}

View File

@ -54,7 +54,7 @@ function markupPreg($instruction, $markup, &$text) {
$output = preg_replace("#${instruction}(.+?)${instruction}#", "<{$markup}>$1</{$markup}>", $output);
# 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;
}
@ -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("# #", "&puncsp;&puncsp;", $text);
$text = preg_replace("#\ ([?!;])#", "&#8239;\$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("<h1>".$text."</h1>\n"); break;
case 2: print("<h2>".$text."</h2>\n"); break;
case 3: print("<h3>".$text."</h3>\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("<p><a href='".$url_link."'>".$url_label."</a></p>\n");
} elseif ('"""' == $line3) {
@ -139,7 +132,7 @@ foreach ($fileLines as $line) {
print("<p>&nbsp;</p>\n");
else
htmlEscape($quote);
keepSpaces($quote);
if ($mode_textAttributes) addTextAttributes($line);
print("<p>".$quote."</p>\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("<p>$line</p>\n");
}
@ -157,7 +149,6 @@ foreach ($fileLines as $line) {
print("</pre>\n");
} else {
htmlEscape($line);
if ($mode_textAttributes) addTextAttributes($line);
print($line."\n");
}
} elseif ("quote"==$mode) {
@ -168,7 +159,6 @@ foreach ($fileLines as $line) {
print("<p>&nbsp;</p>\n");
else
htmlEscape($quote);
keepSpaces($quote);
print("<p>".$quote."</p>\n");
} else {
$mode=null;
@ -183,7 +173,7 @@ foreach ($fileLines as $line) {
print("<li>&nbsp;\n");
else
htmlEscape($li);
keepSpaces($li);
addTextAttributes($li);
print("<li>".$li."\n");
} else {
$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_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 <b>HTML stuff.
Preformatted text with **bold**, //italic//, and so on… But still not <b>HTML</b> stuff.
```
# Quotations