domma-cms 1.62.2 → 1.64.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -3,6 +3,7 @@ import {decodeMessageAttribute} from '../../public/js/celebrations/message-attrs
3
3
  * Markdown Service
4
4
  * Parses frontmatter with gray-matter and renders Markdown to HTML with marked.
5
5
  */
6
+ import {normaliseBackground, backgroundStyle} from '../../public/js/background-style.mjs';
6
7
  import {cssClasses} from '../../public/js/css-classes.mjs';
7
8
  import matter from 'gray-matter';
8
9
  import {marked} from 'marked';
@@ -41,7 +42,7 @@ export const BUILTIN_SHORTCODES = new Set([
41
42
  'accordion', 'item', 'carousel', 'slide', 'countdown', 'timeline',
42
43
  'event', 'listgroup', 'spacer', 'center', 'icon', 'demo', 'embed', 'map', 'image', 'form', 'hero', 'table', 'badge',
43
44
  'text', 'button', 'link', 'cta', 'grid', 'row', 'col', 'card', 'box',
44
- 'banner', 'slideover', 'menu',
45
+ 'banner', 'slideover', 'menu', 'background',
45
46
  // effects
46
47
  'counter', 'celebrate', 'firework', 'fireworks', 'scribe',
47
48
  'reveal', 'breathe', 'pulse', 'shake', 'scramble', 'ripple', 'twinkle',
@@ -1993,7 +1994,7 @@ let scrubCallId = 0;
1993
1994
  * (a nested list, code) keeps the difference. The indent is only ever for the reader.
1994
1995
  */
1995
1996
  export const SHORT_TAG_CONTAINERS = Object.freeze([
1996
- 'grid', 'row', 'col', 'card', 'box', 'header', 'footer', 'tabs', 'tab', 'accordion', 'item', 'carousel', 'slide',
1997
+ 'background', 'grid', 'row', 'col', 'card', 'box', 'header', 'footer', 'tabs', 'tab', 'accordion', 'item', 'carousel', 'slide',
1997
1998
  'timeline', 'event', 'hero', 'banner', 'slideover', 'center', 'listgroup', 'table', 'dconfig', 'reveal', 'animate',
1998
1999
  'pulse', 'shake', 'scramble', 'ripple', 'breathe', 'ambient', 'twinkle', 'fireworks', 'scribe', 'wait', 'render', 'redraw'
1999
2000
  ]);
@@ -2454,81 +2455,82 @@ function responsiveGridCols(cols) {
2454
2455
  return map[String(cols)] ?? [`grid-cols-${classToken(cols)}`];
2455
2456
  }
2456
2457
 
2457
- function processGridBlocks(markdown) {
2458
- const {scrubbed, restore} = scrubCodeRegions(markdown);
2459
- // Pass 1: [col span="N"]...[/col] → <div class="col-span-N">...</div>
2460
- // [col]...[/col] → <div class="col">...</div> (enables flex stacking in [row])
2461
- let result = scrubbed.replace(
2462
- /\[col([^\]]*)\]([\s\S]*?)\[\/col\]/gi,
2463
- (_, attrStr, body) => {
2464
- const attrs = parseShortcodeAttrs(attrStr);
2465
- const COL_INJECTABLE = ['reveal', 'breathe', 'animate', 'ripple'];
2466
- const injected = extractInjectedEffects(attrs, COL_INJECTABLE);
2467
- const baseCls = attrs.span ? `col-span-${classToken(attrs.span)}` : 'col';
2468
- // Explicit alignment takes precedence over the shorthand flags.
2469
- const alignment = typeof attrs.align === 'string'
2470
- ? attrs.align.trim().toLowerCase()
2471
- : ['center', 'centre', 'left', 'right'].find(value => attrs[value] === true);
2472
- const align = alignment === 'centre' ? 'center' : alignment;
2473
- const alignClasses = ['left', 'center', 'right'].includes(align) ? [`text-${align}`] : [];
2474
- const allClasses = [baseCls, ...alignClasses, ...injected.effectClasses].join(' ');
2475
- const cls = ` class="${allClasses}"`;
2476
- const id = attrs.id ? ` id="${escapeAttr(attrs.id)}"` : '';
2477
- // Restore the col body before passing it downstream - otherwise the
2478
- // scrub placeholders from this processor's store get carried into
2479
- // processCardBlocks, which creates its own empty store and fails to
2480
- // decode them, producing the literal string "undefined" in place of
2481
- // whatever was in <pre>, ``` fences, or `inline code`.
2482
- return `<div${cls}${id}${injected.effectDataAttrs}>${markedBody(processCardBlocks(processInlineShortcodes(restore(body.trim()))))}</div>`;
2483
- }
2484
- );
2485
-
2486
- // Pass 2: [row gap="N" class="extra" reveal reveal-mode="stagger"]...[/row]
2487
- result = result.replace(
2488
- /\[row([^\]]*)\]([\s\S]*?)\[\/row\]/gi,
2489
- (_, attrStr, inner) => {
2490
- const attrs = parseShortcodeAttrs(attrStr);
2491
- const classes = ['row'];
2492
- if (attrs.gap) classes.push(`gap-${classToken(attrs.gap)}`);
2493
- if (attrs.class) classes.push(escapeAttr(attrs.class));
2494
- const id = attrs.id ? ` id="${escapeAttr(attrs.id)}"` : '';
2495
- const reveal = attrs.reveal !== undefined ? ' data-reveal="true"' : '';
2496
- const revealMode = attrs['reveal-mode'] ? ` data-reveal-mode="${escapeAttr(attrs['reveal-mode'])}"` : '';
2497
- const revealAnimation = attrs['reveal-animation'] ? ` data-reveal-animation="${escapeAttr(attrs['reveal-animation'])}"` : '';
2498
- const revealDuration = attrs['reveal-duration'] ? ` data-reveal-duration="${escapeAttr(attrs['reveal-duration'])}"` : '';
2499
- const revealStagger = attrs['reveal-stagger'] ? ` data-reveal-stagger="${escapeAttr(attrs['reveal-stagger'])}"` : '';
2500
- const revealDelay = attrs['reveal-delay'] ? ` data-reveal-delay="${escapeAttr(attrs['reveal-delay'])}"` : '';
2501
- const revealDirection = attrs['reveal-direction'] ? ` data-reveal-direction="${escapeAttr(attrs['reveal-direction'])}"` : '';
2502
- // Swoosh in again each time the row comes back up into view; cards that lean toward the pointer.
2503
- const revealReplay = isTruthyAttr(attrs['reveal-replay']) ? ' data-reveal-replay="true"' : '';
2504
- const tilt = isTruthyAttr(attrs.tilt) ? ' data-tilt="true"' : '';
2505
- return `<div class="${classes.join(' ')}"${id}${reveal}${revealMode}${revealAnimation}${revealDuration}${revealStagger}${revealDelay}${revealDirection}${revealReplay}${tilt}>${inner}</div>\n`;
2506
- }
2507
- );
2508
-
2509
- // Pass 3: [grid cols="N" gap="N"]...[/grid] → <div class="grid grid-cols-1 grid-cols-md-N ...">
2510
- // responsive="false" disables the mobile-first stacking behaviour
2511
- result = result.replace(
2512
- /\[grid([^\]]*)\]([\s\S]*?)\[\/grid\]/gi,
2513
- (_, attrStr, inner) => {
2514
- const attrs = parseShortcodeAttrs(attrStr);
2515
- const classes = ['grid'];
2516
- if (attrs.cols) {
2517
- if (attrs.responsive === 'false') {
2518
- classes.push(`grid-cols-${classToken(attrs.cols)}`);
2519
- } else {
2520
- classes.push(...responsiveGridCols(attrs.cols));
2458
+ // Parse balanced containers from the outside, restoring code before entering each child store.
2459
+ function processGridBlocks(markdown, depth = 0) {
2460
+ if (depth >= 64) return markdown;
2461
+ const {scrubbed, restore} = scrubCodeRegions(markdown);
2462
+ const renderers = {
2463
+ background: (attrStr, inner) => {
2464
+ const css = backgroundStyle(parseShortcodeAttrs(attrStr));
2465
+ const body = markedBody(processCardBlocks(processInlineShortcodes(inner.trim())));
2466
+ return `<section class="cms-background"${css ? ` style="${escapeAttr(css)}"` : ''}>${body}</section>\n`;
2467
+ },
2468
+ col: (attrStr, body) => {
2469
+ const attrs = parseShortcodeAttrs(attrStr);
2470
+ const injected = extractInjectedEffects(attrs, ['reveal', 'breathe', 'animate', 'ripple']);
2471
+ const baseCls = attrs.span ? `col-span-${classToken(attrs.span)}` : 'col';
2472
+ // Explicit alignment takes precedence over the shorthand flags.
2473
+ const alignment = typeof attrs.align === 'string'
2474
+ ? attrs.align.trim().toLowerCase()
2475
+ : ['center', 'centre', 'left', 'right'].find(value => attrs[value] === true);
2476
+ const align = alignment === 'centre' ? 'center' : alignment;
2477
+ const alignClasses = ['left', 'center', 'right'].includes(align) ? [`text-${align}`] : [];
2478
+ const classes = [baseCls, ...alignClasses, ...injected.effectClasses];
2479
+ const id = attrs.id ? ` id="${escapeAttr(attrs.id)}"` : '';
2480
+ return `<div class="${classes.join(' ')}"${id}${injected.effectDataAttrs}>${markedBody(processCardBlocks(processInlineShortcodes(body.trim())))}</div>`;
2481
+ },
2482
+ row: (attrStr, inner) => {
2483
+ const attrs = parseShortcodeAttrs(attrStr);
2484
+ const classes = ['row'];
2485
+ if (attrs.gap) classes.push(`gap-${classToken(attrs.gap)}`);
2486
+ if (attrs.class) classes.push(escapeAttr(attrs.class));
2487
+ const id = attrs.id ? ` id="${escapeAttr(attrs.id)}"` : '';
2488
+ const reveal = attrs.reveal !== undefined ? ' data-reveal="true"' : '';
2489
+ const revealMode = attrs['reveal-mode'] ? ` data-reveal-mode="${escapeAttr(attrs['reveal-mode'])}"` : '';
2490
+ const revealAnimation = attrs['reveal-animation'] ? ` data-reveal-animation="${escapeAttr(attrs['reveal-animation'])}"` : '';
2491
+ const revealDuration = attrs['reveal-duration'] ? ` data-reveal-duration="${escapeAttr(attrs['reveal-duration'])}"` : '';
2492
+ const revealStagger = attrs['reveal-stagger'] ? ` data-reveal-stagger="${escapeAttr(attrs['reveal-stagger'])}"` : '';
2493
+ const revealDelay = attrs['reveal-delay'] ? ` data-reveal-delay="${escapeAttr(attrs['reveal-delay'])}"` : '';
2494
+ const revealDirection = attrs['reveal-direction'] ? ` data-reveal-direction="${escapeAttr(attrs['reveal-direction'])}"` : '';
2495
+ const revealReplay = isTruthyAttr(attrs['reveal-replay']) ? ' data-reveal-replay="true"' : '';
2496
+ const tilt = isTruthyAttr(attrs.tilt) ? ' data-tilt="true"' : '';
2497
+ return `<div class="${classes.join(' ')}"${id}${reveal}${revealMode}${revealAnimation}${revealDuration}${revealStagger}${revealDelay}${revealDirection}${revealReplay}${tilt}>${markedBody(processCardBlocks(processInlineShortcodes(inner.trim())))}</div>\n`;
2498
+ },
2499
+ grid: (attrStr, inner) => {
2500
+ const attrs = parseShortcodeAttrs(attrStr);
2501
+ const classes = ['grid'];
2502
+ if (attrs.cols) {
2503
+ classes.push(...(attrs.responsive === 'false'
2504
+ ? [`grid-cols-${classToken(attrs.cols)}`]
2505
+ : responsiveGridCols(attrs.cols)));
2521
2506
  }
2507
+ if (attrs.gap) classes.push(`gap-${classToken(attrs.gap)}`);
2508
+ if (attrs.class) classes.push(escapeAttr(attrs.class));
2509
+ if (attrs.fullwidth === 'true') classes.push('grid-breakout');
2510
+ const id = attrs.id ? ` id="${escapeAttr(attrs.id)}"` : '';
2511
+ return `<div class="${classes.join(' ')}"${id}>${markedBody(processCardBlocks(processInlineShortcodes(inner.trim())))}</div>\n`;
2522
2512
  }
2523
- if (attrs.gap) classes.push(`gap-${classToken(attrs.gap)}`);
2524
- if (attrs.class) classes.push(escapeAttr(attrs.class));
2525
- if (attrs.fullwidth === 'true') classes.push('grid-breakout');
2526
- const id = attrs.id ? ` id="${escapeAttr(attrs.id)}"` : '';
2527
- return `<div class="${classes.join(' ')}"${id}>${inner}</div>\n`;
2513
+ };
2514
+ let result = scrubbed;
2515
+ for (const range of pairedRanges(scrubbed, new Set(['grid', 'row', 'col', 'background'])).reverse()) {
2516
+ const inner = processGridBlocks(restore(scrubbed.slice(range.bodyStart, range.bodyEnd)), depth + 1);
2517
+ const html = renderers[range.name](range.attrs, inner);
2518
+ result = result.slice(0, range.start) + html + result.slice(range.end);
2528
2519
  }
2529
- );
2520
+ return restore(result);
2521
+ }
2530
2522
 
2531
- return restore(result);
2523
+ /** Extract page-level singleton tags before any container can render or escape them. */
2524
+ function extractPageBackground(markdown) {
2525
+ const {scrubbed, restore} = scrubCodeRegions(markdown);
2526
+ const sections = pairedRanges(scrubbed, new Set(['background']));
2527
+ let background = null;
2528
+ const output = scrubbed.replace(/\[background(?=[\s/\]])((?:"[^"]*"|'[^']*'|[^\]"'])*?)\]/gi, (tag, attrs, offset) => {
2529
+ if (sections.some(range => offset >= range.start && offset < range.end)) return tag;
2530
+ background = normaliseBackground(parseShortcodeAttrs(attrs.replace(/\/\s*$/, ''))) || background;
2531
+ return '';
2532
+ });
2533
+ return {output: restore(output), background};
2532
2534
  }
2533
2535
 
2534
2536
  /**
@@ -2702,7 +2704,9 @@ function cardVariantClasses(attrs) {
2702
2704
  const rounded = typeof attrs.rounded === 'string' ? attrs.rounded.trim() : '';
2703
2705
  if (['none', 'xs', 'sm', 'lg', 'full'].includes(rounded)) classes.push(`card-rounded-${rounded}`);
2704
2706
  const textAlign = typeof attrs['text-align'] === 'string' ? attrs['text-align'].trim() : '';
2705
- if (['center', 'right'].includes(textAlign)) classes.push(`card-align-${textAlign}`);
2707
+ if (['left', 'center', 'right'].includes(textAlign)) classes.push(`card-align-${textAlign}`);
2708
+ const bodyAlign = typeof attrs['body-align'] === 'string' ? attrs['body-align'].trim().toLowerCase() : '';
2709
+ if (['left', 'center', 'right'].includes(bodyAlign)) classes.push(`card-body-align-${bodyAlign}`);
2706
2710
  const padding = typeof attrs.padding === 'string' ? attrs.padding.trim() : '';
2707
2711
  if (['compact', 'spacious'].includes(padding)) classes.push(`card-pad-${padding}`);
2708
2712
  // span="2".."6" or "full": how many columns the card takes in a [grid].
@@ -3418,10 +3422,9 @@ function processInlineShortcodes(markdown) {
3418
3422
  * works the same. A header is never drawn: title, subtitle, icon, image and
3419
3423
  * layout are dropped.
3420
3424
  *
3421
- * Runs at the top of processCardBlocks, so it reaches every place a card does
3422
- * (every container renders its nested body through processCardBlocks), and a box
3423
- * renders its own body through processCardBlocks - a [card] inside a [box] and a
3424
- * [box] inside a [card] both work. Like [card], a [box] cannot hold another [box].
3425
+ * Rendered by processCardBlocks, so it reaches every place a card does
3426
+ * (every container renders its nested body through processCardBlocks). Cards
3427
+ * and boxes can nest, including another container of the same kind.
3425
3428
  *
3426
3429
  * Colour follows the theme: a bare box is drawn from the theme's card tokens
3427
3430
  * (Domma's .card), and `color="primary|secondary|success|info|warning|danger"`
@@ -3432,37 +3435,30 @@ function processInlineShortcodes(markdown) {
3432
3435
  * a valid one replaces `variant` (their colours would clash).
3433
3436
  * `variant="primary"` gives the primary border, as on a classic [card].
3434
3437
  *
3435
- * @param {string} markdown
3438
+ * @param {object} attrs
3439
+ * @param {string} body
3436
3440
  * @returns {string}
3437
3441
  */
3438
- function processBoxBlocks(markdown) {
3439
- if (!/\[box[\s\]]/i.test(markdown)) return markdown;
3440
- const {scrubbed, restore} = scrubCodeRegions(markdown);
3441
- return restore(scrubbed.replace(
3442
- /\[box([^\]]*)\]([\s\S]*?)\[\/box\]/gi,
3443
- (_, attrStr, body) => {
3444
- const attrs = parseShortcodeAttrs(attrStr);
3445
- for (const k of ['title', 'subtitle', 'icon', 'icon-layout', 'icon-size', 'icon-align', 'image', 'layout']) delete attrs[k];
3446
- if (!('shadow' in attrs)) attrs.shadow = 'none';
3447
- if (!('rounded' in attrs)) attrs.rounded = 'xs';
3448
- const tone = boxTone(attrs.color ?? attrs.colour);
3449
- const extra = [];
3450
- // A colour replaces the variant's own colours: the two together
3451
- // would pair one's background with the other's text.
3452
- if (tone) {
3453
- delete attrs.variant;
3454
- delete attrs.gradient;
3455
- extra.push(...tone.classes);
3456
- } else if (typeof attrs.variant === 'string' && attrs.variant.trim() === 'primary') {
3457
- extra.push('card-primary');
3458
- }
3459
- attrs.class = ['dm-box', ...extra, typeof attrs.class === 'string' ? attrs.class.trim() : ''].filter(Boolean).join(' ');
3460
- const html = LAYOUT_RENDERERS['no-header-footer'](attrs, processCardBlocks(restore(body)));
3461
- // cardRoot writes no style attribute, so the custom colour goes on
3462
- // the first tag (the box root) here.
3463
- return tone?.style ? html.replace(/^<div /, `<div style="${tone.style}" `) : html;
3464
- }
3465
- ));
3442
+ function renderBox(attrs, body) {
3443
+ for (const k of ['title', 'subtitle', 'icon', 'icon-layout', 'icon-size', 'icon-align', 'image', 'layout']) delete attrs[k];
3444
+ if (!('shadow' in attrs)) attrs.shadow = 'none';
3445
+ if (!('rounded' in attrs)) attrs.rounded = 'xs';
3446
+ const tone = boxTone(attrs.color ?? attrs.colour);
3447
+ const extra = [];
3448
+ // A colour replaces the variant's own colours: the two together
3449
+ // would pair one's background with the other's text.
3450
+ if (tone) {
3451
+ delete attrs.variant;
3452
+ delete attrs.gradient;
3453
+ extra.push(...tone.classes);
3454
+ } else if (typeof attrs.variant === 'string' && attrs.variant.trim() === 'primary') {
3455
+ extra.push('card-primary');
3456
+ }
3457
+ attrs.class = ['dm-box', ...extra, typeof attrs.class === 'string' ? attrs.class.trim() : ''].filter(Boolean).join(' ');
3458
+ const html = LAYOUT_RENDERERS['no-header-footer'](attrs, body);
3459
+ // cardRoot writes no style attribute, so the custom colour goes on
3460
+ // the first tag (the box root) here.
3461
+ return tone?.style ? html.replace(/^<div /, `<div style="${tone.style}" `) : html;
3466
3462
  }
3467
3463
 
3468
3464
  /** Theme colours a [box] can be tinted with - each maps to the --dm-<name> token. */
@@ -3510,27 +3506,55 @@ function readableOn(hex) {
3510
3506
  return darkText >= whiteText ? `#${dark}` : '#ffffff';
3511
3507
  }
3512
3508
 
3509
+ /** Balanced card/box pairs, retaining the legacy parser's tolerance of stray quotes. */
3510
+ function cardContainerRanges(text) {
3511
+ const stack = [], pairs = [];
3512
+ // Prefer complete quoted values (which may contain ]). If the author has
3513
+ // left a quote unmatched, still consume the tag and let the attribute
3514
+ // parser and escaping handle its values, as the old card parser did.
3515
+ const tags = /\[(\/)?(card|box)(?=[\s\]])((?:"[^"]*"|'[^']*'|[^\]"'])*|[^\]]*)\]/gi;
3516
+ for (const match of text.matchAll(tags)) {
3517
+ const name = match[2].toLowerCase();
3518
+ if (!match[1]) {
3519
+ stack.push({name, start: match.index, bodyStart: match.index + match[0].length, attrs: match[3]});
3520
+ continue;
3521
+ }
3522
+ const at = stack.findLastIndex(open => open.name === name);
3523
+ if (at < 0) continue;
3524
+ const open = stack[at];
3525
+ stack.length = at;
3526
+ pairs.push({...open, bodyEnd: match.index, end: match.index + match[0].length});
3527
+ }
3528
+ return pairs.filter(p => !pairs.some(q => q.start < p.start && q.end >= p.end));
3529
+ }
3530
+
3513
3531
  function processCardBlocks(markdown) {
3514
- markdown = processBoxBlocks(markdown);
3515
3532
  const {scrubbed, restore} = scrubCodeRegions(markdown);
3516
- return restore(scrubbed.replace(
3517
- /\[card([^\]]*)\]([\s\S]*?)\[\/card\]/gi,
3518
- (_, attrStr, body) => {
3519
- const attrs = parseShortcodeAttrs(attrStr);
3533
+ const held = new Map();
3534
+ const nonce = randomUUID();
3535
+ // Keep rendered children opaque while the parent extracts its own header,
3536
+ // footer and layout sub-tags, and while marked parses its Markdown body.
3537
+ const render = (source, nested = false) => {
3538
+ let output = source;
3539
+ for (const range of cardContainerRanges(source).reverse()) {
3540
+ const attrs = parseShortcodeAttrs(range.attrs);
3520
3541
  const layout = typeof attrs.layout === 'string' ? attrs.layout.trim() : '';
3521
- const renderer = LAYOUT_RENDERERS[layout];
3522
- // Restore code regions INSIDE the card body before rendering so
3523
- // marked can process fenced code blocks (```lang ... ```) normally.
3524
- // Without this, the body contains placeholder tokens that marked
3525
- // wraps in <p>, and the outer restore() call then substitutes raw
3526
- // backticks into the <p>, producing literal '```json' text and
3527
- // collapsing the HTML on any inline-backtick template literal.
3528
- const restoredBody = restore(body);
3529
- return renderer
3530
- ? renderer(attrs, restoredBody, marked, escapeAttr)
3531
- : renderLegacyCard(attrs, restoredBody, marked, escapeAttr);
3532
- }
3533
- ));
3542
+ const rawBody = source.slice(range.bodyStart, range.bodyEnd);
3543
+ const body = restore(range.name === 'card' && layout === 'code-snippet'
3544
+ ? rawBody : render(rawBody, true));
3545
+ const renderer = LAYOUT_RENDERERS[layout] || renderLegacyCard;
3546
+ const html = range.name === 'box'
3547
+ ? renderBox(attrs, body)
3548
+ : renderer(attrs, body, marked, escapeAttr);
3549
+ const token = `<!--cms-card-${nonce}-${held.size}-->`;
3550
+ held.set(token, html);
3551
+ const gap = nested ? '\n\n' : '';
3552
+ output = output.slice(0, range.start) + gap + token + gap + output.slice(range.end);
3553
+ }
3554
+ return output;
3555
+ };
3556
+ const expand = text => text.replace(new RegExp(`<!--cms-card-${nonce}-\\d+-->`, 'g'), token => expand(held.get(token)));
3557
+ return expand(restore(render(scrubbed)));
3534
3558
  }
3535
3559
 
3536
3560
  /**
@@ -5449,7 +5473,7 @@ export async function parseMarkdown(raw, opts = {}) {
5449
5473
  // → dconfig → effects → plugin shortcodes → tabs → accordion → carousel → countdown → timeline
5450
5474
  // → listgroup → spacer → center → icon → demo → embed → image → form → hero → table
5451
5475
  // → badge → text → button → link → cta → grid → card (+ box) → banner → slideover
5452
- // → marked → sanitize → afterParse
5476
+ // → background → marked → sanitize → afterParse
5453
5477
  // Comments must be removed before shortcodes are expanded. Protect code
5454
5478
  // examples first; four-space-indented lines remain Markdown code too.
5455
5479
  const comments = scrubCodeRegions(content, true);
@@ -5461,7 +5485,8 @@ export async function parseMarkdown(raw, opts = {}) {
5461
5485
  ...(opts.expiry || {}), urlPath: opts.urlPath || '/', parseAttrs: parseShortcodeAttrs
5462
5486
  });
5463
5487
  const visible = expirySafe.restore(expiry.markdown);
5464
- const preprocessed = opts[SLOT_FRAGMENT] ? visible : applyTransforms('markdown:beforeParse', visible);
5488
+ const withBackground = extractPageBackground(visible);
5489
+ const preprocessed = opts[SLOT_FRAGMENT] ? withBackground.output : applyTransforms('markdown:beforeParse', withBackground.output);
5465
5490
  const tagSet = new Set();
5466
5491
  const flags = {perViewer: false, hasExpiry:expiry.hasExpiry};
5467
5492
  const slotComponents = new Set();
@@ -5516,7 +5541,7 @@ export async function parseMarkdown(raw, opts = {}) {
5516
5541
  const filteredUsed = [...usedComponents].filter(name => allowed.has(name));
5517
5542
 
5518
5543
  // `content` is the body as written: the editor loads it from here, and the nesting indent is the person's.
5519
- return {data, content: written, html, usedComponents: filteredUsed, tags: [...tagSet], perViewer: flags.perViewer, hasExpiry:flags.hasExpiry};
5544
+ return {data, content: written, html, background: withBackground.background, usedComponents: filteredUsed, tags: [...tagSet], perViewer: flags.perViewer, hasExpiry:flags.hasExpiry};
5520
5545
  }
5521
5546
 
5522
5547
  /**
@@ -1,3 +1,4 @@
1
+ import {pageBackgroundStyleTag} from '../../public/js/background-style.mjs';
1
2
  /**
2
3
  * Renderer Service
3
4
  * Assembles the full HTML page shell from the template + page data + site config.
@@ -672,7 +673,7 @@ export async function renderPage(page, opts = {}) {
672
673
  // generated, custom.css is hand-written, and the hand-written one stays
673
674
  // the last word.
674
675
  headInjectLate: [injection.headLate, searchAssets.headTag, motionAssets.headTag, embed ? '' : switcherAssets.headTag,
675
- launcherAssets.headTag, embed ? EMBED_HEAD_TAG : '', themeView.customThemeStyleTag, themeView.overrideStyleTag, customCssTag, navbarStyleTag]
676
+ launcherAssets.headTag, embed ? EMBED_HEAD_TAG : '', themeView.customThemeStyleTag, themeView.overrideStyleTag, themeView.backgroundStyleTag, customCssTag, navbarStyleTag]
676
677
  .filter(Boolean).join('\n'),
677
678
  bodyEndInject: [
678
679
  // Draft banner - first, so it is the topmost fixed element and a
@@ -1189,7 +1190,8 @@ async function buildThemeView(page = {}) {
1189
1190
  fontStyleTag: fontOverride ? `<style>${fontOverride}</style>` : '',
1190
1191
  // Only the custom themes this page can show: its own, and day/night's.
1191
1192
  customThemeStyleTag: buildCustomThemeStyleTag([activeTheme, autoTheme?.dayTheme, autoTheme?.nightTheme]),
1192
- overrideStyleTag: buildOverrideStyleTag(cfg)
1193
+ overrideStyleTag: buildOverrideStyleTag(cfg),
1194
+ backgroundStyleTag: pageBackgroundStyleTag(page.background || cfg.background)
1193
1195
  };
1194
1196
  }
1195
1197
 
@@ -1455,7 +1457,7 @@ export async function renderBlogPage(templatePath, data = {}, seoMeta = {}) {
1455
1457
  // Theme overrides land BEFORE content/custom.css: the overrides are
1456
1458
  // generated, custom.css is hand-written, and the hand-written one stays
1457
1459
  // the last word.
1458
- headInjectLate: [bare ? '' : injection.headLate, searchAssets.headTag, motionAssets.headTag, switcherAssets.headTag, launcherAssets.headTag, themeView.customThemeStyleTag, themeView.overrideStyleTag, customCssTag, navbarStyleTag]
1460
+ headInjectLate: [bare ? '' : injection.headLate, searchAssets.headTag, motionAssets.headTag, switcherAssets.headTag, launcherAssets.headTag, themeView.customThemeStyleTag, themeView.overrideStyleTag, themeView.backgroundStyleTag, customCssTag, navbarStyleTag]
1459
1461
  .filter(Boolean).join('\n'),
1460
1462
  bodyEndInject: [
1461
1463
  overlayMenus,
@@ -1,3 +1,4 @@
1
+ import {normaliseBackground} from '../../public/js/background-style.mjs';
1
2
  /**
2
3
  * Theme settings - config/theme.json.
3
4
  *
@@ -109,6 +110,7 @@ export function defaultThemeConfig() {
109
110
  lightTheme: 'charcoal-light',
110
111
  darkTheme: 'charcoal-dark'
111
112
  },
113
+ background: null,
112
114
  overrides: []
113
115
  };
114
116
  }
@@ -412,6 +414,7 @@ function definedOnly(obj) {
412
414
  function mergeDefaults(raw) {
413
415
  const d = defaultThemeConfig();
414
416
  const cfg = {...d, ...definedOnly(raw)};
417
+ cfg.background = normaliseBackground(raw?.background);
415
418
  cfg.autoTheme = {...d.autoTheme, ...definedOnly(raw?.autoTheme)};
416
419
  cfg.font = {...d.font, ...definedOnly(raw?.font)};
417
420
  cfg.switcher = {...d.switcher, ...definedOnly(raw?.switcher)};
@@ -649,6 +652,7 @@ export function validateThemeConfig(input, {remembered = [], currentSwitcher = {
649
652
  const errors = [];
650
653
  if (!input || typeof input !== 'object') return ['Theme config must be an object'];
651
654
 
655
+ if (input.background != null && !normaliseBackground(input.background)) errors.push('Choose a valid background type, preset or colour');
652
656
  const builtins = listThemeIds();
653
657
  // Custom themes (a plugin's) are chosen like any other - except by the
654
658
  // public switcher below, which switches through Domma's engine. One the
@@ -25,7 +25,7 @@
25
25
  <link rel="stylesheet" href="/dist/domma/themes/domma-themes.css">
26
26
 
27
27
  <!-- Site CSS -->
28
- <link rel="stylesheet" href="/public/css/site.css?v=20261108-hero-outline">
28
+ <link rel="stylesheet" href="/public/css/site.css?v=20261112-backgrounds">
29
29
  <link rel="stylesheet" href="/public/css/forms.css?v=20261031-forms-reduce-motion">
30
30
  <!-- Menu item hover / current-page effects. Loaded after site.css so a
31
31
  menu's own highlight wins over the blanket link styling there. -->
@@ -189,7 +189,7 @@
189
189
  <script src="/public/js/form-logic-engine.js?v=20261031-forms-reduce-motion" defer></script>
190
190
 
191
191
  <!-- Site initialisation -->
192
- <script src="/public/js/site.js?v=20261111-one-menu-float" type="module"></script>
192
+ <script src="/public/js/site.js?v=20261112-card-body-align" type="module"></script>
193
193
  <script src="/public/js/collection-context.js?v=20261010-utf8-payloads" type="module"></script>
194
194
  {{ctxMenusModule}}
195
195
  <!-- [image zoom] pictures' full-size view - only on a page that has one -->