@astl/engine 0.6.0 → 0.7.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.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,42 @@
1
1
  # @astl/engine
2
2
 
3
+ ## 0.7.0
4
+
5
+ ### Minor Changes
6
+
7
+ - 8ae6707: Tables in rich text: `table`, `caption`, `thead`, `tbody`, `tr`, `th` (`scope`, `colspan`, `rowspan`) and `td`
8
+ (`colspan`, `rowspan`), a block wherever a figure may be. Cells and the caption hold inline content, inline components
9
+ among it, which keep their ids and slots as anywhere. The source is read as a browser reads it; what stays broken is
10
+ `TABLE_INVALID` (parts out of order or missing, rows that cover different columns, a span past its rows), more than
11
+ 12 columns or 50 rows `TABLE_TOO_LARGE`. The style allow-list adds `border-collapse` and `border-spacing`; tag rules
12
+ and named styles reach every part.
13
+
14
+ The player draws a table as wide as its column, its head tinted and its row headers lighter (lines only in high
15
+ contrast), in a box of its own that scrolls sideways when the table is too wide, never the page: at its content
16
+ width when it cannot fit wrapped tight, with fading edges where there is more to see, the box then a stop of the
17
+ keyboard named by the caption ("Table" otherwise). Fields in cells (a gap, a select, a drop) keep their size and
18
+ their words whole instead of being squeezed: inline components read `--astl-inline-line`, `--astl-inline-wrap`,
19
+ `--astl-inline-hyphens` and `--astl-inline-min`, which a cell sets. The TipTap surface keeps tables, their cells
20
+ written in place, a wide one scrolling in its box; tools to change a table's shape come with the table's editing.
21
+ - 0f89c80: Worked examples: a gap, a long answer or a select with `example` (public) is answered already, so students see what
22
+ to do before they start. A gap and a long answer show its text, a select the option whose id it holds as chosen;
23
+ written in by hand (the new tokens `--astl-font-hand`, a system cursive stack, and `--astl-example-ink`, in every
24
+ theme and built-in look), read-only and never a stop of the keyboard. A gap with boxes shows a letter in each box, a
25
+ long answer its box with its paper. Screen readers read "Example: ..." ("Przykład: ..."); the part is `example`.
26
+
27
+ An example has no slot: it is not graded, adds nothing to the maximum score, is left out of the player's numbers and
28
+ of what counts as unanswered, and needs no answer. A gap's `answer` is no longer required by its manifest: a gap
29
+ without one reports `GAP_ANSWER_MISSING` instead of `ATTRIBUTE_REQUIRED`. New issues: `GAP_EXAMPLE_WITH_ANSWER` and
30
+ `SELECT_EXAMPLE_WITH_CORRECT` (warnings, the example wins), `SELECT_EXAMPLE_UNKNOWN` (an error). The kit offers
31
+ "Example" ("Przykład") for all three, a select's from its own options: an attribute field's `options` without `from`
32
+ lists the element's own children.
33
+
34
+ ### Patch Changes
35
+
36
+ - Updated dependencies [8ae6707]
37
+ - Updated dependencies [0f89c80]
38
+ - @astl/core@0.7.0
39
+
3
40
  ## 0.6.0
4
41
 
5
42
  ### Minor Changes
@@ -1 +1 @@
1
- {"version":3,"file":"analyse.d.ts","sourceRoot":"","sources":["../src/analyse.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,OAAO,EAwBL,KAAK,mBAAmB,EAMxB,KAAK,SAAS,EAId,KAAK,OAAO,EAEZ,KAAK,WAAW,EAOhB,KAAK,eAAe,EAEpB,KAAK,YAAY,EAKjB,KAAK,KAAK,EAeV,KAAK,IAAI,EACT,KAAK,oBAAoB,EAWzB,KAAK,aAAa,EAWlB,KAAK,SAAS,EACf,MAAM,YAAY,CAAC;AAsDpB,MAAM,WAAW,eAAe;IAC9B,QAAQ,CAAC,UAAU,EAAE,mBAAmB,CAAC;IACzC,qDAAqD;IACrD,QAAQ,CAAC,OAAO,EAAE,WAAW,CAAC;IAC9B,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAC1B,kCAAkC;IAClC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,GAAG,EAAE,SAAS,CAAC;IACxB,4EAA4E;IAC5E,QAAQ,CAAC,QAAQ,EAAE,SAAS,MAAM,EAAE,CAAC;IACrC,qHAAqH;IACrH,QAAQ,CAAC,IAAI,EAAE,UAAU,GAAG,IAAI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C7D,6GAA6G;IAC7G,QAAQ,CAAC,YAAY,CAAC,EAAE,YAAY,CAAC;CACtC;AAED,wBAAgB,OAAO,CAAC,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,cAAc,GAAG,QAAQ,CAEzE"}
package/dist/analyse.js CHANGED
@@ -2,20 +2,23 @@
2
2
  * One pass over a source that sanitises it and validates it against the registered manifests. `validate` and
3
3
  * `compile` share it: compile only runs on an error-free analysis and works on the sanitised tree it returns.
4
4
  */
5
- import { allAttributes, BADGE_ATTRIBUTES, BADGE_FILLS, BADGE_SHAPES, BADGE_TAG, BLOCK_TAGS, BOX_ICONS, BOX_LABEL_TAG, BOX_TAG, BOX_TITLE_PLACES, BOX_TITLE_TAG, BOX_VARIANTS, CAPTION_TAG, CHECK_ATTRIBUTES, CHECK_FOR_ATTRIBUTE, CHECK_TAG, CLASS_ATTRIBUTE, COLUMN_TAG, COLUMNS_TAG, CONTENT_ATTRIBUTES, checkFor, checkNodes, checkParts, DEFAULT_DOC_KIND, DOC_ATTRIBUTES, DOC_KINDS, DOC_TAG, directionOf, ENGINE_NAMESPACE, EngineIssue, EXPLANATION_TAG, element, FEEDBACK_TAG, FEEDBACK_VARIANTS, FIGURE_TAG, HELP_TAGS, HINT_TAG, INLINE_TAGS, INSTRUCTION_TAG, isCheckable, isElement, isSourceId, LANGUAGE_TAG_PATTERN, MAX_ATTRIBUTES_PER_ELEMENT, MAX_BADGE_LENGTH, MAX_BADGE_PALETTE, MAX_COLUMNS, MAX_NESTING_DEPTH, MAX_SOURCE_LENGTH, MAX_TASK_LABELS, MAX_TASK_LEVEL, MIN_COLUMNS, PAGE_ATTRIBUTES, PAGE_CHECK_ATTRIBUTE, PAGE_TAG, planChecks, REMOVED_WITH_CONTENT, RULE_TAG, STYLE_TAG, STYLE_TEMPLATE_ATTRIBUTE, SUBTASK_LEVELS, SUBTASK_TAG, SUPPORTED_FORMATS, TAG_ATTRIBUTES, TASK_LABEL_ICONS, TASK_LABEL_TAG, TASK_NUMBERING_ATTRIBUTE, TASK_NUMBERINGS, TASK_TAG, URL_ATTRIBUTES, } from '@astl/core';
5
+ import { allAttributes, BADGE_ATTRIBUTES, BADGE_FILLS, BADGE_SHAPES, BADGE_TAG, BLOCK_TAGS, BOX_ICONS, BOX_LABEL_TAG, BOX_TAG, BOX_TITLE_PLACES, BOX_TITLE_TAG, BOX_VARIANTS, CAPTION_TAG, CHECK_ATTRIBUTES, CHECK_FOR_ATTRIBUTE, CHECK_TAG, CLASS_ATTRIBUTE, COLUMN_TAG, COLUMNS_TAG, CONTENT_ATTRIBUTES, checkFor, checkNodes, checkParts, DEFAULT_DOC_KIND, DOC_ATTRIBUTES, DOC_KINDS, DOC_TAG, directionOf, ENGINE_NAMESPACE, EngineIssue, EXPLANATION_TAG, element, FEEDBACK_TAG, FEEDBACK_VARIANTS, FIGURE_TAG, HELP_TAGS, HINT_TAG, INLINE_TAGS, INSTRUCTION_TAG, isCheckable, isElement, isSourceId, LANGUAGE_TAG_PATTERN, MAX_ATTRIBUTES_PER_ELEMENT, MAX_BADGE_LENGTH, MAX_BADGE_PALETTE, MAX_COLUMNS, MAX_NESTING_DEPTH, MAX_SOURCE_LENGTH, MAX_TABLE_COLUMNS, MAX_TABLE_ROWS, MAX_TASK_LABELS, MAX_TASK_LEVEL, MIN_COLUMNS, PAGE_ATTRIBUTES, PAGE_CHECK_ATTRIBUTE, PAGE_TAG, planChecks, REMOVED_WITH_CONTENT, RULE_TAG, STYLE_TAG, STYLE_TEMPLATE_ATTRIBUTE, SUBTASK_LEVELS, SUBTASK_TAG, SUPPORTED_FORMATS, TABLE_BODY_TAG, TABLE_CAPTION_TAG, TABLE_CELL_TAG, TABLE_HEAD_TAG, TABLE_HEADER_CELL_TAG, TABLE_ROW_TAG, TABLE_SCOPES, TABLE_TAG, TABLE_TAGS, TAG_ATTRIBUTES, TASK_LABEL_ICONS, TASK_LABEL_TAG, TASK_NUMBERING_ATTRIBUTE, TASK_NUMBERINGS, TASK_TAG, URL_ATTRIBUTES, } from '@astl/core';
6
6
  import { cleanStyle, isStyleName, MAX_INLINED_STYLES, MAX_STYLE_LENGTH, MAX_STYLE_RULES, mergeStyles, overStyleColor, parseStyleColor, styleContrast, styleText, } from '@astl/core/declarations';
7
7
  import { appendText, isHtmlWhitespace, parseSource } from './html.js';
8
8
  import { isBooleanValue, parseDecimalValue, parseIntegerValue } from './kit/attributes.js';
9
9
  import { mostAttributes } from './limits.js';
10
10
  import { round6 } from './round.js';
11
11
  /**
12
- * Where inline components may sit: text-holding blocks, captions and inline formatting, never inside a link (and a
13
- * rule, a line break or a picture holds nothing).
12
+ * Where inline components may sit: text-holding blocks, captions, table cells and inline formatting, never inside a
13
+ * link (and a rule, a line break or a picture holds nothing).
14
14
  */
15
15
  const TEXT_PARENTS = new Set([
16
16
  ...[...BLOCK_TAGS].filter((t) => t !== 'ul' && t !== 'ol' && t !== RULE_TAG),
17
17
  ...[...INLINE_TAGS].filter((t) => t !== 'a' && t !== 'br' && t !== 'img'),
18
18
  CAPTION_TAG,
19
+ TABLE_CAPTION_TAG,
20
+ TABLE_HEADER_CELL_TAG,
21
+ TABLE_CELL_TAG,
19
22
  ]);
20
23
  const DIRECTIONS = new Set(['ltr', 'rtl', 'auto']);
21
24
  /** The attributes of `<astl-style>`. */
@@ -36,6 +39,7 @@ const RULE_TARGETS = new Set([
36
39
  INSTRUCTION_TAG,
37
40
  TASK_LABEL_TAG,
38
41
  SUBTASK_TAG,
42
+ ...TABLE_TAGS,
39
43
  ]);
40
44
  /** The contrast WCAG asks of normal text (AA); large text may have less, and then the warning is only stricter. */
41
45
  const MIN_CONTRAST = 4.5;
@@ -46,6 +50,61 @@ const noHelp = () => ({ hints: [], explanation: null, feedback: {}, where: [] })
46
50
  const helpRecord = (parts) => parts.where.length === 0
47
51
  ? null
48
52
  : { hints: parts.hints, explanation: parts.explanation, feedback: parts.feedback };
53
+ /** A cell's `colspan` or `rowspan`: 1 when absent, 0 when it is no whole number from 1 to `max`. */
54
+ function tableSpan(value, max) {
55
+ if (value === undefined)
56
+ return 1;
57
+ const n = parseIntegerValue(value);
58
+ return n !== null && n >= 1 && n <= max ? n : 0;
59
+ }
60
+ /**
61
+ * The columns a table's rows cover, row by row as HTML lays them out: a cell takes the first column no span from a row
62
+ * above holds, and as many as its `colspan`; its `rowspan` holds them in the rows below, within its part (a head, a
63
+ * body, the rows standing directly in the table).
64
+ */
65
+ class TableGrid {
66
+ rows = 0;
67
+ /** The table's columns: the most any row covers. */
68
+ columns = 0;
69
+ /** What the first row covered: every other row must cover as much. */
70
+ #width = null;
71
+ /** Per column, how many more rows a span from above holds it. */
72
+ #held = [];
73
+ /** A new part: spans never cross into it. */
74
+ start() {
75
+ this.#held = [];
76
+ }
77
+ /** The end of a part: whether a span reached past its last row. */
78
+ end() {
79
+ const past = this.#held.some((n) => n > 0);
80
+ this.#held = [];
81
+ return past;
82
+ }
83
+ /** One row of cells (`[colspan, rowspan]`, 0 for an invalid span, counted as 1): whether it fits the table. */
84
+ row(cells) {
85
+ this.rows++;
86
+ const above = this.#held.map((n) => n > 0);
87
+ const held = this.#held.map((n) => Math.max(0, n - 1));
88
+ let fits = true;
89
+ let at = 0;
90
+ for (const [colspan, rowspan] of cells) {
91
+ while (above[at])
92
+ at++;
93
+ for (let column = at; column < at + Math.max(1, colspan); column++) {
94
+ // A cell running into a column a span from above holds.
95
+ if (above[column])
96
+ fits = false;
97
+ held[column] = Math.max(held[column] ?? 0, Math.max(1, rowspan) - 1);
98
+ }
99
+ at += Math.max(1, colspan);
100
+ }
101
+ this.#held = Array.from({ length: Math.max(held.length, at) }, (_, i) => held[i] ?? 0);
102
+ const width = Math.max(at, above.lastIndexOf(true) + 1);
103
+ this.columns = Math.max(this.columns, width);
104
+ this.#width ??= width;
105
+ return fits && width === this.#width;
106
+ }
107
+ }
49
108
  function own(attrs, name) {
50
109
  return Object.hasOwn(attrs, name) ? attrs[name] : undefined;
51
110
  }
@@ -386,7 +445,8 @@ class Analyser {
386
445
  const record = this.components.get(node);
387
446
  return {
388
447
  id: record?.sourceId ?? null,
389
- graded: isCheckable(definition.manifest),
448
+ // An example is answered already: nothing for a Check.
449
+ graded: isCheckable(definition.manifest) && definition.example?.(node) !== true,
390
450
  block: definition.manifest.display === 'block',
391
451
  };
392
452
  },
@@ -664,6 +724,16 @@ class Analyser {
664
724
  // A figure is a block: in a prompt or an option it is unwrapped like the other blocks, below.
665
725
  if (tag === FIGURE_TAG && scope.mode === 'flow')
666
726
  return [this.visitFigure(el, scope, place, where)];
727
+ if (tag === TABLE_TAG) {
728
+ return scope.mode === 'flow'
729
+ ? [this.visitTable(el, scope, place, where)]
730
+ : this.unwrapTable(el, scope, place, where);
731
+ }
732
+ // A part of a table out of its table (a cell outside a row): its content stays, to be validated.
733
+ if (TABLE_TAGS.has(tag)) {
734
+ this.add(EngineIssue.TABLE_INVALID, {}, where);
735
+ return this.visitNodes(el, scope, place.path);
736
+ }
667
737
  if (tag.includes('-')) {
668
738
  const host = scope.host;
669
739
  const spec = host?.manifest.children.find((c) => c.tag === tag);
@@ -1059,6 +1129,13 @@ class Analyser {
1059
1129
  else if ((name === 'width' || name === 'height') && !((parseIntegerValue(value) ?? 0) > 0)) {
1060
1130
  this.invalid(el.tag, name, value, 'integer', [], where);
1061
1131
  }
1132
+ else if ((name === 'colspan' || name === 'rowspan') &&
1133
+ tableSpan(value, name === 'colspan' ? MAX_TABLE_COLUMNS : MAX_TABLE_ROWS) === 0) {
1134
+ this.invalid(el.tag, name, value, 'integer', [], where);
1135
+ }
1136
+ else if (name === 'scope' && !TABLE_SCOPES.includes(value)) {
1137
+ this.invalid(el.tag, name, value, 'enum', TABLE_SCOPES, where);
1138
+ }
1062
1139
  else {
1063
1140
  attrs[name] = value;
1064
1141
  }
@@ -1078,16 +1155,8 @@ class Analyser {
1078
1155
  * and at most one caption. A caption holds rich inline text, which may hold inline components like any text.
1079
1156
  */
1080
1157
  visitFigure(el, scope, place, where) {
1081
- if (scope.parent !== PAGE_TAG &&
1082
- scope.parent !== DOC_TAG &&
1083
- scope.parent !== COLUMN_TAG &&
1084
- scope.parent !== BOX_TAG &&
1085
- scope.parent !== TASK_TAG &&
1086
- scope.parent !== SUBTASK_TAG &&
1087
- scope.parent !== scope.host?.manifest.tag &&
1088
- !HELP_TAGS.has(scope.parent)) {
1158
+ if (!this.blockPlace(scope))
1089
1159
  this.add(EngineIssue.PLACEMENT_INVALID, { tag: el.tag }, where);
1090
- }
1091
1160
  const attrs = this.richAttributes(el, where, scope);
1092
1161
  const inner = { ...scope, ...this.below(attrs, scope), parent: FIGURE_TAG };
1093
1162
  let pictures = 0;
@@ -1112,6 +1181,135 @@ class Analyser {
1112
1181
  this.add(EngineIssue.FIGURE_INVALID, {}, where);
1113
1182
  return element(FIGURE_TAG, attrs, children);
1114
1183
  }
1184
+ /** Where a figure or a table may stand: directly in a page, the document, a column, a frame, a task, a rich block or help. */
1185
+ blockPlace(scope) {
1186
+ return (scope.parent === PAGE_TAG ||
1187
+ scope.parent === DOC_TAG ||
1188
+ scope.parent === COLUMN_TAG ||
1189
+ scope.parent === BOX_TAG ||
1190
+ scope.parent === TASK_TAG ||
1191
+ scope.parent === SUBTASK_TAG ||
1192
+ scope.parent === scope.host?.manifest.tag ||
1193
+ HELP_TAGS.has(scope.parent));
1194
+ }
1195
+ /**
1196
+ * A table, where a figure may stand. Its caption (first, once) holds rich inline text; then a head (once, before the
1197
+ * bodies) and bodies of rows, or rows directly in it (one body until the next part); a row holds header and data
1198
+ * cells, whose content is rich inline text with inline components in it. A part out of its place, text between
1199
+ * rows or cells, rows that cover different columns, a span past the rows of its part or no rows at all are
1200
+ * TABLE_INVALID, reported at the part; more than MAX_TABLE_COLUMNS columns or MAX_TABLE_ROWS rows TABLE_TOO_LARGE.
1201
+ */
1202
+ visitTable(el, scope, place, where) {
1203
+ if (!this.blockPlace(scope))
1204
+ this.add(EngineIssue.PLACEMENT_INVALID, { tag: el.tag }, where);
1205
+ const attrs = this.richAttributes(el, where, scope);
1206
+ const inner = { ...scope, ...this.below(attrs, scope), parent: TABLE_TAG };
1207
+ const grid = new TableGrid();
1208
+ // What came last: the order is caption, head, bodies (and rows of their own).
1209
+ const seen = { last: 'start' };
1210
+ const children = this.visitNodes(el, inner, place.path, (child, childPlace) => {
1211
+ const at = this.where(inner, childPlace, child.tag);
1212
+ if (child.tag === TABLE_CAPTION_TAG && seen.last === 'start') {
1213
+ seen.last = 'caption';
1214
+ const caption = this.richAttributes(child, at, inner);
1215
+ const text = {
1216
+ ...inner,
1217
+ ...this.below(caption, inner),
1218
+ parent: TABLE_CAPTION_TAG,
1219
+ mode: 'inline',
1220
+ };
1221
+ return [element(TABLE_CAPTION_TAG, caption, this.visitNodes(child, text, childPlace.path))];
1222
+ }
1223
+ if (child.tag === TABLE_HEAD_TAG && (seen.last === 'start' || seen.last === 'caption')) {
1224
+ seen.last = 'head';
1225
+ return [this.visitTableSection(child, inner, childPlace, at, grid)];
1226
+ }
1227
+ if (child.tag === TABLE_BODY_TAG) {
1228
+ if (seen.last === 'rows')
1229
+ this.endTableSection(grid, where);
1230
+ seen.last = 'body';
1231
+ return [this.visitTableSection(child, inner, childPlace, at, grid)];
1232
+ }
1233
+ if (child.tag === TABLE_ROW_TAG) {
1234
+ if (seen.last !== 'rows')
1235
+ grid.start();
1236
+ seen.last = 'rows';
1237
+ return [this.visitTableRow(child, inner, childPlace, at, grid)];
1238
+ }
1239
+ this.add(EngineIssue.TABLE_INVALID, {}, at);
1240
+ return [];
1241
+ });
1242
+ if (seen.last === 'rows')
1243
+ this.endTableSection(grid, where);
1244
+ if (children.some((n) => n.type === 'text' && !isHtmlWhitespace(n.value)) || grid.rows === 0) {
1245
+ this.add(EngineIssue.TABLE_INVALID, {}, where);
1246
+ }
1247
+ if (grid.columns > MAX_TABLE_COLUMNS || grid.rows > MAX_TABLE_ROWS) {
1248
+ const params = {
1249
+ columns: grid.columns,
1250
+ rows: grid.rows,
1251
+ maxColumns: MAX_TABLE_COLUMNS,
1252
+ maxRows: MAX_TABLE_ROWS,
1253
+ };
1254
+ this.add(EngineIssue.TABLE_TOO_LARGE, params, where);
1255
+ }
1256
+ return element(TABLE_TAG, attrs, children);
1257
+ }
1258
+ /** A head or a body: rows only, its spans ending with it. */
1259
+ visitTableSection(el, scope, place, where, grid) {
1260
+ const attrs = this.richAttributes(el, where, scope);
1261
+ const inner = { ...scope, ...this.below(attrs, scope), parent: el.tag };
1262
+ grid.start();
1263
+ const children = this.visitNodes(el, inner, place.path, (child, childPlace) => {
1264
+ const at = this.where(inner, childPlace, child.tag);
1265
+ if (child.tag === TABLE_ROW_TAG)
1266
+ return [this.visitTableRow(child, inner, childPlace, at, grid)];
1267
+ this.add(EngineIssue.TABLE_INVALID, {}, at);
1268
+ return [];
1269
+ });
1270
+ if (children.some((n) => n.type === 'text' && !isHtmlWhitespace(n.value))) {
1271
+ this.add(EngineIssue.TABLE_INVALID, {}, where);
1272
+ }
1273
+ this.endTableSection(grid, where);
1274
+ return element(el.tag, attrs, children);
1275
+ }
1276
+ /** A span that reaches past the last row of its part. */
1277
+ endTableSection(grid, where) {
1278
+ if (grid.end())
1279
+ this.add(EngineIssue.TABLE_INVALID, {}, where);
1280
+ }
1281
+ /** A row: cells only, covering the columns of the rows before it. */
1282
+ visitTableRow(el, scope, place, where, grid) {
1283
+ const attrs = this.richAttributes(el, where, scope);
1284
+ const inner = { ...scope, ...this.below(attrs, scope), parent: TABLE_ROW_TAG };
1285
+ const spans = [];
1286
+ const children = this.visitNodes(el, inner, place.path, (child, childPlace) => {
1287
+ const at = this.where(inner, childPlace, child.tag);
1288
+ if (child.tag !== TABLE_HEADER_CELL_TAG && child.tag !== TABLE_CELL_TAG) {
1289
+ this.add(EngineIssue.TABLE_INVALID, {}, at);
1290
+ return [];
1291
+ }
1292
+ const cell = this.richAttributes(child, at, inner);
1293
+ spans.push([tableSpan(cell.colspan, MAX_TABLE_COLUMNS), tableSpan(cell.rowspan, MAX_TABLE_ROWS)]);
1294
+ const text = { ...inner, ...this.below(cell, inner), parent: child.tag, mode: 'inline' };
1295
+ return [element(child.tag, cell, this.visitNodes(child, text, childPlace.path))];
1296
+ });
1297
+ if (children.some((n) => n.type === 'text' && !isHtmlWhitespace(n.value)) || !grid.row(spans)) {
1298
+ this.add(EngineIssue.TABLE_INVALID, {}, where);
1299
+ }
1300
+ return element(TABLE_ROW_TAG, attrs, children);
1301
+ }
1302
+ /**
1303
+ * A table in a prompt, an option or a card, where blocks are unwrapped: its parts go, the text of its caption and
1304
+ * cells stays, a space between them.
1305
+ */
1306
+ unwrapTable(el, scope, place, where) {
1307
+ this.add(EngineIssue.ELEMENT_REMOVED, { tag: el.tag }, where, 'warning');
1308
+ const unwrap = (child, childPlace) => TABLE_TAGS.has(child.tag)
1309
+ ? [{ type: 'text', value: ' ' }, ...this.visitNodes(child, scope, childPlace.path, unwrap)]
1310
+ : null;
1311
+ return this.visitNodes(el, scope, place.path, unwrap);
1312
+ }
1115
1313
  visitPage(el, index, place, base) {
1116
1314
  const id = own(el.attrs, 'id');
1117
1315
  const where = {
@@ -1164,7 +1362,7 @@ class Analyser {
1164
1362
  const id = own(raw.attrs, 'id');
1165
1363
  const where = { order: place.order, page: scope.page, element: id ?? null, tag, path: place.path };
1166
1364
  this.componentCount++;
1167
- if (manifest.graded)
1365
+ if (manifest.graded && definition.example?.(raw) !== true)
1168
1366
  this.gradedPages.add(scope.pageIndex);
1169
1367
  if (!placementAllowed(manifest.display, scope))
1170
1368
  this.add(EngineIssue.PLACEMENT_INVALID, { tag }, where);