Skip to content

Commit

Permalink
feat(text-format): add FMT_HTML_CSS_VARS() formatter
Browse files Browse the repository at this point in the history
  • Loading branch information
postspectacular committed Mar 27, 2024
1 parent e7df551 commit 277155e
Showing 1 changed file with 40 additions and 1 deletion.
41 changes: 40 additions & 1 deletion packages/text-format/src/html.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ export const FMT_HTML_TACHYONS = formatHtml({
});

/**
* Preset HTML formatter for use w/ default format IDs, generating `<span>`
* Preset HTML formatter for use w/ default text format IDs, generating `<span>`
* elements with thi.ng/meta-css base framework color classes.
*/
export const FMT_HTML_MCSS = formatHtml({
Expand All @@ -124,6 +124,45 @@ export const FMT_HTML_MCSS = formatHtml({
underline: "underline",
});

/**
* Preset HTML formatter for use w/ default text format IDs, generating `<span>`
* elements with `style` attributes and given CSS variable names for defining
* colors.
*
* @remarks
* The color variable names must be given in this order:
*
* - black
* - red
* - green
* - yellow
* - blue
* - magenta
* - cyan
* - light gray
* - gray
* - light red
* - light green
* - light yellow
* - light blue
* - light magenta
* - light cyan
* - white
*
* @param varNames
*/
export const FMT_HTML_CSS_VARS = (varNames: string[]) =>
formatHtml({
colors: varNames.map((x) => `var(--${x})`),
attrib: "style",
delim: ";",
fg: "color:",
bg: "background:",
bold: "font-weight:bold",
dim: "opacity:0.5",
underline: "text-decoration:underline",
});

/**
* Higher order custom HTML formatter for 16bit (RGB565) colors (without
* additional formatting flags). By default assigns text color, but can be
Expand Down

0 comments on commit 277155e

Please sign in to comment.