From 990667c2a76dd66033692345ebfa59a05a7b6bf8 Mon Sep 17 00:00:00 2001 From: Talon Poole Date: Fri, 29 Jan 2021 22:32:30 +0000 Subject: [PATCH] use cli to pass in CSS vars --- cli.js | 58 +++++++++++++++++++++++++++++++++---------------- gmi-web.1 | 38 +++++++++++++++----------------- gmi-web.1.scd | 29 +++++++++++-------------- to-html.js | 60 ++++++++++++++++++++++++++++++--------------------- 4 files changed, 104 insertions(+), 81 deletions(-) diff --git a/cli.js b/cli.js index df25ad2..5805467 100755 --- a/cli.js +++ b/cli.js @@ -5,10 +5,33 @@ const map = require("map-stream"); const tokenize = require("./tokenize"); const toHTML = require("./to-html"); +// TODO: automatically pull these in from gmi.css (also for gmi.css(5)) +const GMI_CSS_VARS = [ + "foreground", + "background", + "p-size", + "p-indent", + "p-line-height", + "a-size", + "pre-size", + "pre-line-height", + "h1-size", + "h2-size", + "h3-size", + "heading-line-height", + "ul-size", + "ul-line-height", + "blockquote-size", + "blockquote-line-height", + "mono", + "serif", + "sans-serif", +]; + require("yargs") .scriptName("gmi-web") .command( - "$0 ", + "$0 [files..]", "Convert .gmi to .html. See gmi-web(1) for more details.", (yargs) => yargs @@ -19,52 +42,49 @@ require("yargs") .option("images", { type: "boolean", default: false, - description: "Include images", + describe: "Include images", }) .option("audio", { type: "boolean", default: false, - description: "Include audio", + describe: "Include audio", }) .option("video", { type: "boolean", default: false, - description: "Include video", - }) - .option("verbose", { - alias: "v", - type: "boolean", - default: false, - description: "No logging to stdout", + describe: "Include video", }) .option("css", { type: "boolean", default: true, - description: "Include gmi.css", + describe: + "gmi.css is included by default. Use --no-css to for the bare-minimum "); -module.exports = (options) => (file, cb) => { - if (!TOKENS_EXT.test(file.path)) return cb(null); - - // TODO: meta: language, description, canonical - file.contents = Buffer.from(` - - -${ - options.css - ? `\n\n\n` - : "" - } +const toHTML = (exports.toHTML = (file, options) => ` + +${head(file.path, options)} -${toHTML(JSON.parse(file.contents.toString("utf8")), options)} +${gemtext(JSON.parse(file.contents.toString("utf8")), options)} `); - +module.exports = (options) => (file, cb) => { + if (!TOKENS_EXT.test(file.path)) return cb(null); + file.contents = Buffer.from(toHTML(file, options)); file.path = file.path.replace(TOKENS_EXT, ".html"); - if (!options.silent) console.log(file.path); + if (options.verbose) console.log(file.path); return cb(null, file); }; -function toHTML(tokens, options) { +// TODO: meta: language, description, canonical +function head(file, options) { + return ` + +${ + !options.css + ? BASE_STYLE + : `\n\n` + } + +`; +} + +function gemtext(tokens, options) { let body = []; let cursor = tokens.shift(); @@ -83,3 +88,8 @@ function line( if (quote) return `
${quote}
`; return `


`; } + +function omit(key, obj) { + const { [key]: omitted, ...rest } = obj; + return rest; +}