some fixes

This commit is contained in:
tezlm 2022-04-24 00:33:55 -07:00
parent 164143d7e9
commit dbd85009cf
5 changed files with 23 additions and 12 deletions

1
.gitignore vendored Normal file
View file

@ -0,0 +1 @@
files

View file

@ -1,3 +1,5 @@
this is pretty old, but i like the idea. maybe i'll redo it later?
# md
a tiny server for hosting markdown sites.

View file

@ -30,10 +30,18 @@ editor.addEventListener("input", (e) => {
}
if (e.inputType === "insertLineBreak") {
const slice = value.slice(0, sel).trimEnd();
const slice = value.slice(0, sel - 1);
const line = slice.slice(slice.lastIndexOf("\n") + 1);
if (/^([-*+]|[0-9]+.) $/.test(line)) {
editor.value = `${value.slice(0, sel - line.length - 1)}${value.slice(sel)}`;
return;
}
if (line[0] === "-") return insert("- ");
if (line[0] === "*") return insert("* ");
if (line[0] === "+") return insert("+ ");
if (/^[0-9]+\.\s/.test(line)) {
const num = Number(line.match(/^[0-9]+/)) + 1;
return insert(num + ". ");

View file

@ -11,10 +11,10 @@ h1, h2, h3 {
}
code, pre, key {
font-family: Monaco, "Courier New", monospace;
font-family: ui-monospace, "Segoe UI Mono", "Source Code Pro", monospace;
border-radius: 3px;
background: #eee;
padding: 3px;
background: #eeeeee;
padding: 1px 2px;
overflow-x: auto;
}
@ -26,7 +26,7 @@ img {
}
blockquote {
border-left: solid #888 3px;
border-left: solid #888888 3px;
font-style: italic;
padding-left: 1em;
margin-left: 3px;
@ -35,18 +35,18 @@ blockquote {
pre { padding: 8px; }
key { box-shadow: 0 3px 0 #ddd; }
hr { margin: 1em 0; }
a { color: #2082ea; }
a:visited { color: #741ac9;}
li { line-height: 1.5; }
hr { margin: 1em 0; }
a { color: #2082ea; }
a:visited { color: #741ac9; }
li { line-height: 1.5; }
@media (prefers-color-scheme: dark) {
body {
background: #222;
background: #1c1c1c;
color: #eee;
}
code, pre, key { background: #444; }
code, pre, key { background: #444444; }
key { box-shadow: 0 3px 0 #333; }
a { color: #66b0f0; }
a:visited { color: #a65fea; }

View file

@ -33,7 +33,7 @@ function renderMarkdown(text) {
.replace(/```.*\n((.|\n)+?)```/gim, "<pre>$1</pre>")
.replace(/`((\\.|[^`])+)`/gim, "<code>$1</code>")
.replace(/!\[(.+?)\]\((.+?)\)/gim, '<img src="$2" alt="$1" />')
.replace(/\[(.+?)\]\((.+?)\)/gim, '<a href="$1">$2</a>')
.replace(/\[(.+?)\]\((.+?)\)/gim, '<a href="$2">$1</a>')
.replace(/(?<=\n)\n/gim, "<br />");
}