This commit is contained in:
Talon Poole 2021-01-28 23:13:02 +00:00
parent e587d1a933
commit 06a8bab54a
2 changed files with 22 additions and 20 deletions

View file

@ -5,9 +5,11 @@ module.exports = ({css} = {css: true}) => (file, cb) => {
file.contents = Buffer.from(`<!DOCTYPE html>
<html>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width,initial-scale=1">${css ?
'\n<meta name="color-scheme" content="dark light">\n<link rel="stylesheet" href="/gmi.min.css">'
: ''}
<meta name="viewport" content="width=device-width,initial-scale=1">${
css
? '\n<meta name="color-scheme" content="dark light">\n<link rel="stylesheet" href="/gmi.min.css">'
: ""
}
<body>
${toHTML(JSON.parse(file.contents.toString("utf8")))}
</body>
@ -17,29 +19,29 @@ ${toHTML(JSON.parse(file.contents.toString("utf8")))}
};
function toHTML(tokens) {
let body = []
let body = [];
let cursor = tokens.shift()
let cursor = tokens.shift();
while (tokens.length) {
if (cursor.pre) {
body.push(`<pre${cursor.alt ? `title="${cursor.alt}"` : ""}>`)
const closing = tokens.findIndex(token => token.pre)
body = body.concat(tokens.slice(0, closing).map(({text}) => text))
body.push("</pre>")
tokens = tokens.slice(closing + 1)
body.push(`<pre${cursor.alt ? `title="${cursor.alt}"` : ""}>`);
const closing = tokens.findIndex((token) => token.pre);
body = body.concat(tokens.slice(0, closing).map(({ text }) => text));
body.push("</pre>");
tokens = tokens.slice(closing + 1);
}
if (cursor.li) {
body.push(`<ul>`)
const closing = tokens.findIndex(token => !token.li)
body = body.concat(tokens.slice(0, closing).map(line))
body.push("</ul>")
tokens = tokens.slice(closing + 1)
body.push(`<ul>`);
const closing = tokens.findIndex((token) => !token.li);
body = body.concat(tokens.slice(0, closing).map(line));
body.push("</ul>");
tokens = tokens.slice(closing + 1);
}
body.push(line(cursor))
cursor = tokens.shift()
body.push(line(cursor));
cursor = tokens.shift();
}
return body.join("\n")
return body.join("\n");
}
function line({ text, href, title, pre, alt, h1, h2, h3, li, quote }) {