body core styles

This commit is contained in:
Talon Poole 2021-02-15 21:40:59 +00:00
parent 77e4ecb2fb
commit b1d2f7140b
3 changed files with 13 additions and 10 deletions

1
cli.js
View file

@ -70,7 +70,6 @@ const cli = yargs(process.argv.slice(2))
const CSS_VARS = CSS.rootVariables(CSS.FULL); const CSS_VARS = CSS.rootVariables(CSS.FULL);
Object.keys(CSS_VARS).map((key) => { Object.keys(CSS_VARS).map((key) => {
cli.option(key, { default: CSS_VARS[key] }); cli.option(key, { default: CSS_VARS[key] });
cli.conflicts(key, "body");
return key; return key;
}); });

View file

@ -18,7 +18,8 @@ mobile-friendly fashion!
# OPTIONS # OPTIONS
*--body* *--body*
Generate only the HTML for the lines of the Gemini document. Generate only the HTML for the lines of the Gemini document. Use *--css* none
to turn off the core inline styles.
*--html* _LANG_ *--html* _LANG_
Generate a full HTML5 document with the provided _LANG_. *--dir* can be used Generate a full HTML5 document with the provided _LANG_. *--dir* can be used

19
html.js
View file

@ -57,24 +57,27 @@ export function head(options) {
function line( function line(
{ text, href, title, pre, alt, h1, h2, h3, li, quote }, { text, href, title, pre, alt, h1, h2, h3, li, quote },
{ image, audio, video, css } = {} { image, audio, video, css, body } = {}
) { ) {
if (text) return `<p>${escape(text)}</p>`; if (text) return `<p>${escape(text)}</p>`;
const matchesExt = (url, exts) =>
exts.some((ext) => new RegExp(`\.${ext}$`).test(url));
if (href) { if (href) {
const titleProp = title ? ` title="${title}"` : ""; const titleProp = title ? ` title="${title}"` : "";
const FIX_NORMAL_FLOW = body && css ? ` style="display: block; max-width: 100%;"` : ""
const matchesExt = (url, exts) =>
exts.some((ext) => new RegExp(`\.${ext}$`).test(url));
if (image && matchesExt(href, image)) { if (image && matchesExt(href, image)) {
return `<img src="${href}"${titleProp}/>`; return `<img src="${href}"${titleProp}${FIX_NORMAL_FLOW}/>`;
} }
if (audio && matchesExt(href, audio)) { if (audio && matchesExt(href, audio)) {
return `<audio controls src="${href}"${titleProp}></audio>`; return `<audio controls src="${href}"${titleProp}${FIX_NORMAL_FLOW}></audio>`;
}
if (video && matchesExt(href, video)) {
return `<video controls src="${href}"${titleProp}${FIX_NORMAL_FLOW}/></video>`;
} }
if (video && matchesExt(href, video))
return `<video controls src="${href}"${titleProp}/></video>`;
return `<a href="${href}">${title ? escape(title) : href}</a>`; return `<a href="${href}"${FIX_NORMAL_FLOW}>${title ? escape(title) : href}</a>`;
} }
if (h1) return `<h1>${escape(h1)}</h1>`; if (h1) return `<h1>${escape(h1)}</h1>`;