actually apply style overrides!
This commit is contained in:
parent
b3d012e256
commit
f3b51cf3ae
1
cli.js
1
cli.js
|
@ -85,7 +85,6 @@ cli.group(Object.keys(CSS_VARS), "CSS:");
|
||||||
|
|
||||||
const argv = cli
|
const argv = cli
|
||||||
.conflicts("author", "body")
|
.conflicts("author", "body")
|
||||||
.conflicts("descriptions", "body")
|
|
||||||
.conflicts("html", "body")
|
.conflicts("html", "body")
|
||||||
.alias("html", "language")
|
.alias("html", "language")
|
||||||
.alias("html", "lang")
|
.alias("html", "lang")
|
||||||
|
|
|
@ -5,7 +5,7 @@
|
||||||
.nh
|
.nh
|
||||||
.ad l
|
.ad l
|
||||||
.\" Begin generated content:
|
.\" Begin generated content:
|
||||||
.TH "gmi-web" "1" "2021-02-15" "1.0.0-rc.2"
|
.TH "gmi-web" "1" "2021-02-15" "1.0.2-rc.2"
|
||||||
.P
|
.P
|
||||||
.SH NAME
|
.SH NAME
|
||||||
.P
|
.P
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
gmi-web(1) "1.0.2-rc.2"
|
gmi-web(1) "1.0.3-rc.2"
|
||||||
|
|
||||||
# NAME
|
# NAME
|
||||||
|
|
||||||
|
|
20
html.js
20
html.js
|
@ -5,9 +5,6 @@ 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 GMI_REGEX = /^((=>\s?(?<href>[^\s]+)(\s(?<title>.+))?)|(?<pre>```\s?(?<alt>.+)?)|(###\s?(?<h3>.+))|(##\s?(?<h2>.+))|(#\s?(?<h1>.+))|(\*\s?(?<li>.+))|(>\s?(?<quote>.+))|(?<text>(.+)?))$/;
|
||||||
|
|
||||||
const truncate = (text, limit) =>
|
|
||||||
text.length > limit ? `${text.substring(0, limit)}...` : text;
|
|
||||||
|
|
||||||
export function toHTML(gemtext, options) {
|
export function toHTML(gemtext, options) {
|
||||||
const tokens = gemtext.split("\n").map((line) => GMI_REGEX.exec(line).groups);
|
const tokens = gemtext.split("\n").map((line) => GMI_REGEX.exec(line).groups);
|
||||||
|
|
||||||
|
@ -20,8 +17,13 @@ export function toHTML(gemtext, options) {
|
||||||
|
|
||||||
if (options.body) return body(tokens, options);
|
if (options.body) return body(tokens, options);
|
||||||
|
|
||||||
|
const truncate = (text, limit) =>
|
||||||
|
text.length > limit ? `${text.substring(0, limit)}...` : text;
|
||||||
|
|
||||||
return `<!DOCTYPE html>
|
return `<!DOCTYPE html>
|
||||||
<html lang="${options.language}" dir="${options.dir}" style="${options.styles}">
|
<html lang="${options.language}" dir="${options.dir}" style="${overrideStyles(
|
||||||
|
options
|
||||||
|
)}">
|
||||||
<head>${head(
|
<head>${head(
|
||||||
Object.assign(options, {
|
Object.assign(options, {
|
||||||
title: tokens[0].h1,
|
title: tokens[0].h1,
|
||||||
|
@ -36,6 +38,16 @@ ${body(tokens, options)}
|
||||||
`;
|
`;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function overrideStyles(options) {
|
||||||
|
if (options.css !== "full") return "";
|
||||||
|
const vars = CSS.rootVariables(CSS.FULL)
|
||||||
|
|
||||||
|
return Object.keys(vars).reduce((styles, key) => {
|
||||||
|
if (options[key] && options[key] !== vars[key]) styles += `--${key}: ${options[key]};`;
|
||||||
|
return styles;
|
||||||
|
}, "");
|
||||||
|
}
|
||||||
|
|
||||||
export function head(options) {
|
export function head(options) {
|
||||||
return `
|
return `
|
||||||
<meta charset="${options.charset}">
|
<meta charset="${options.charset}">
|
||||||
|
|
2
package-lock.json
generated
2
package-lock.json
generated
|
@ -1,6 +1,6 @@
|
||||||
{
|
{
|
||||||
"name": "gmi-web-cli",
|
"name": "gmi-web-cli",
|
||||||
"version": "1.0.1-rc.2",
|
"version": "1.0.2-rc.2",
|
||||||
"lockfileVersion": 1,
|
"lockfileVersion": 1,
|
||||||
"requires": true,
|
"requires": true,
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
{
|
{
|
||||||
"name": "gmi-web-cli",
|
"name": "gmi-web-cli",
|
||||||
"version": "1.0.2-rc.2",
|
"version": "1.0.3-rc.2",
|
||||||
"description": "A bridge between HTML and Gemini",
|
"description": "A bridge between HTML and Gemini",
|
||||||
"main": "html.js",
|
"main": "html.js",
|
||||||
"type": "module",
|
"type": "module",
|
||||||
|
|
Loading…
Reference in a new issue