From 7c38255205b46cb2fcbce136970a695eaa14a1f3 Mon Sep 17 00:00:00 2001 From: Talon Poole Date: Wed, 24 Feb 2021 21:51:23 +0000 Subject: [PATCH] css.spec.js --- css.js | 6 +++--- css.spec.js | 55 ++++++++++++++++++++++++++++++++++++++++++++++++++++ html.js | 4 +++- html.spec.js | 16 +++++++-------- 4 files changed, 69 insertions(+), 12 deletions(-) create mode 100644 css.spec.js diff --git a/css.js b/css.js index 8046951..4dc99a9 100644 --- a/css.js +++ b/css.js @@ -17,7 +17,7 @@ export function style(options) { )}`; } -export const inline = (options) => { +export function inline(options) { const rules = load(options); return function inlineCSS(tag) { if ((options.body || options.inline) && options.css !== "none") { @@ -34,7 +34,7 @@ export const inline = (options) => { return ""; } }; -}; +} export function load(options) { if (options.css === "none") return []; @@ -76,7 +76,7 @@ export function rootVariables(rules) { ); } -function reduceVariables(rules, options) { +function reduceVariables(rules, options = {}) { const defaultVariables = rootVariables(rules); const CSS_VAR = /(^var\((?.+)\)|(?.+))/; const reduce = (rule) => diff --git a/css.spec.js b/css.spec.js new file mode 100644 index 0000000..f1497d9 --- /dev/null +++ b/css.spec.js @@ -0,0 +1,55 @@ +import { readFileSync } from "fs"; +import { resolve } from "path"; +import { load, rootVariables, style } from "./css.js"; + +test("rootVariables", () => { + expect(rootVariables(load({ css: "gmi-web.css" }))).toMatchInlineSnapshot(` + Object { + "--a-decoration": "underline", + "--a-family": "var(--serif)", + "--a-height": "1.5", + "--a-size": "var(--p-size)", + "--a-style": "normal", + "--background": "white", + "--body-width": "48rem", + "--foreground": "black", + "--h1-family": "var(--sans-serif)", + "--h1-height": "1.25", + "--h1-size": "3rem", + "--h2-family": "var(--sans-serif)", + "--h2-height": "1.25", + "--h2-size": "2.25rem", + "--h3-family": "var(--sans-serif)", + "--h3-height": "1.25", + "--h3-size": "1.5rem", + "--hyphens": "manual", + "--mono": "consolas, monaco, monospace", + "--p-family": "var(--serif)", + "--p-height": "1.5", + "--p-indent": "0rem", + "--p-size": "1.25rem", + "--pre-family": "var(--mono)", + "--pre-height": "1", + "--pre-size": "1rem", + "--quote-family": "var(--serif)", + "--quote-height": "1.25", + "--quote-size": "var(--p-size)", + "--quote-style": "italic", + "--sans-serif": "avenir, helvetica, arial, sans-serif", + "--serif": "georgia, times, serif", + "--ul-family": "var(--serif)", + "--ul-height": "1.25", + "--ul-size": "var(--p-size)", + "--ul-style": "circle", + } + `); +}); + +test("style with variable overrides", () => { + expect(style({ css: "gmi-web.css", foreground: "#137752" })) + .toMatchInlineSnapshot(` + " + + " + `); +}); diff --git a/html.js b/html.js index d2b0619..3aed862 100644 --- a/html.js +++ b/html.js @@ -63,7 +63,9 @@ export function block( } } if (options.body || options.inline) - props += options.inlineCSS(type === "p" && content === "" ? "p:empty" : type) + props += options.inlineCSS( + type === "p" && content === "" ? "p:empty" : type + ); return `<${type}${props}>${escape(content)}`; } diff --git a/html.spec.js b/html.spec.js index a896372..9237cc9 100644 --- a/html.spec.js +++ b/html.spec.js @@ -10,9 +10,9 @@ test("--body", () => {
a bridge between HTML and Gemini
https://codeberg.org/talon/gmi-web on NPM -

+

line-types

-

+

gmi-web makes writing HTML documents as simple as learning the handful of Gemini line-types:

  • paragraphs
  • @@ -21,7 +21,7 @@ test("--body", () => {
  • quotes
  • headings
-

+

     if you are
        familiar with markdown
@@ -30,7 +30,7 @@ test("--body", () => {
 
     but even simpler
     
-

+

inline media

video with title prop image with title prop @@ -146,9 +146,9 @@ test("--image, --audio, --video", () => {
a bridge between HTML and Gemini
https://codeberg.org/talon/gmi-web on NPM -

+

line-types

-

+

gmi-web makes writing HTML documents as simple as learning the handful of Gemini line-types:

  • paragraphs
  • @@ -157,7 +157,7 @@ test("--image, --audio, --video", () => {
  • quotes
  • headings
-

+

     if you are
        familiar with markdown
@@ -166,7 +166,7 @@ test("--image, --audio, --video", () => {
 
     but even simpler
     
-

+

inline media