@bendyline/squisq 1.4.1 → 1.5.1
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.
- package/README.md +14 -1
- package/dist/{ContentContainer-DNx460y8.d.ts → ContentContainer-BXUlIf18.d.ts} +6 -2
- package/dist/{Doc-BeSeH2iX.d.ts → Doc-BBVGq1_9.d.ts} +922 -273
- package/dist/{ImageEditDoc-BTIvw0oq.d.ts → ImageEditDoc-FuyGtt6o.d.ts} +11 -4
- package/dist/{chunk-ZTX4PFFT.js → chunk-2OIBZYKP.js} +75 -2
- package/dist/chunk-2OIBZYKP.js.map +1 -0
- package/dist/chunk-2UQOHYE2.js +45 -0
- package/dist/chunk-2UQOHYE2.js.map +1 -0
- package/dist/chunk-6ATE2PSM.js +344 -0
- package/dist/chunk-6ATE2PSM.js.map +1 -0
- package/dist/{chunk-57CVQCFX.js → chunk-A4O7GIWE.js} +74 -23
- package/dist/chunk-A4O7GIWE.js.map +1 -0
- package/dist/{chunk-5WFRKURX.js → chunk-DLXZMS5K.js} +4 -2
- package/dist/chunk-DLXZMS5K.js.map +1 -0
- package/dist/chunk-ET53IIEP.js +1 -0
- package/dist/chunk-ET53IIEP.js.map +1 -0
- package/dist/chunk-HWVFJAAH.js +362 -0
- package/dist/chunk-HWVFJAAH.js.map +1 -0
- package/dist/{chunk-2TMAWB4Y.js → chunk-IMSCRLLV.js} +1 -1
- package/dist/chunk-IMSCRLLV.js.map +1 -0
- package/dist/{chunk-B4EEON3N.js → chunk-KKNUBQ6Y.js} +536 -103
- package/dist/chunk-KKNUBQ6Y.js.map +1 -0
- package/dist/chunk-LDQ2HJIX.js +596 -0
- package/dist/chunk-LDQ2HJIX.js.map +1 -0
- package/dist/chunk-LH7I6SH7.js +7208 -0
- package/dist/chunk-LH7I6SH7.js.map +1 -0
- package/dist/chunk-PGGGKYWG.js +1 -0
- package/dist/chunk-PGGGKYWG.js.map +1 -0
- package/dist/{chunk-7UDSRZKG.js → chunk-Q3ROPT5H.js} +35 -14
- package/dist/chunk-Q3ROPT5H.js.map +1 -0
- package/dist/chunk-QE7TWGVT.js +178 -0
- package/dist/chunk-QE7TWGVT.js.map +1 -0
- package/dist/chunk-RUDYOTA6.js +345 -0
- package/dist/chunk-RUDYOTA6.js.map +1 -0
- package/dist/{chunk-K32VJONL.js → chunk-T5UK6YOB.js} +41 -2
- package/dist/chunk-T5UK6YOB.js.map +1 -0
- package/dist/{chunk-3K5OG6KI.js → chunk-TEEEILMP.js} +412 -186
- package/dist/chunk-TEEEILMP.js.map +1 -0
- package/dist/{chunk-FR2RBTKO.js → chunk-TQWLI6S2.js} +93 -27
- package/dist/chunk-TQWLI6S2.js.map +1 -0
- package/dist/{chunk-WMOI7FN3.js → chunk-UY7KGQ5R.js} +12 -2
- package/dist/{chunk-WMOI7FN3.js.map → chunk-UY7KGQ5R.js.map} +1 -1
- package/dist/{chunk-3E5F2XMR.js → chunk-VWUFZ6ZG.js} +29 -2
- package/dist/chunk-VWUFZ6ZG.js.map +1 -0
- package/dist/chunk-ZLQKNOZQ.js +1 -0
- package/dist/chunk-ZLQKNOZQ.js.map +1 -0
- package/dist/doc/index.d.ts +5 -5
- package/dist/doc/index.js +135 -8
- package/dist/generate/index.d.ts +3 -74
- package/dist/generate/index.js +2 -7
- package/dist/icons/index.d.ts +3 -26
- package/dist/icons/index.js +13 -0
- package/dist/icons/inlineIconMarker.d.ts +1 -0
- package/dist/icons/inlineIconMarker.js +15 -0
- package/dist/icons/inlineIconMarker.js.map +1 -0
- package/dist/imageEdit/index.d.ts +12 -6
- package/dist/imageEdit/index.js +4 -1
- package/dist/index.d.ts +14 -11
- package/dist/index.js +265 -37
- package/dist/inlineIconMarker-CiE8Hlvz.d.ts +59 -0
- package/dist/jsonForm/index.d.ts +42 -1
- package/dist/jsonForm/index.js +9 -1
- package/dist/markdown/index.d.ts +228 -3
- package/dist/markdown/index.js +42 -7
- package/dist/recommend/index.d.ts +1 -1
- package/dist/recommend/index.js +3 -2
- package/dist/schemas/index.d.ts +28 -8
- package/dist/schemas/index.js +36 -8
- package/dist/spatial/index.d.ts +9 -4
- package/dist/spatial/index.js +1 -1
- package/dist/storage/index.d.ts +2 -2
- package/dist/storage/index.js +1 -1
- package/dist/story/index.d.ts +1021 -41
- package/dist/story/index.js +135 -8
- package/dist/{themeLibrary-BHjJ0Qx6.d.ts → themeLibrary-CehcJhzz.d.ts} +1 -1
- package/dist/timing/index.js +3 -5
- package/dist/transform/index.d.ts +48 -10
- package/dist/transform/index.js +17 -481
- package/dist/transform/index.js.map +1 -1
- package/dist/{types-BdZkdJ3z.d.ts → types-DlAZ7MW4.d.ts} +115 -1
- package/dist/versions/index.d.ts +1 -1
- package/package.json +6 -1
- package/src/__tests__/animationUtils.test.ts +40 -0
- package/src/__tests__/annotationCoercion.test.ts +243 -0
- package/src/__tests__/applyRenderStyle.test.ts +146 -0
- package/src/__tests__/atmosphereLayers.test.ts +108 -0
- package/src/__tests__/attrTokens.test.ts +162 -0
- package/src/__tests__/contentExtractor.test.ts +60 -0
- package/src/__tests__/coverBlock.test.ts +46 -1
- package/src/__tests__/customTemplateSample.test.ts +144 -0
- package/src/__tests__/customTemplatesFrontmatter.test.ts +236 -0
- package/src/__tests__/customThemesFrontmatter.test.ts +145 -0
- package/src/__tests__/diagramBlock.test.ts +122 -0
- package/src/__tests__/diagramLayout.test.ts +134 -0
- package/src/__tests__/drawing.test.ts +109 -0
- package/src/__tests__/drawingBlock.test.ts +124 -0
- package/src/__tests__/drawingLayout.test.ts +171 -0
- package/src/__tests__/geohash.test.ts +6 -5
- package/src/__tests__/getLayers.test.ts +6 -2
- package/src/__tests__/getLayersFallback.test.ts +103 -0
- package/src/__tests__/imageEditExportSvg.test.ts +70 -0
- package/src/__tests__/imageEditVersions.test.ts +72 -0
- package/src/__tests__/inlineIconMarker.test.ts +36 -0
- package/src/__tests__/inputDescriptors.test.ts +162 -0
- package/src/__tests__/jsonForm.tokens.test.ts +84 -0
- package/src/__tests__/layoutBlock.test.ts +83 -0
- package/src/__tests__/layoutLayout.test.ts +169 -0
- package/src/__tests__/markdown.test.ts +87 -0
- package/src/__tests__/markdownSanitize.test.ts +79 -0
- package/src/__tests__/markdownToDoc.test.ts +391 -2
- package/src/__tests__/mediaAnnotations.test.ts +91 -0
- package/src/__tests__/mediaSchedule.test.ts +118 -0
- package/src/__tests__/pandocAttrParse.test.ts +187 -0
- package/src/__tests__/resolveDocTheme.test.ts +55 -0
- package/src/__tests__/rootExports.test.ts +43 -0
- package/src/__tests__/shapeGeometry.test.ts +89 -0
- package/src/__tests__/shapeVocabulary.test.ts +133 -0
- package/src/__tests__/structuredData.test.ts +249 -0
- package/src/__tests__/templateAnnotationParse.test.ts +108 -0
- package/src/__tests__/templateMetadata.test.ts +31 -0
- package/src/__tests__/templates.test.ts +257 -4
- package/src/__tests__/themeCompile.test.ts +42 -0
- package/src/__tests__/themeValidator.test.ts +6 -0
- package/src/__tests__/transformV2.test.ts +137 -0
- package/src/__tests__/transitionNormalize.test.ts +61 -0
- package/src/__tests__/validateDoc.test.ts +260 -0
- package/src/doc/annotationBlocks.ts +117 -0
- package/src/doc/customTemplatesFrontmatter.ts +314 -0
- package/src/doc/customThemesFrontmatter.ts +95 -0
- package/src/doc/docToMarkdown.ts +104 -5
- package/src/doc/getLayers.ts +49 -17
- package/src/doc/index.ts +47 -1
- package/src/doc/markdownToDoc.ts +411 -13
- package/src/doc/mediaAnnotations.ts +100 -0
- package/src/doc/resolveDocTheme.ts +55 -0
- package/src/doc/standaloneAnnotation.ts +58 -0
- package/src/doc/structuredData.ts +301 -0
- package/src/doc/templateInputs.ts +240 -0
- package/src/doc/templates/__tests__/customTemplate.test.ts +170 -0
- package/src/doc/templates/__tests__/customTemplateRegistry.test.ts +110 -0
- package/src/doc/templates/accentImage.ts +30 -6
- package/src/doc/templates/captionUtils.ts +23 -0
- package/src/doc/templates/comparisonBar.ts +33 -18
- package/src/doc/templates/coverBlock.ts +35 -5
- package/src/doc/templates/customTemplate.ts +51 -0
- package/src/doc/templates/dataTable.ts +37 -19
- package/src/doc/templates/dateEvent.ts +41 -20
- package/src/doc/templates/definitionCard.ts +26 -18
- package/src/doc/templates/diagramBlock.ts +204 -0
- package/src/doc/templates/diagramLayout.ts +159 -0
- package/src/doc/templates/drawingBlock.ts +325 -0
- package/src/doc/templates/drawingLayout.ts +539 -0
- package/src/doc/templates/factCard.ts +54 -26
- package/src/doc/templates/fallbackBlock.ts +123 -0
- package/src/doc/templates/featureBlock.ts +20 -13
- package/src/doc/templates/fullBleedQuote.ts +18 -8
- package/src/doc/templates/imageWithCaption.ts +30 -15
- package/src/doc/templates/index.ts +225 -46
- package/src/doc/templates/inputDescriptors.ts +432 -0
- package/src/doc/templates/layoutBlock.ts +43 -0
- package/src/doc/templates/layoutLayout.ts +243 -0
- package/src/doc/templates/listBlock.ts +56 -30
- package/src/doc/templates/mapBlock.ts +15 -12
- package/src/doc/templates/metadata.ts +120 -0
- package/src/doc/templates/persistentLayers.ts +129 -11
- package/src/doc/templates/photoGrid.ts +22 -34
- package/src/doc/templates/pullQuote.ts +30 -12
- package/src/doc/templates/quoteBlock.ts +54 -29
- package/src/doc/templates/sectionHeader.ts +25 -11
- package/src/doc/templates/statHighlight.ts +39 -22
- package/src/doc/templates/titleBlock.ts +59 -21
- package/src/doc/templates/tokens/__tests__/resolveTokens.test.ts +487 -0
- package/src/doc/templates/tokens/resolveTokens.ts +453 -0
- package/src/doc/templates/twoColumn.ts +48 -30
- package/src/doc/templates/videoPullQuote.ts +22 -12
- package/src/doc/templates/videoWithCaption.ts +21 -15
- package/src/doc/utils/animationUtils.ts +267 -3
- package/src/doc/utils/applyRenderStyle.ts +113 -0
- package/src/doc/utils/imageTreatment.ts +70 -0
- package/src/doc/utils/nearest.ts +59 -0
- package/src/doc/utils/shapeGeometry.ts +464 -0
- package/src/doc/utils/themeUtils.ts +75 -1
- package/src/doc/validate.ts +575 -0
- package/src/generate/contentExtractor.ts +148 -35
- package/src/generate/index.ts +0 -3
- package/src/icons/index.ts +8 -0
- package/src/icons/inlineIconMarker.ts +73 -0
- package/src/imageEdit/export.ts +85 -2
- package/src/imageEdit/index.ts +1 -0
- package/src/imageEdit/persistence.ts +51 -0
- package/src/index.ts +2 -0
- package/src/jsonForm/index.ts +2 -0
- package/src/jsonForm/tokens.ts +78 -0
- package/src/markdown/annotationCoercion.ts +295 -0
- package/src/markdown/attrTokens.ts +241 -0
- package/src/markdown/convert.ts +229 -26
- package/src/markdown/index.ts +37 -0
- package/src/markdown/sanitize.ts +318 -0
- package/src/markdown/stringify.ts +96 -6
- package/src/markdown/types.ts +66 -0
- package/src/markdown/utils.ts +111 -2
- package/src/recommend/templates.ts +24 -0
- package/src/schemas/BlockTemplates.ts +133 -4
- package/src/schemas/CustomTemplates.ts +126 -0
- package/src/schemas/Doc.ts +387 -65
- package/src/schemas/ImageEditDoc.ts +11 -4
- package/src/schemas/Media.ts +169 -0
- package/src/schemas/Theme.ts +23 -1
- package/src/schemas/Transitions.ts +224 -0
- package/src/schemas/colorUtils.ts +33 -0
- package/src/schemas/fontStacks.ts +5 -2
- package/src/schemas/index.ts +3 -0
- package/src/schemas/themeCompile.ts +24 -5
- package/src/schemas/themeValidator.ts +49 -11
- package/src/schemas/themes/cinematic.json +69 -12
- package/src/schemas/themes/documentary.json +58 -11
- package/src/schemas/themes/gezellig.json +60 -11
- package/src/schemas/themes/magazine.json +54 -9
- package/src/schemas/themes/morning-light.json +52 -9
- package/src/schemas/themes/standard-dark.json +48 -13
- package/src/schemas/themes/standard.json +44 -12
- package/src/schemas/themes/tech-dark.json +65 -12
- package/src/spatial/Geohash.ts +52 -21
- package/src/storage/ContentContainer.ts +6 -2
- package/src/transform/applyTransform.ts +43 -4
- package/src/transform/index.ts +1 -0
- package/src/transform/registry.ts +44 -13
- package/src/transform/styles/dataDriven.ts +2 -1
- package/src/transform/styles/documentary.ts +2 -1
- package/src/transform/styles/magazine.ts +3 -1
- package/src/transform/styles/minimal.ts +2 -1
- package/src/transform/styles/narrative.ts +3 -1
- package/src/transform/templateSelector.ts +87 -11
- package/src/transform/types.ts +35 -2
- package/dist/chunk-2TMAWB4Y.js.map +0 -1
- package/dist/chunk-3E5F2XMR.js.map +0 -1
- package/dist/chunk-3K5OG6KI.js.map +0 -1
- package/dist/chunk-4X3JQXNM.js +0 -35
- package/dist/chunk-4X3JQXNM.js.map +0 -1
- package/dist/chunk-57CVQCFX.js.map +0 -1
- package/dist/chunk-5WFRKURX.js.map +0 -1
- package/dist/chunk-7UDSRZKG.js.map +0 -1
- package/dist/chunk-B4EEON3N.js.map +0 -1
- package/dist/chunk-FR2RBTKO.js.map +0 -1
- package/dist/chunk-H3AXU4MJ.js +0 -179
- package/dist/chunk-H3AXU4MJ.js.map +0 -1
- package/dist/chunk-K32VJONL.js.map +0 -1
- package/dist/chunk-KSWJR66U.js +0 -3706
- package/dist/chunk-KSWJR66U.js.map +0 -1
- package/dist/chunk-MYIH7FWD.js +0 -145
- package/dist/chunk-MYIH7FWD.js.map +0 -1
- package/dist/chunk-ZTX4PFFT.js.map +0 -1
- package/src/__tests__/slideshowGenerator.test.ts +0 -128
- package/src/generate/slideshowGenerator.ts +0 -273
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Standalone-paragraph annotation parser.
|
|
3
|
+
*
|
|
4
|
+
* A paragraph whose entire trimmed text is exactly a `{[…]}` annotation
|
|
5
|
+
* (nothing before or after) is a *standalone annotation*. Two features share
|
|
6
|
+
* this shape:
|
|
7
|
+
*
|
|
8
|
+
* - **Media annotations** (`{[audio …]}` / `{[video …]}`) — lifted into typed
|
|
9
|
+
* {@link import('../schemas/Media.js').MediaClip}s by `mediaAnnotations.ts`.
|
|
10
|
+
* - **Standalone template blocks** (`{[quote]}`, `{[statHighlight …]}`, …) —
|
|
11
|
+
* turned into heading-less {@link import('../schemas/Doc.js').Block}s by
|
|
12
|
+
* `annotationBlocks.ts`.
|
|
13
|
+
*
|
|
14
|
+
* Both call the single parser here so the annotation grammar (quoting,
|
|
15
|
+
* escaping, first-token-is-template) stays identical to the heading form.
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
import {
|
|
19
|
+
matchTrailingTemplateAnnotation,
|
|
20
|
+
tokenizeAttrTokens,
|
|
21
|
+
splitKeyValueToken,
|
|
22
|
+
} from '../markdown/attrTokens.js';
|
|
23
|
+
import type { MarkdownBlockNode } from '../markdown/types.js';
|
|
24
|
+
|
|
25
|
+
/** The template name + params parsed out of a standalone `{[…]}` paragraph. */
|
|
26
|
+
export interface ParsedAnnotation {
|
|
27
|
+
/** First bare token, when the annotation leads with one (e.g. `quote`). */
|
|
28
|
+
template?: string;
|
|
29
|
+
/** Remaining `key=value` tokens, unquoted/unescaped. */
|
|
30
|
+
params: Record<string, string>;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Parse a paragraph node that is *exactly* a `{[…]}` annotation (nothing
|
|
35
|
+
* before or after). Returns the template + params, or null when the node
|
|
36
|
+
* isn't a standalone annotation (not a paragraph, more than one child, a
|
|
37
|
+
* non-text child such as a resolved inline icon, or trailing text).
|
|
38
|
+
*/
|
|
39
|
+
export function parseStandaloneAnnotation(node: MarkdownBlockNode): ParsedAnnotation | null {
|
|
40
|
+
if (node.type !== 'paragraph') return null;
|
|
41
|
+
const children = node.children ?? [];
|
|
42
|
+
if (children.length !== 1 || children[0].type !== 'text') return null;
|
|
43
|
+
const text = children[0].value.trim();
|
|
44
|
+
const match = matchTrailingTemplateAnnotation(text);
|
|
45
|
+
// index 0 means the whole (trimmed) paragraph is the annotation.
|
|
46
|
+
if (!match || match.index !== 0) return null;
|
|
47
|
+
|
|
48
|
+
const tokens = tokenizeAttrTokens(match.inner.trim());
|
|
49
|
+
const firstIsParam = tokens.length > 0 && tokens[0].indexOf('=') > 0;
|
|
50
|
+
const template = firstIsParam || tokens.length === 0 ? undefined : tokens[0];
|
|
51
|
+
const startIdx = firstIsParam ? 0 : 1;
|
|
52
|
+
const params: Record<string, string> = {};
|
|
53
|
+
for (let i = startIdx; i < tokens.length; i++) {
|
|
54
|
+
const kv = splitKeyValueToken(tokens[i]);
|
|
55
|
+
if (kv) params[kv.key] = kv.value;
|
|
56
|
+
}
|
|
57
|
+
return { template, params };
|
|
58
|
+
}
|
|
@@ -0,0 +1,301 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Structured template data from markdown body content.
|
|
3
|
+
*
|
|
4
|
+
* Attribute strings on a heading annotation are fine for scalar params,
|
|
5
|
+
* but tabular or nested inputs (dataTable rows, map markers, chart data)
|
|
6
|
+
* don't pack well into a single quoted line. This module supplies the two
|
|
7
|
+
* structured channels instead:
|
|
8
|
+
*
|
|
9
|
+
* 1. **Data fences** — a fenced code block whose info string is
|
|
10
|
+
* `json data` or `yaml data`, placed in a heading's body content:
|
|
11
|
+
*
|
|
12
|
+
* ````markdown
|
|
13
|
+
* ## Quarterly numbers {[dataTable]}
|
|
14
|
+
*
|
|
15
|
+
* ```json data
|
|
16
|
+
* { "headers": ["Q", "Revenue"], "rows": [["Q1", "1.2M"], ["Q2", "1.4M"]] }
|
|
17
|
+
* ```
|
|
18
|
+
* ````
|
|
19
|
+
*
|
|
20
|
+
* The parsed object lands on `block.templateData` and merges into the
|
|
21
|
+
* template input (after defaults, before `{[…]}` string overrides).
|
|
22
|
+
* The `data` marker keeps ordinary ```json code samples — which should
|
|
23
|
+
* render as code — out of the template input.
|
|
24
|
+
*
|
|
25
|
+
* 2. **GFM tables** — for the `dataTable` template, the first table in the
|
|
26
|
+
* section body supplies `headers` / `rows` / `align` when the author
|
|
27
|
+
* didn't provide them explicitly.
|
|
28
|
+
*
|
|
29
|
+
* YAML support is a documented subset (this package has no YAML
|
|
30
|
+
* dependency): top-level `key: scalar`, `key: [inline, array]`, `key:`
|
|
31
|
+
* followed by an indented `- item` block sequence (scalars or inline
|
|
32
|
+
* arrays), and `key:` followed by *one level* of indented `subkey: scalar`
|
|
33
|
+
* lines (a nested map, e.g. `center:` + indented `lat:` / `lng:`). Deeper
|
|
34
|
+
* nesting, and mixing list items with mapping keys under one key, are
|
|
35
|
+
* rejected with a clear error — use a `json data` fence for those.
|
|
36
|
+
*/
|
|
37
|
+
|
|
38
|
+
import type {
|
|
39
|
+
MarkdownBlockNode,
|
|
40
|
+
MarkdownCodeBlock,
|
|
41
|
+
MarkdownTable,
|
|
42
|
+
MarkdownTableRow,
|
|
43
|
+
} from '../markdown/types.js';
|
|
44
|
+
import { extractPlainText } from '../markdown/utils.js';
|
|
45
|
+
|
|
46
|
+
// ============================================
|
|
47
|
+
// Data fences
|
|
48
|
+
// ============================================
|
|
49
|
+
|
|
50
|
+
/** Languages accepted for data fences. */
|
|
51
|
+
const DATA_FENCE_LANGS = new Set(['json', 'yaml', 'yml']);
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* Whether a code block is a structured-data fence: lang `json`/`yaml`/`yml`
|
|
55
|
+
* with the word `data` in the fence meta (` ```json data `).
|
|
56
|
+
*/
|
|
57
|
+
export function isDataFence(node: MarkdownCodeBlock): boolean {
|
|
58
|
+
if (!node.lang || !DATA_FENCE_LANGS.has(node.lang.toLowerCase())) return false;
|
|
59
|
+
const meta = node.meta ?? '';
|
|
60
|
+
return /\bdata\b/.test(meta);
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
export interface DataFenceParseResult {
|
|
64
|
+
/** Parsed key→value map. Undefined when parsing failed. */
|
|
65
|
+
data?: Record<string, unknown>;
|
|
66
|
+
/** Parse failure description. Undefined when parsing succeeded. */
|
|
67
|
+
error?: string;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* Parse a data fence's content into a key→value map. JSON fences must
|
|
72
|
+
* contain a top-level object (arrays have no key to merge under); YAML
|
|
73
|
+
* fences are parsed with {@link parseYamlSubset}.
|
|
74
|
+
*/
|
|
75
|
+
export function parseDataFence(node: MarkdownCodeBlock): DataFenceParseResult {
|
|
76
|
+
const lang = node.lang?.toLowerCase();
|
|
77
|
+
if (lang === 'json') {
|
|
78
|
+
try {
|
|
79
|
+
const parsed: unknown = JSON.parse(node.value);
|
|
80
|
+
if (parsed === null || typeof parsed !== 'object' || Array.isArray(parsed)) {
|
|
81
|
+
return { error: 'JSON data fence must contain a top-level object ({"key": …})' };
|
|
82
|
+
}
|
|
83
|
+
return { data: parsed as Record<string, unknown> };
|
|
84
|
+
} catch (err: unknown) {
|
|
85
|
+
return { error: `invalid JSON: ${err instanceof Error ? err.message : String(err)}` };
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
try {
|
|
89
|
+
return { data: parseYamlSubset(node.value) };
|
|
90
|
+
} catch (err: unknown) {
|
|
91
|
+
return { error: `invalid YAML: ${err instanceof Error ? err.message : String(err)}` };
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
/**
|
|
96
|
+
* Return a new contents array with the first data fence's code content
|
|
97
|
+
* replaced by `data` (pretty-printed JSON). The fence node keeps its
|
|
98
|
+
* language and `data` marker; only `value` changes. When no data fence
|
|
99
|
+
* exists, a new ` ```json data ` fence is appended instead.
|
|
100
|
+
*
|
|
101
|
+
* Pure: neither `contents` nor its nodes are mutated. This is the write
|
|
102
|
+
* half of the data-fence channel — editors update `block.templateData`
|
|
103
|
+
* and call this to reflect the change back into `block.contents`.
|
|
104
|
+
*/
|
|
105
|
+
export function replaceDataFence(
|
|
106
|
+
contents: MarkdownBlockNode[],
|
|
107
|
+
data: Record<string, unknown>,
|
|
108
|
+
): MarkdownBlockNode[] {
|
|
109
|
+
const value = JSON.stringify(data, null, 2);
|
|
110
|
+
const index = contents.findIndex((node) => node.type === 'code' && isDataFence(node));
|
|
111
|
+
if (index < 0) {
|
|
112
|
+
const fence: MarkdownCodeBlock = { type: 'code', lang: 'json', meta: 'data', value };
|
|
113
|
+
return [...contents, fence];
|
|
114
|
+
}
|
|
115
|
+
const next = [...contents];
|
|
116
|
+
next[index] = { ...(contents[index] as MarkdownCodeBlock), value };
|
|
117
|
+
return next;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
// ============================================
|
|
121
|
+
// YAML subset parser
|
|
122
|
+
// ============================================
|
|
123
|
+
|
|
124
|
+
/** Parse a scalar token: quoted string, boolean, null, number, or string. */
|
|
125
|
+
function parseScalar(raw: string): unknown {
|
|
126
|
+
const trimmed = raw.trim();
|
|
127
|
+
if (trimmed.length >= 2) {
|
|
128
|
+
const q = trimmed[0];
|
|
129
|
+
if ((q === '"' || q === "'") && trimmed.endsWith(q)) {
|
|
130
|
+
return trimmed.slice(1, -1);
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
if (trimmed === 'true') return true;
|
|
134
|
+
if (trimmed === 'false') return false;
|
|
135
|
+
if (trimmed === 'null' || trimmed === '~') return null;
|
|
136
|
+
if (trimmed !== '' && !isNaN(Number(trimmed))) return Number(trimmed);
|
|
137
|
+
return trimmed;
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
/**
|
|
141
|
+
* Split an inline-array interior on top-level commas, respecting quotes.
|
|
142
|
+
*/
|
|
143
|
+
function splitInlineArray(interior: string): string[] {
|
|
144
|
+
const items: string[] = [];
|
|
145
|
+
let current = '';
|
|
146
|
+
let quote: string | null = null;
|
|
147
|
+
for (const ch of interior) {
|
|
148
|
+
if (quote) {
|
|
149
|
+
current += ch;
|
|
150
|
+
if (ch === quote) quote = null;
|
|
151
|
+
} else if (ch === '"' || ch === "'") {
|
|
152
|
+
quote = ch;
|
|
153
|
+
current += ch;
|
|
154
|
+
} else if (ch === ',') {
|
|
155
|
+
items.push(current);
|
|
156
|
+
current = '';
|
|
157
|
+
} else {
|
|
158
|
+
current += ch;
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
items.push(current);
|
|
162
|
+
// A trailing comma (or empty interior) leaves an empty final item — drop it.
|
|
163
|
+
return items.map((s) => s.trim()).filter((s) => s !== '');
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
/** Parse a value that may be an inline array `[a, b]` or a scalar. */
|
|
167
|
+
function parseInlineValue(raw: string): unknown {
|
|
168
|
+
const trimmed = raw.trim();
|
|
169
|
+
if (trimmed.startsWith('[') && trimmed.endsWith(']')) {
|
|
170
|
+
return splitInlineArray(trimmed.slice(1, -1)).map(parseScalar);
|
|
171
|
+
}
|
|
172
|
+
return parseScalar(trimmed);
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
/**
|
|
176
|
+
* Parse the supported YAML subset (see module doc) into a key→value map.
|
|
177
|
+
* Throws an Error with a line-anchored message on anything outside the
|
|
178
|
+
* subset, so callers can surface a precise diagnostic.
|
|
179
|
+
*/
|
|
180
|
+
export function parseYamlSubset(src: string): Record<string, unknown> {
|
|
181
|
+
const result: Record<string, unknown> = {};
|
|
182
|
+
const lines = src.split('\n');
|
|
183
|
+
|
|
184
|
+
// Open block under the most recent `key:` line: whether its children are a
|
|
185
|
+
// block sequence (`- …`) or a nested map (`subkey: …`) is decided by the
|
|
186
|
+
// first indented child; `childIndent` pins the one allowed child depth.
|
|
187
|
+
let pendingKey: string | null = null;
|
|
188
|
+
let pendingKind: 'list' | 'map' | null = null;
|
|
189
|
+
let childIndent = -1;
|
|
190
|
+
|
|
191
|
+
for (let i = 0; i < lines.length; i++) {
|
|
192
|
+
const line = lines[i];
|
|
193
|
+
const trimmed = line.trim();
|
|
194
|
+
if (!trimmed || trimmed.startsWith('#')) continue;
|
|
195
|
+
|
|
196
|
+
const indent = line.length - line.trimStart().length;
|
|
197
|
+
|
|
198
|
+
if (indent > 0) {
|
|
199
|
+
if (!pendingKey) {
|
|
200
|
+
throw new Error(`line ${i + 1}: unexpected indented line without a preceding "key:" line`);
|
|
201
|
+
}
|
|
202
|
+
if (childIndent < 0) childIndent = indent;
|
|
203
|
+
if (indent > childIndent) {
|
|
204
|
+
throw new Error(
|
|
205
|
+
`line ${i + 1}: nesting deeper than one level is not supported — use a \`\`\`json data fence for nested input`,
|
|
206
|
+
);
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
if (trimmed.startsWith('- ')) {
|
|
210
|
+
if (pendingKind === 'map') {
|
|
211
|
+
throw new Error(
|
|
212
|
+
`line ${i + 1}: cannot mix list items and mapping keys under "${pendingKey}"`,
|
|
213
|
+
);
|
|
214
|
+
}
|
|
215
|
+
pendingKind = 'list';
|
|
216
|
+
(result[pendingKey] as unknown[]).push(parseInlineValue(trimmed.slice(2)));
|
|
217
|
+
continue;
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
// Otherwise this is a nested `subkey: value` mapping line.
|
|
221
|
+
if (pendingKind === 'list') {
|
|
222
|
+
throw new Error(
|
|
223
|
+
`line ${i + 1}: cannot mix mapping keys and list items under "${pendingKey}"`,
|
|
224
|
+
);
|
|
225
|
+
}
|
|
226
|
+
const subColon = trimmed.indexOf(':');
|
|
227
|
+
if (subColon < 1) {
|
|
228
|
+
throw new Error(`line ${i + 1}: expected "key: value"`);
|
|
229
|
+
}
|
|
230
|
+
const subValue = trimmed.slice(subColon + 1).trim();
|
|
231
|
+
if (subValue === '') {
|
|
232
|
+
// A nested `subkey:` opening its own block would be a second level.
|
|
233
|
+
throw new Error(
|
|
234
|
+
`line ${i + 1}: nesting deeper than one level is not supported — use a \`\`\`json data fence for nested input`,
|
|
235
|
+
);
|
|
236
|
+
}
|
|
237
|
+
if (pendingKind !== 'map') {
|
|
238
|
+
pendingKind = 'map';
|
|
239
|
+
result[pendingKey] = {};
|
|
240
|
+
}
|
|
241
|
+
(result[pendingKey] as Record<string, unknown>)[trimmed.slice(0, subColon).trim()] =
|
|
242
|
+
parseInlineValue(subValue);
|
|
243
|
+
continue;
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
pendingKey = null;
|
|
247
|
+
pendingKind = null;
|
|
248
|
+
childIndent = -1;
|
|
249
|
+
const colonIdx = trimmed.indexOf(':');
|
|
250
|
+
if (colonIdx < 1) {
|
|
251
|
+
throw new Error(`line ${i + 1}: expected "key: value"`);
|
|
252
|
+
}
|
|
253
|
+
const key = trimmed.slice(0, colonIdx).trim();
|
|
254
|
+
const rawValue = trimmed.slice(colonIdx + 1).trim();
|
|
255
|
+
|
|
256
|
+
if (rawValue === '') {
|
|
257
|
+
// `key:` opens a block: an indented `- …` sequence or a `subkey: …`
|
|
258
|
+
// map. Default to an empty list so a `key:` with no children stays
|
|
259
|
+
// back-compatible (`{ key: [] }`); the map branch replaces it wholesale.
|
|
260
|
+
result[key] = [];
|
|
261
|
+
pendingKey = key;
|
|
262
|
+
} else {
|
|
263
|
+
result[key] = parseInlineValue(rawValue);
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
return result;
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
// ============================================
|
|
271
|
+
// GFM table extraction
|
|
272
|
+
// ============================================
|
|
273
|
+
|
|
274
|
+
export interface ExtractedTableData {
|
|
275
|
+
headers: string[];
|
|
276
|
+
rows: string[][];
|
|
277
|
+
align?: (('left' | 'right' | 'center') | null)[];
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
/** Find the first GFM table among a block's body contents. */
|
|
281
|
+
export function findFirstTable(
|
|
282
|
+
contents: MarkdownBlockNode[] | undefined,
|
|
283
|
+
): MarkdownTable | undefined {
|
|
284
|
+
return contents?.find((n): n is MarkdownTable => n.type === 'table');
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
/**
|
|
288
|
+
* Extract `headers` / `rows` / `align` (the `dataTable` input shape) from a
|
|
289
|
+
* GFM table node. The first row is the header row.
|
|
290
|
+
*/
|
|
291
|
+
export function extractTableData(table: MarkdownTable): ExtractedTableData {
|
|
292
|
+
const toCells = (row: MarkdownTableRow): string[] =>
|
|
293
|
+
row.children.map((cell) => extractPlainText(cell).trim());
|
|
294
|
+
|
|
295
|
+
const [headerRow, ...bodyRows] = table.children;
|
|
296
|
+
return {
|
|
297
|
+
headers: headerRow ? toCells(headerRow) : [],
|
|
298
|
+
rows: bodyRows.map(toCells),
|
|
299
|
+
...(table.align && table.align.some((a) => a != null) ? { align: table.align } : {}),
|
|
300
|
+
};
|
|
301
|
+
}
|
|
@@ -0,0 +1,240 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Template input derivation — build a template's required inputs from a
|
|
3
|
+
* block's heading + markdown body.
|
|
4
|
+
*
|
|
5
|
+
* Used by:
|
|
6
|
+
* - `markdownToDoc`'s content-aware auto template picking, so an
|
|
7
|
+
* auto-picked `quote`/`statHighlight`/`leftFeature` block carries the
|
|
8
|
+
* inputs its template needs through every render path (player, linear
|
|
9
|
+
* view, exports).
|
|
10
|
+
* - `LinearDocView` / editor previews, to render annotated blocks whose
|
|
11
|
+
* authors didn't spell out every template param.
|
|
12
|
+
*
|
|
13
|
+
* Two modes:
|
|
14
|
+
* - strict (default): returns `null` when an essential input can't be
|
|
15
|
+
* derived (no image for a feature block, no table for dataTable…) —
|
|
16
|
+
* auto-picking uses this to fall back to the structural default.
|
|
17
|
+
* - placeholders: returns visible placeholder values instead of failing —
|
|
18
|
+
* preview surfaces use this so a half-authored block still renders.
|
|
19
|
+
*/
|
|
20
|
+
|
|
21
|
+
import type { MarkdownBlockNode, MarkdownList, MarkdownTable } from '../markdown/types.js';
|
|
22
|
+
import { extractPlainText } from '../markdown/utils.js';
|
|
23
|
+
|
|
24
|
+
/** First image discovered in a block's body, with explicit dimensions when present. */
|
|
25
|
+
export interface FirstImage {
|
|
26
|
+
src: string;
|
|
27
|
+
alt: string;
|
|
28
|
+
width?: number;
|
|
29
|
+
height?: number;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/** Plain text of a block's body contents (excluding the heading). */
|
|
33
|
+
export function extractBodyPlainText(contents?: MarkdownBlockNode[]): string {
|
|
34
|
+
if (!contents || contents.length === 0) return '';
|
|
35
|
+
return contents
|
|
36
|
+
.map((n) => extractPlainText(n))
|
|
37
|
+
.join('\n')
|
|
38
|
+
.trim();
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/** Extract list items as plain text. */
|
|
42
|
+
export function extractListItems(contents?: MarkdownBlockNode[]): string[] {
|
|
43
|
+
if (!contents) return [];
|
|
44
|
+
const items: string[] = [];
|
|
45
|
+
for (const node of contents) {
|
|
46
|
+
if (node.type === 'list') {
|
|
47
|
+
for (const item of (node as MarkdownList).children) {
|
|
48
|
+
const text = extractPlainText(item).trim();
|
|
49
|
+
if (text) items.push(text);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
return items;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/** Parse a `width`/`height` HTML attribute to a positive number. */
|
|
57
|
+
function parseDim(raw: string | undefined): number | undefined {
|
|
58
|
+
if (raw === undefined) return undefined;
|
|
59
|
+
const n = parseFloat(raw);
|
|
60
|
+
return Number.isFinite(n) && n > 0 ? n : undefined;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* Find images referenced anywhere in block contents — both markdown
|
|
65
|
+
* shorthand `` (type `image`) and raw HTML `<img>` tags
|
|
66
|
+
* (type `htmlBlock`/`htmlInline`). The WYSIWYG editor emits the HTML form
|
|
67
|
+
* whenever a user resizes an image, so missing that path silently breaks
|
|
68
|
+
* every resized image.
|
|
69
|
+
*
|
|
70
|
+
* @param limit Stop after this many images (default: all).
|
|
71
|
+
*/
|
|
72
|
+
export function extractImages(
|
|
73
|
+
contents: MarkdownBlockNode[] | undefined,
|
|
74
|
+
limit = Infinity,
|
|
75
|
+
): FirstImage[] {
|
|
76
|
+
if (!contents || contents.length === 0) return [];
|
|
77
|
+
const found: FirstImage[] = [];
|
|
78
|
+
|
|
79
|
+
function fromHtml(nodes: unknown[]): void {
|
|
80
|
+
for (const node of nodes) {
|
|
81
|
+
if (found.length >= limit) return;
|
|
82
|
+
if (!node || typeof node !== 'object') continue;
|
|
83
|
+
const n = node as Record<string, unknown>;
|
|
84
|
+
if (n.type === 'htmlElement' && n.tagName === 'img') {
|
|
85
|
+
const attrs = n.attributes as Record<string, string> | undefined;
|
|
86
|
+
if (attrs && typeof attrs.src === 'string' && attrs.src) {
|
|
87
|
+
found.push({
|
|
88
|
+
src: attrs.src,
|
|
89
|
+
alt: typeof attrs.alt === 'string' ? attrs.alt : '',
|
|
90
|
+
width: parseDim(attrs.width),
|
|
91
|
+
height: parseDim(attrs.height),
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
if (Array.isArray(n.children)) fromHtml(n.children);
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
function walk(node: unknown): void {
|
|
100
|
+
if (found.length >= limit) return;
|
|
101
|
+
if (!node || typeof node !== 'object') return;
|
|
102
|
+
const n = node as Record<string, unknown>;
|
|
103
|
+
if (n.type === 'image' && typeof n.url === 'string' && n.url) {
|
|
104
|
+
found.push({ src: n.url, alt: typeof n.alt === 'string' ? n.alt : '' });
|
|
105
|
+
return;
|
|
106
|
+
}
|
|
107
|
+
if ((n.type === 'htmlBlock' || n.type === 'htmlInline') && Array.isArray(n.htmlChildren)) {
|
|
108
|
+
fromHtml(n.htmlChildren);
|
|
109
|
+
}
|
|
110
|
+
if (Array.isArray(n.children)) {
|
|
111
|
+
for (const child of n.children) walk(child);
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
for (const node of contents) {
|
|
116
|
+
if (found.length >= limit) break;
|
|
117
|
+
walk(node);
|
|
118
|
+
}
|
|
119
|
+
return found;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
/** First image in a block's body, or null. */
|
|
123
|
+
export function extractFirstImage(contents: MarkdownBlockNode[] | undefined): FirstImage | null {
|
|
124
|
+
return extractImages(contents, 1)[0] ?? null;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
/** Extract table data (headers, rows, alignment) from block contents. */
|
|
128
|
+
export function extractTableFromContents(contents?: MarkdownBlockNode[]): {
|
|
129
|
+
headers: string[];
|
|
130
|
+
rows: string[][];
|
|
131
|
+
align?: (('left' | 'right' | 'center') | null)[];
|
|
132
|
+
} | null {
|
|
133
|
+
if (!contents) return null;
|
|
134
|
+
for (const node of contents) {
|
|
135
|
+
if (node.type === 'table') {
|
|
136
|
+
const table = node as MarkdownTable;
|
|
137
|
+
const [headerRow, ...bodyRows] = table.children;
|
|
138
|
+
if (!headerRow) return null;
|
|
139
|
+
const headers = headerRow.children.map((cell) => extractPlainText(cell).trim());
|
|
140
|
+
const rows = bodyRows.map((row) => row.children.map((cell) => extractPlainText(cell).trim()));
|
|
141
|
+
return { headers, rows, align: table.align };
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
return null;
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
/** First blockquote's plain text, or ''. */
|
|
148
|
+
export function extractBlockquoteText(contents?: MarkdownBlockNode[]): string {
|
|
149
|
+
if (!contents) return '';
|
|
150
|
+
for (const node of contents) {
|
|
151
|
+
if (node.type === 'blockquote') return extractPlainText(node).trim();
|
|
152
|
+
}
|
|
153
|
+
return '';
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
export interface DeriveTemplateInputsOptions {
|
|
157
|
+
/**
|
|
158
|
+
* Return visible placeholder values instead of `null` when an essential
|
|
159
|
+
* input can't be derived (preview surfaces). Default false (strict).
|
|
160
|
+
*/
|
|
161
|
+
placeholders?: boolean;
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
/**
|
|
165
|
+
* Derive a template's inputs from a block's heading text and body nodes.
|
|
166
|
+
* Returns the input fields to merge onto the block, or `null` in strict
|
|
167
|
+
* mode when an essential input is missing.
|
|
168
|
+
*/
|
|
169
|
+
export function deriveTemplateInputs(
|
|
170
|
+
templateName: string,
|
|
171
|
+
headingText: string,
|
|
172
|
+
contents: MarkdownBlockNode[] | undefined,
|
|
173
|
+
options: DeriveTemplateInputsOptions = {},
|
|
174
|
+
): Record<string, unknown> | null {
|
|
175
|
+
const placeholders = options.placeholders === true;
|
|
176
|
+
const bodyText = extractBodyPlainText(contents);
|
|
177
|
+
|
|
178
|
+
switch (templateName) {
|
|
179
|
+
case 'statHighlight':
|
|
180
|
+
return { stat: headingText, description: bodyText || headingText };
|
|
181
|
+
case 'quote': {
|
|
182
|
+
const quote = extractBlockquoteText(contents) || bodyText || headingText;
|
|
183
|
+
return { quote };
|
|
184
|
+
}
|
|
185
|
+
case 'fullBleedQuote':
|
|
186
|
+
case 'pullQuote': {
|
|
187
|
+
// These templates take `text` (not `quote`).
|
|
188
|
+
const text = extractBlockquoteText(contents) || bodyText || headingText;
|
|
189
|
+
return { text };
|
|
190
|
+
}
|
|
191
|
+
case 'factCard':
|
|
192
|
+
return { fact: headingText, explanation: bodyText || headingText };
|
|
193
|
+
case 'comparisonBar':
|
|
194
|
+
return placeholders
|
|
195
|
+
? { leftLabel: 'A', leftValue: 60, rightLabel: 'B', rightValue: 40 }
|
|
196
|
+
: null;
|
|
197
|
+
case 'list': {
|
|
198
|
+
const items = extractListItems(contents);
|
|
199
|
+
if (items.length > 0) return { items };
|
|
200
|
+
return placeholders ? { items: ['Item 1', 'Item 2', 'Item 3'] } : null;
|
|
201
|
+
}
|
|
202
|
+
case 'definitionCard':
|
|
203
|
+
return { term: headingText, definition: bodyText || headingText };
|
|
204
|
+
case 'dateEvent':
|
|
205
|
+
return { date: headingText, description: bodyText || headingText };
|
|
206
|
+
case 'dataTable': {
|
|
207
|
+
const tableData = extractTableFromContents(contents);
|
|
208
|
+
if (tableData) return tableData;
|
|
209
|
+
return placeholders ? { headers: ['Column'], rows: [['Data']] } : null;
|
|
210
|
+
}
|
|
211
|
+
case 'imageWithCaption': {
|
|
212
|
+
const img = extractFirstImage(contents);
|
|
213
|
+
if (!img) return placeholders ? { caption: headingText } : null;
|
|
214
|
+
return { imageSrc: img.src, imageAlt: img.alt || headingText, caption: headingText };
|
|
215
|
+
}
|
|
216
|
+
case 'photoGrid': {
|
|
217
|
+
const images = extractImages(contents, 4);
|
|
218
|
+
if (images.length < 2) return placeholders ? {} : null;
|
|
219
|
+
return {
|
|
220
|
+
images: images.map((i) => ({ src: i.src, alt: i.alt })),
|
|
221
|
+
caption: headingText,
|
|
222
|
+
};
|
|
223
|
+
}
|
|
224
|
+
case 'leftFeature':
|
|
225
|
+
case 'rightFeature': {
|
|
226
|
+
const img = extractFirstImage(contents);
|
|
227
|
+
if (!img && !placeholders) return null;
|
|
228
|
+
return {
|
|
229
|
+
imageSrc: img?.src ?? '',
|
|
230
|
+
imageAlt: img?.alt || headingText,
|
|
231
|
+
imageWidth: img?.width,
|
|
232
|
+
imageHeight: img?.height,
|
|
233
|
+
title: headingText,
|
|
234
|
+
body: bodyText,
|
|
235
|
+
};
|
|
236
|
+
}
|
|
237
|
+
default:
|
|
238
|
+
return placeholders ? {} : null;
|
|
239
|
+
}
|
|
240
|
+
}
|