@podlite/schema 0.0.38 → 0.0.40

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.podlite CHANGED
@@ -2,6 +2,20 @@
2
2
 
3
3
  =head1 Upcoming
4
4
 
5
+ =head1 0.0.40
6
+
7
+ =item recognise the C<header> MIME parameter (RFC 4180 §3) on C<:mime-type> for CSV/TSV C<=data> blocks. When the C<=data> block declares C<:mime-type<'text/csv; header=present'>> (or the same with C<text/tab-separated-values>), C<=table data:X> marks the first row as C<:header>, which renders as C<<th>>/C<<thead>> in HTML and JSX. Default C<absent> preserves the previous behaviour. The MIME-type parser also accepts other parameters (e.g. C<charset>) without disturbing type matching. Spec: podlite-specs#25
8
+
9
+ =head1 0.0.39
10
+
11
+ =item resolve C<=table data:<key>> as CSV from a C<=data :mime-type<text/csv>> block (spec §1672) — table content is replaced with C<=row>/C<=cell> structure parsed per RFC 4180 (comma delimiter, C<"..."> quoted fields with C<""> escape). Spec §1672 does not define how to mark a header in CSV-sourced tables; authors who need a header row should use a structured table with C<=begin row :header> or a Markdown GFM table. C<file:<path>> scheme is left unresolved for host-driven readers
12
+ =item resolve C<=table data:<key>> as TSV when the C<=data> block carries C<:mime-type<text/tab-separated-values>> — split on tabs only, no quoting (C<"> is a literal character, unlike CSV)
13
+ =item add table error recovery — pad short rows with empty cells, truncate over-long rows; expected cell count is taken from a C<:header> row when present, otherwise from the row with the maximum cell count. Warn on each adjustment. Tables containing C<:colspan>/C<:rowspan> cells are skipped (naive count would mis-handle spanning)
14
+ =item warn on mixed column separator types within a single text-mode C<=table> (e.g. C<|> in one row, whitespace in another) — does not block parsing
15
+ =item improve CSV/TSV error recovery — missing C<=data> block leaves the table empty; a non-tabular mime-type is rendered as a C<=code> block so the underlying content remains visible
16
+ =item add per-line separator detection for text-mode C<=table> when lines disagree about separator type. A common pattern — header with C<|> for visual emphasis and data rows aligned by whitespace alone — used to collapse columns under the unified positional mask; each line is now parsed on its own and produces the expected cells. Tables with a single separator type, or with both visible kinds (C<|>+C<+>) handled by the shared mask, still go through the legacy positional path so continuation lines in multi-line rows keep their column alignment
17
+ =item move C<parseSelector> and C<runSelector> here from C<@podlite/publisher>. These are pure AST queries (no I/O, no filesystem) and belong in C<@podlite/schema>. C<runSelector> is now generic over a C<SelectorDoc> shape (C<{ file, node }>), so consumers without the publisher's richer C<publishRecord> type can use it directly. The publisher re-exports from C<@podlite/schema> for backward compatibility
18
+
5
19
  =head1 0.0.38
6
20
 
7
21
  =item added C<type: "map"> on config items parsed from C<:attr{k=>v, ...}> key-value syntax — previously the hash form returned the map value without a type annotation, making it indistinguishable from other value kinds
package/esm/index.d.ts CHANGED
@@ -78,5 +78,7 @@ export { parse as parse };
78
78
  export { default as toHtml } from './exportHtml';
79
79
  export { default as toMarkdown } from './exportMarkdown';
80
80
  export { default as Writer } from './writer';
81
+ export { parseSelector, runSelector } from './selectors';
82
+ export type { SelectorDoc, ParsedSelector } from './selectors';
81
83
  declare const VERSION: any;
82
84
  export { VERSION as version };
package/esm/index.js CHANGED
@@ -140,6 +140,7 @@ export { parse as parse };
140
140
  export { default as toHtml } from './exportHtml';
141
141
  export { default as toMarkdown } from './exportMarkdown';
142
142
  export { default as Writer } from './writer';
143
+ export { parseSelector, runSelector } from './selectors';
143
144
  // Cannot be `import` as it's not under TS root dir
144
145
  // https://stackoverflow.com/questions/51070138/how-to-import-package-json-into-typescript-file-without-including-it-in-the-comp
145
146
  const { version: VERSION } = require('../package.json');
package/esm/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,GAAoC,MAAM,KAAK,CAAA;AACtD,OAAO,KAAK,OAAO,MAAM,cAAc,CAAA;AAGvC,OAAO,KAAK,UAAU,MAAM,WAAW,CAAA;AACvC,OAAO,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAA;AAE9C,cAAc,SAAS,CAAA;A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AAK,EAAE,CAAA;AACzB,OAAO,EAAE,OAAO,IAAI,MAAM,EAAE,MAAM,cAAc,CAAA;AAChD,OAAO,EAAE,OAAO,IAAI,UAAU,EAAE,MAAM,kBAAkB,CAAA;AACxD,OAAO,EAAE,OAAO,IAAI,MAAM,EAAE,MAAM,UAAU,CAAA;AAC5C,OAAO,EAAE,aAAa,EAAE,WAAW,EAAE,MAAM,aAAa,CAAA;AAExD,mDAAmD;AACnD,gIAAgI;AAEhI,MAAM,EAAE,OAAO,EAAE,OAAO,EAAE,GAAG,OAAO,CAAC,iBAAiB,CAAC,CAAA;AACvD,gDAAgD;AAChD,OAAO,EAAE,OAAO,IAAI,OAAO,EAAE,CAAA"}
@@ -4,13 +4,302 @@
4
4
  * and the remaining content is treated as the definition for the term.
5
5
  */
6
6
  import makeTransformer from './helpers/makeTransformer';
7
+ import makeAttrs from './helpers/config';
7
8
  function flattenDeep(arr) {
8
9
  return arr.reduce((acc, val) => (Array.isArray(val) ? acc.concat(flattenDeep(val)) : acc.concat(val)), []);
9
10
  }
11
+ // ─── CSV source for =table (spec §1672) ────────────────────────────────────
12
+ // Parse CSV content per RFC 4180: comma delimiter, `"`-quoted fields with
13
+ // `""` as embedded-quote escape. Supports LF or CRLF line endings. Leading
14
+ // indentation typical of =data block bodies is stripped from each line.
15
+ function parseCsv(text) {
16
+ const rows = [];
17
+ let field = '';
18
+ let row = [];
19
+ let inQuote = false;
20
+ let i = 0;
21
+ while (i < text.length) {
22
+ const c = text[i];
23
+ if (inQuote) {
24
+ if (c === '"' && text[i + 1] === '"') {
25
+ field += '"';
26
+ i += 2;
27
+ continue;
28
+ }
29
+ if (c === '"') {
30
+ inQuote = false;
31
+ i++;
32
+ continue;
33
+ }
34
+ field += c;
35
+ i++;
36
+ continue;
37
+ }
38
+ if (c === '"' && field === '') {
39
+ inQuote = true;
40
+ i++;
41
+ continue;
42
+ }
43
+ if (c === ',') {
44
+ row.push(field);
45
+ field = '';
46
+ i++;
47
+ continue;
48
+ }
49
+ if (c === '\r') {
50
+ i++;
51
+ continue;
52
+ }
53
+ if (c === '\n') {
54
+ row.push(field);
55
+ rows.push(row);
56
+ row = [];
57
+ field = '';
58
+ i++;
59
+ continue;
60
+ }
61
+ field += c;
62
+ i++;
63
+ }
64
+ if (field !== '' || row.length > 0) {
65
+ row.push(field);
66
+ rows.push(row);
67
+ }
68
+ // Drop rows that are entirely blank (empty content after trim).
69
+ return rows.filter(r => !(r.length === 1 && r[0].trim() === ''));
70
+ }
71
+ // Parse a TSV (tab-separated values) blob. Unlike CSV, TSV has no quoting
72
+ // mechanism — fields are split strictly on tabs and `"` is a literal
73
+ // character. Tabs and newlines inside fields are not representable in TSV.
74
+ function parseTsv(text) {
75
+ const lines = text.split(/\r?\n/);
76
+ const rows = lines.map(line => line.split('\t'));
77
+ return rows.filter(r => !(r.length === 1 && r[0].trim() === ''));
78
+ }
79
+ // Parse a MIME type value into the bare type and a map of parameters
80
+ // (RFC 6838 / RFC 7231 §3.1.1.1). Used to recognise the `header` parameter
81
+ // (RFC 4180 §3) on `:mime-type` of CSV/TSV =data blocks.
82
+ //
83
+ // Examples:
84
+ // "text/csv" → { type: 'text/csv', params: {} }
85
+ // "text/csv; header=present" → { type: 'text/csv', params: { header: 'present' } }
86
+ // "text/csv;charset=utf-8;header=absent" → { ..., params: { charset: 'utf-8', header: 'absent' } }
87
+ function parseMimeType(raw) {
88
+ if (!raw || typeof raw !== 'string')
89
+ return { type: '', params: {} };
90
+ const parts = raw.split(';').map(s => s.trim());
91
+ const type = (parts.shift() || '').toLowerCase();
92
+ const params = {};
93
+ for (const p of parts) {
94
+ if (!p)
95
+ continue;
96
+ const eq = p.indexOf('=');
97
+ if (eq < 0)
98
+ continue;
99
+ const key = p.slice(0, eq).trim().toLowerCase();
100
+ let value = p.slice(eq + 1).trim();
101
+ if ((value.startsWith('"') && value.endsWith('"')) || (value.startsWith("'") && value.endsWith("'"))) {
102
+ value = value.slice(1, -1);
103
+ }
104
+ if (key)
105
+ params[key] = value;
106
+ }
107
+ return { type, params };
108
+ }
109
+ // Locate the first `=data` block with a matching `:key` attribute anywhere
110
+ // in the document tree.
111
+ function findDataBlockByKey(tree, key) {
112
+ let found = null;
113
+ const walk = node => {
114
+ if (found)
115
+ return;
116
+ if (Array.isArray(node)) {
117
+ node.forEach(walk);
118
+ return;
119
+ }
120
+ if (!node || typeof node !== 'object')
121
+ return;
122
+ if (node.type === 'block' && node.name === 'data') {
123
+ const attrs = makeAttrs(node, {});
124
+ if (attrs.getFirstValue('key') === key) {
125
+ found = node;
126
+ return;
127
+ }
128
+ }
129
+ if (Array.isArray(node.content))
130
+ node.content.forEach(walk);
131
+ };
132
+ walk(tree);
133
+ return found;
134
+ }
135
+ function extractDataText(dataNode) {
136
+ if (!dataNode || !Array.isArray(dataNode.content))
137
+ return '';
138
+ const verbatim = dataNode.content.find(c => c && c.type === 'verbatim');
139
+ return verbatim && typeof verbatim.value === 'string' ? verbatim.value : '';
140
+ }
141
+ // Detect whether the =table body is a single-line source reference like
142
+ // `data:key` or `file:path` (spec §1672). Returns the parsed reference or
143
+ // null if the body is ordinary table content.
144
+ function detectSourceReference(tableNode) {
145
+ const texts = [];
146
+ const walker = makeTransformer({
147
+ 'row:text': r => {
148
+ texts.push(r.value);
149
+ return r;
150
+ },
151
+ 'head:text': h => {
152
+ texts.push(h.value);
153
+ return h;
154
+ },
155
+ });
156
+ walker(tableNode, {});
157
+ const joined = texts.join('\n').trim();
158
+ const lines = joined
159
+ .split(/\r?\n/)
160
+ .map(l => l.trim())
161
+ .filter(l => l.length > 0);
162
+ if (lines.length !== 1)
163
+ return null;
164
+ const m = lines[0].match(/^(data|file):(\S+)$/);
165
+ if (!m)
166
+ return null;
167
+ return { scheme: m[1], target: m[2] };
168
+ }
169
+ function buildCellBlock(text) {
170
+ return {
171
+ name: 'cell',
172
+ type: 'block',
173
+ margin: '',
174
+ content: [{ type: 'text', value: text }],
175
+ };
176
+ }
177
+ function buildRowBlock(cells, isHeader) {
178
+ const block = {
179
+ name: 'row',
180
+ type: 'block',
181
+ margin: '',
182
+ content: cells,
183
+ };
184
+ if (isHeader) {
185
+ block.config = [{ name: 'header', value: true, type: 'boolean' }];
186
+ }
187
+ return block;
188
+ }
189
+ // Convert parsed CSV/TSV rows to plain `=row`/`=cell` blocks. When
190
+ // `hasHeader` is true (signalled by the `header=present` MIME parameter on
191
+ // the source `=data` block, per RFC 4180 §3), the first row is marked with
192
+ // `:header`. Default behaviour leaves all rows unmarked, matching authors
193
+ // who use a structured table with explicit `=begin row :header` or a
194
+ // Markdown GFM table.
195
+ function csvToTableContent(csvRows, hasHeader = false) {
196
+ return csvRows.map((row, i) => {
197
+ const cells = row.map(v => buildCellBlock(v.trim()));
198
+ return buildRowBlock(cells, hasHeader && i === 0);
199
+ });
200
+ }
201
+ // ─── Error recovery (design notes Rules 2-4) ───────────────────────────────
202
+ // Rule 2 — table-level cell count validation. Pad short rows with empty
203
+ // cells; truncate long rows. Emit a warning whenever a row is changed.
204
+ // Expected count is taken from the `:header` row if present, otherwise from
205
+ // the row with the maximum cell count.
206
+ //
207
+ // Skipped when any cell uses `:colspan` or `:rowspan`: a spanning cell
208
+ // occupies multiple columns, so naive cell counting would misreport row
209
+ // width and drop legitimate spanned cells.
210
+ function normalizeCellCounts(tableNode, source = 'table') {
211
+ if (!tableNode || !Array.isArray(tableNode.content))
212
+ return tableNode;
213
+ const rows = tableNode.content.filter(c => c && c.type === 'block' && c.name === 'row');
214
+ if (rows.length === 0)
215
+ return tableNode;
216
+ const cellsOf = row => (Array.isArray(row.content) ? row.content.filter(c => c && c.name === 'cell') : []);
217
+ const isHeaderRow = row => Array.isArray(row.config) && row.config.some(a => a.name === 'header' && a.value === true);
218
+ const cellHasSpan = cell => Array.isArray(cell.config) && cell.config.some(a => a.name === 'colspan' || a.name === 'rowspan');
219
+ const rowHasSpan = row => cellsOf(row).some(cellHasSpan);
220
+ if (rows.some(rowHasSpan))
221
+ return tableNode;
222
+ const headerRow = rows.find(isHeaderRow);
223
+ const expected = headerRow ? cellsOf(headerRow).length : Math.max(...rows.map(r => cellsOf(r).length));
224
+ if (expected === 0)
225
+ return tableNode;
226
+ let mutated = false;
227
+ const newContent = tableNode.content.map(child => {
228
+ if (!child || child.type !== 'block' || child.name !== 'row')
229
+ return child;
230
+ const cells = cellsOf(child);
231
+ if (cells.length === expected)
232
+ return child;
233
+ if (cells.length < expected) {
234
+ const padding = [];
235
+ for (let i = cells.length; i < expected; i++)
236
+ padding.push(buildCellBlock(''));
237
+ console.warn(`[${source}] row has ${cells.length} cells, expected ${expected} — padded with ${padding.length} empty`);
238
+ mutated = true;
239
+ return { ...child, content: [...child.content, ...padding] };
240
+ }
241
+ // cells.length > expected → truncate
242
+ const dropped = cells.length - expected;
243
+ console.warn(`[${source}] row has ${cells.length} cells, expected ${expected} — truncated ${dropped}`);
244
+ mutated = true;
245
+ // Keep non-cell entries (e.g. blanklines) and the first `expected` cells
246
+ let keepCells = expected;
247
+ const trimmed = [];
248
+ for (const c of child.content || []) {
249
+ if (c && c.type === 'block' && c.name === 'cell') {
250
+ if (keepCells > 0) {
251
+ trimmed.push(c);
252
+ keepCells--;
253
+ }
254
+ }
255
+ else {
256
+ trimmed.push(c);
257
+ }
258
+ }
259
+ return { ...child, content: trimmed };
260
+ });
261
+ return mutated ? { ...tableNode, content: newContent } : tableNode;
262
+ }
263
+ // Rule 3 — mixed separator detection (text-mode only). Inspects each line
264
+ // for visible separators (`|` / `+`) surrounded by whitespace; lines without
265
+ // any visible separator fall back to whitespace separation. Warns when more
266
+ // than one separator type is observed within a single table.
267
+ function detectMixedSeparators(lines) {
268
+ const seen = new Set();
269
+ for (const line of lines) {
270
+ if (!line || typeof line !== 'string')
271
+ continue;
272
+ if (/\s\|\s/.test(line))
273
+ seen.add('pipe');
274
+ else if (/\s\+\s/.test(line))
275
+ seen.add('plus');
276
+ else if (line.trim().length > 0)
277
+ seen.add('whitespace');
278
+ if (seen.size > 1)
279
+ break;
280
+ }
281
+ if (seen.size > 1) {
282
+ console.warn(`[table] mixed separator types detected: ${Array.from(seen).join(', ')} — recommend a single style`);
283
+ }
284
+ }
285
+ // Rule 4 — replace =table with =code block. Used when a referenced =data
286
+ // source has a non-CSV mime type: the spec mandates the source be rendered
287
+ // as a code block so the user can still see the underlying content.
288
+ function buildCodeFromDataBlock(tableNode, dataBlock) {
289
+ return {
290
+ type: 'block',
291
+ name: 'code',
292
+ margin: tableNode.margin || '',
293
+ content: Array.isArray(dataBlock.content) ? dataBlock.content : [],
294
+ config: Array.isArray(tableNode.config) ? tableNode.config : [],
295
+ };
296
+ }
10
297
  /**
11
298
  * Helpers section
12
299
  */
13
- // run cb in symbols pair
300
+ // Bit-mask helper used by the positional column extractor for multi-line
301
+ // rows. Compares two same-length digit strings character by character via
302
+ // `cb`, returning the joined result.
14
303
  const strbin = (str1, str2, cb) => {
15
304
  let res = [];
16
305
  for (let i = 0; str1.length > i; i++) {
@@ -18,62 +307,109 @@ const strbin = (str1, str2, cb) => {
18
307
  }
19
308
  return res.join('');
20
309
  };
21
- // Create mask for extract columns
310
+ // Build a unified column-position mask across a set of lines. Used as a
311
+ // fallback when a row spans multiple lines (continuation lines that align
312
+ // content by character position rather than by separator). Returns a binary
313
+ // string where `0` runs mark column ranges and `1` runs mark gaps.
22
314
  const makeMask = (lines, separators) => {
23
- // calculate template length
24
315
  const tmplLength = Math.max(...[...lines, ...separators].map(s => s.length));
25
- // make bin mask for each string
26
316
  const masks = lines.map(str => {
27
- /** make mask for each line
28
- ' The Shoveller | Eddie Stevens | King Arthur\'s singing shovel',
29
- '0000000011111111111110001111111111111000001111111111111111111111111111' ]
30
- then not(mask) ... then & masks
31
- */
32
- // enlarge string to tmplLength
33
- let tstr = str + ' '.repeat(tmplLength - str.length);
34
- let mask = [];
317
+ const tstr = str + ' '.repeat(tmplLength - str.length);
318
+ const mask = [];
35
319
  const re = /\s+[+|\s]\s/g;
36
320
  let match;
37
321
  while ((match = re.exec(tstr)) != null) {
38
322
  const tmpMask = '1'.repeat(match.index) + '0'.repeat(match[0].length);
39
323
  mask.push(tmpMask + '1'.repeat(tmplLength - tmpMask.length));
40
324
  }
41
- return mask.reduce((a, b) => {
42
- return strbin(a, b, (i1, i2) => i1 & i2);
43
- }, '1'.repeat(tmplLength));
325
+ return mask.reduce((a, b) => strbin(a, b, (i1, i2) => i1 & i2), '1'.repeat(tmplLength));
44
326
  });
45
- // make result mask
46
327
  const inverted = masks.map(m => strbin(m, '', i1 => (i1 == 0 ? 1 : 0)));
47
- const columnTemplate = inverted.reduce((a, b) => {
48
- return strbin(a, b, (i1, i2) => i1 & i2);
49
- }, '1'.repeat(tmplLength));
50
- return columnTemplate;
328
+ return inverted.reduce((a, b) => strbin(a, b, (i1, i2) => i1 & i2), '1'.repeat(tmplLength));
51
329
  };
330
+ // Apply a column-position template to a multi-line text block, extracting
331
+ // per-column substrings and aggregating across lines (continuation lines
332
+ // append to the cell at the same column position).
52
333
  const extractColumnsByTemplate = (text, template) => {
53
- const lines = flattenDeep(text
54
- .split(/\n/) // split each row by eol
55
- .filter(str => str.length > 0));
334
+ const lines = flattenDeep(text.split(/\n/).filter(s => s.length > 0));
56
335
  const cols = lines.map(line => {
57
336
  const re = /((1+|0+))/g;
58
- let columns = [];
337
+ const columns = [];
59
338
  let match;
60
339
  while ((match = re.exec(template)) != null) {
61
- if (match[0][0] == 1)
340
+ if (match[0][0] == '1')
62
341
  continue;
63
- const s = line.substring(match.index, match.index + match[0].length);
64
- columns.push(s);
342
+ columns.push(line.substring(match.index, match.index + match[0].length));
65
343
  }
66
344
  return columns;
67
345
  });
68
- let result = [];
69
- result = cols.reduce((a, b) => {
346
+ const result = [];
347
+ cols.reduce((a, b) => {
70
348
  for (let i = 0; i < b.length; i++) {
71
349
  a[i] = (a[i] === undefined ? '' : a[i]) + ' ' + b[i];
72
350
  }
73
351
  return a;
74
- }, []);
352
+ }, result);
75
353
  return result;
76
354
  };
355
+ const detectLineSeparator = (line) => {
356
+ if (/(?:^|\s)\|(?:\s|$)/.test(line))
357
+ return 'pipe';
358
+ if (/(?:^|\s)\+(?:\s|$)/.test(line))
359
+ return 'plus';
360
+ return 'whitespace';
361
+ };
362
+ const trimEdgeEmpty = (cells) => {
363
+ // A leading `|` produces an empty cell at index 0; a trailing `|` does the
364
+ // same at the end. Drop those edge artifacts. Empty cells in the middle of
365
+ // the row are preserved.
366
+ let start = 0;
367
+ let end = cells.length;
368
+ if (cells[start] === '')
369
+ start++;
370
+ if (end > start && cells[end - 1] === '')
371
+ end--;
372
+ return cells.slice(start, end);
373
+ };
374
+ const splitLineByPipe = (line) => trimEdgeEmpty(line.split(/\s*\|\s*/).map(c => c.trim()));
375
+ const splitLineByPlus = (line) => trimEdgeEmpty(line.split(/\s*\+\s*/).map(c => c.trim()));
376
+ const splitLineByWhitespace = (line) => line
377
+ .trim()
378
+ .split(/\s{2,}/)
379
+ .filter(c => c !== '');
380
+ const splitLineCells = (line) => {
381
+ const trimmed = line.trim();
382
+ if (trimmed === '')
383
+ return [];
384
+ const kind = detectLineSeparator(line);
385
+ if (kind === 'pipe')
386
+ return splitLineByPipe(line);
387
+ if (kind === 'plus')
388
+ return splitLineByPlus(line);
389
+ return splitLineByWhitespace(line);
390
+ };
391
+ // Convert a row's raw text (which may span multiple lines) to cell values.
392
+ // Multi-line rows: take the separator kind from the first non-blank line and
393
+ // apply it to every line of the row, then aggregate column-wise so that a
394
+ // continuation line (e.g. wrapped cell content) appends to the cell from the
395
+ // previous line in the same column.
396
+ const rowToCells = (rowValue) => {
397
+ const lines = rowValue.split(/\r?\n/).filter(l => l.trim() !== '');
398
+ if (lines.length === 0)
399
+ return [];
400
+ if (lines.length === 1)
401
+ return splitLineCells(lines[0]);
402
+ const kind = detectLineSeparator(lines[0]);
403
+ const splitFn = kind === 'pipe' ? splitLineByPipe : kind === 'plus' ? splitLineByPlus : splitLineByWhitespace;
404
+ const lineCells = lines.map(splitFn);
405
+ const maxCols = Math.max(...lineCells.map(c => c.length));
406
+ const merged = [];
407
+ for (let i = 0; i < maxCols; i++) {
408
+ const parts = lineCells.map(line => line[i] ?? '').filter(p => p !== '');
409
+ merged.push(parts.join(' '));
410
+ }
411
+ return merged;
412
+ };
77
413
  /**
78
414
  * Main transforms
79
415
  */
@@ -97,14 +433,45 @@ const isStructured = tableNode => Array.isArray(tableNode.content) &&
97
433
  export default () => tree => {
98
434
  const transformer = makeTransformer({
99
435
  table: node => {
100
- // structured mode: transform row children (wrap implicit cells)
436
+ // CSV/data source reference (spec §1672):
437
+ // =table data:<key> → resolve =data block with :key<key>
438
+ // =table file:<path> → defer to host reader (not implemented here)
439
+ const ref = detectSourceReference(node);
440
+ if (ref && ref.scheme === 'data') {
441
+ const dataBlock = findDataBlockByKey(tree, ref.target);
442
+ if (!dataBlock) {
443
+ // Rule 4: source not found → empty table (still a =table block)
444
+ console.warn(`[table] no =data block found for data:${ref.target} — rendered as empty`);
445
+ return { ...node, content: [] };
446
+ }
447
+ const rawMime = makeAttrs(dataBlock, {}).getFirstValue('mime-type');
448
+ const { type: mimeType, params: mimeParams } = parseMimeType(rawMime);
449
+ const isCsv = mimeType === 'text/csv';
450
+ const isTsv = mimeType === 'text/tab-separated-values';
451
+ if (isCsv || isTsv) {
452
+ const text = extractDataText(dataBlock);
453
+ const rows = isCsv ? parseCsv(text) : parseTsv(text);
454
+ if (rows.length === 0) {
455
+ console.warn(`[table] ${isCsv ? 'CSV' : 'TSV'} parse produced no rows for data:${ref.target} — rendered as empty`);
456
+ return { ...node, content: [] };
457
+ }
458
+ const hasHeader = mimeParams.header === 'present';
459
+ const filledNode = { ...node, content: csvToTableContent(rows, hasHeader) };
460
+ return normalizeCellCounts(filledNode, `table data:${ref.target}`);
461
+ }
462
+ // Rule 4: source not tabular → render as code block so content remains visible
463
+ console.warn(`[table] =data :key<${ref.target}> has non-tabular mime-type ${rawMime || '(none)'} — rendered as =code`);
464
+ return buildCodeFromDataBlock(node, dataBlock);
465
+ }
466
+ // structured mode: transform row children (wrap implicit cells), then
467
+ // apply Rule 2 cell count normalization.
101
468
  if (isStructured(node)) {
102
469
  const transformedContent = (node.content || []).map(c => {
103
470
  if (c && c.name === 'row')
104
471
  return wrapImplicitCells(c);
105
472
  return c;
106
473
  });
107
- return { ...node, content: transformedContent };
474
+ return normalizeCellCounts({ ...node, content: transformedContent }, 'table');
108
475
  }
109
476
  let rows = [];
110
477
  const collectValues = row => {
@@ -129,6 +496,8 @@ export default () => tree => {
129
496
  // split each row into lines
130
497
  const lines = flattenDeep(rows.map(splitToLines));
131
498
  const separators = flattenDeep(seps.map(splitToLines));
499
+ // Rule 3: warn on mixed separator types within a single table
500
+ detectMixedSeparators(lines);
132
501
  // collect text rows
133
502
  let textRows = [];
134
503
  makeTransformer({
@@ -136,33 +505,48 @@ export default () => tree => {
136
505
  textRows.push(row.value);
137
506
  },
138
507
  })(node);
139
- const columnTemplate = makeMask(lines, separators);
140
508
  const makeBlock = (name, content, extra = {}) => {
141
509
  return { ...extra, name, type: 'block', content: Array.isArray(content) ? content : [content] };
142
510
  };
143
511
  const makeRow = cells => makeBlock('row', cells);
144
512
  const makeHeaderRow = cells => makeBlock('row', cells, { config: [{ name: 'header', value: true, type: 'boolean' }] });
145
513
  const makeCell = text => makeBlock('cell', { type: 'text', value: text });
146
- // make columns
514
+ // Routing: per-line separator detection (Rule 1) is used only when a
515
+ // line with a visible separator (`|` or `+`) coexists with one that
516
+ // has only whitespace separation — the Scenario 2 case where the
517
+ // legacy positional mask collapses columns. Tables with a uniform
518
+ // separator, or with both visible kinds (pipe + plus) handled by the
519
+ // shared mask, fall back to the legacy positional template, which
520
+ // preserves continuation-line alignment in multi-line rows and keeps
521
+ // byte-for-byte AST/HTML output stable.
522
+ const columnTemplate = makeMask(lines, separators);
523
+ const seenSeparatorKinds = new Set(lines.map(detectLineSeparator));
524
+ const hasVisible = seenSeparatorKinds.has('pipe') || seenSeparatorKinds.has('plus');
525
+ const hasWhitespace = seenSeparatorKinds.has('whitespace');
526
+ const useMixedSplitting = hasVisible && hasWhitespace;
527
+ const splitToCells = (rowValue) => {
528
+ if (useMixedSplitting) {
529
+ const rowLines = rowValue.split(/\r?\n/).filter(l => l.trim() !== '');
530
+ if (rowLines.length <= 1)
531
+ return rowToCells(rowValue);
532
+ }
533
+ return extractColumnsByTemplate(rowValue, columnTemplate);
534
+ };
147
535
  const res = makeTransformer({
148
536
  'row:text': row => {
149
537
  if (textRows.length == 1) {
150
- // split each text row into lines
538
+ // No separator blocks: each line of the only text row becomes its own row
151
539
  const textRowsLines = flattenDeep([row.value].map(splitToLines));
152
- return textRowsLines.map(rowValue => {
153
- const cols = extractColumnsByTemplate(rowValue, columnTemplate);
154
- return makeRow(cols.map(makeCell));
155
- });
540
+ if (useMixedSplitting) {
541
+ return textRowsLines.map(line => makeRow(splitLineCells(line).map(makeCell)));
542
+ }
543
+ return textRowsLines.map(line => makeRow(extractColumnsByTemplate(line, columnTemplate).map(makeCell)));
156
544
  }
157
- const cols = extractColumnsByTemplate(row.value, columnTemplate);
158
- return makeRow(cols.map(makeCell));
159
- },
160
- 'head:text': head => {
161
- const cols = extractColumnsByTemplate(head.value, columnTemplate);
162
- return makeHeaderRow(cols.map(makeCell));
545
+ return makeRow(splitToCells(row.value).map(makeCell));
163
546
  },
547
+ 'head:text': head => makeHeaderRow(splitToCells(head.value).map(makeCell)),
164
548
  })(node);
165
- return res;
549
+ return normalizeCellCounts(res, 'table');
166
550
  },
167
551
  });
168
552
  return transformer(tree, {});