refactor html.js
This commit is contained in:
parent
09572cb347
commit
4a81c7248e
15
cli.js
15
cli.js
|
@ -31,6 +31,7 @@ const cli = yargs(process.argv.slice(2))
|
|||
},
|
||||
dir: {
|
||||
type: "string",
|
||||
hidden: true,
|
||||
choices: ["rtl", "ltr"],
|
||||
default: "ltr",
|
||||
requiresArg: true,
|
||||
|
@ -40,8 +41,9 @@ const cli = yargs(process.argv.slice(2))
|
|||
requiresArg: true,
|
||||
},
|
||||
descriptions: {
|
||||
type: "number",
|
||||
default: 0,
|
||||
coerce: (arg) => {
|
||||
return typeof arg === "number" ? arg : arg ? Infinity : 0;
|
||||
},
|
||||
},
|
||||
css: {
|
||||
default: "full",
|
||||
|
@ -49,6 +51,7 @@ const cli = yargs(process.argv.slice(2))
|
|||
},
|
||||
inline: {
|
||||
type: "boolean",
|
||||
hidden: true,
|
||||
group: "CSS:",
|
||||
},
|
||||
image: {
|
||||
|
@ -69,15 +72,9 @@ const cli = yargs(process.argv.slice(2))
|
|||
default: "utf-8",
|
||||
requiresArg: true,
|
||||
},
|
||||
schemes: {
|
||||
type: "boolean",
|
||||
hidden: true,
|
||||
default: false,
|
||||
group: "CSS:",
|
||||
},
|
||||
})
|
||||
.group(["html", "body"], "Core:")
|
||||
.group(["author", "descriptions", "css", "schemes", "dir"], "HTML:")
|
||||
.group(["author", "descriptions", "css", "dir"], "HTML:")
|
||||
.group(["image", "audio", "video"], "Inline Media:");
|
||||
|
||||
const CSS_VARS = CSS.rootVariables(CSS.FULL);
|
||||
|
|
5
css.js
5
css.js
|
@ -53,7 +53,10 @@ export function style({ inline, css }) {
|
|||
if (css === "core")
|
||||
return `<style>${stringify(CORE, { compress: true })}</style>`;
|
||||
if (css === "full")
|
||||
return `<style>${stringify(FULL, { compress: true })}</style>`;
|
||||
return `<meta name="color-scheme" content="dark light">\n<style>${stringify(
|
||||
FULL,
|
||||
{ compress: true }
|
||||
)}</style>`;
|
||||
|
||||
return `<style>${stringify(load(css, { compress: true }))}</style>`;
|
||||
}
|
||||
|
|
13
html.js
13
html.js
|
@ -4,6 +4,8 @@ import escape from "escape-html";
|
|||
import * as CSS from "./css.js";
|
||||
|
||||
export const GMI_REGEX = /^((=>\s?(?<href>[^\s]+)(\s(?<title>.+))?)|(?<pre>```\s?(?<alt>.+)?)|(###\s?(?<h3>.+))|(##\s?(?<h2>.+))|(#\s?(?<h1>.+))|(\*\s?(?<li>.+))|(>\s?(?<quote>.+))|(?<text>(.+)?))$/;
|
||||
export const tokenize = (gemtext) =>
|
||||
gemtext.split("\n").map((line) => GMI_REGEX.exec(line).groups);
|
||||
|
||||
export function block(
|
||||
{ text, href, title, pre, alt, h1, h2, h3, li, quote },
|
||||
|
@ -94,7 +96,7 @@ export function body(tokens, options) {
|
|||
}
|
||||
|
||||
export function toHTML(gemtext, options) {
|
||||
const tokens = gemtext.split("\n").map((line) => GMI_REGEX.exec(line).groups);
|
||||
const tokens = tokenize(gemtext);
|
||||
|
||||
if (options.body) return body(tokens, options);
|
||||
|
||||
|
@ -118,12 +120,9 @@ ${body(tokens, options)}
|
|||
export function head(options) {
|
||||
return `
|
||||
<meta charset="${options.charset}">
|
||||
<meta name="viewport" content="width=device-width,initial-scale=1">
|
||||
${
|
||||
options.schemes || options.css === "full"
|
||||
? `<meta name="color-scheme" content="dark light">\n`
|
||||
: ""
|
||||
}${CSS.style(options)}
|
||||
<meta name="viewport" content="width=device-width,initial-scale=1">${CSS.style(
|
||||
options
|
||||
)}
|
||||
<title>${options.title}</title>${
|
||||
!options.author ? "" : `\n<meta name="author" content="${options.author}">`
|
||||
}${
|
||||
|
|
2
package-lock.json
generated
2
package-lock.json
generated
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "gmi-web-cli",
|
||||
"version": "1.0.11-rc.2",
|
||||
"version": "1.0.0-rc.3",
|
||||
"lockfileVersion": 1,
|
||||
"requires": true,
|
||||
"dependencies": {
|
||||
|
|
Loading…
Reference in a new issue