@podlite/schema 0.0.82 → 0.0.84

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.
Files changed (43) hide show
  1. package/CHANGELOG.podlite +24 -0
  2. package/esm/ast-inerator.js +1 -3
  3. package/esm/ast-inerator.js.map +1 -1
  4. package/esm/grammar.js +531 -416
  5. package/esm/grammar.js.map +1 -1
  6. package/esm/helpers/flatten-deep.d.ts +2 -0
  7. package/esm/helpers/flatten-deep.js +32 -0
  8. package/esm/helpers/flatten-deep.js.map +1 -0
  9. package/esm/helpers/makeInterator.js +3 -6
  10. package/esm/helpers/makeInterator.js.map +1 -1
  11. package/esm/helpers/makeTransformer.js +1 -3
  12. package/esm/helpers/makeTransformer.js.map +1 -1
  13. package/esm/index.d.ts +1 -0
  14. package/esm/index.js +1 -0
  15. package/esm/index.js.map +1 -1
  16. package/esm/pluggableParser.js +9 -4
  17. package/esm/pluggableParser.js.map +1 -1
  18. package/esm/plugin-group-items.d.ts +4 -1
  19. package/esm/plugin-group-items.js +41 -7
  20. package/esm/plugin-group-items.js.map +1 -1
  21. package/esm/plugin-tables.js +62 -17
  22. package/esm/plugin-tables.js.map +1 -1
  23. package/esm/types.d.ts +1 -1
  24. package/esm/version.d.ts +1 -1
  25. package/esm/version.js +1 -1
  26. package/lib/ast-inerator.js +2 -4
  27. package/lib/grammar.js +531 -416
  28. package/lib/helpers/flatten-deep.d.ts +2 -0
  29. package/lib/helpers/flatten-deep.js +35 -0
  30. package/lib/helpers/makeInterator.js +3 -6
  31. package/lib/helpers/makeTransformer.js +2 -4
  32. package/lib/index.d.ts +1 -0
  33. package/lib/index.js +4 -2
  34. package/lib/pluggableParser.js +9 -4
  35. package/lib/plugin-group-items.d.ts +4 -1
  36. package/lib/plugin-group-items.js +42 -7
  37. package/lib/plugin-tables.js +66 -21
  38. package/lib/types.d.ts +1 -1
  39. package/lib/version.d.ts +1 -1
  40. package/lib/version.js +1 -1
  41. package/package.json +3 -3
  42. package/schema/AstTree.json +1 -0
  43. package/schema/PodliteDocument.json +1 -0
@@ -0,0 +1,2 @@
1
+ export type Nested<T> = T | ReadonlyArray<Nested<T>>;
2
+ export declare function flattenDeep<T>(items: ReadonlyArray<Nested<T>>): T[];
@@ -0,0 +1,35 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.flattenDeep = flattenDeep;
4
+ const isList = (item) => Array.isArray(item);
5
+ /*
6
+ =begin pod :kind<export>
7
+
8
+ =head2 flattenDeep
9
+
10
+ Puts the items of nested lists into one list, in order, in time that grows with
11
+ the number of items. Holes of a list are skipped. A value that is not a list is
12
+ taken the way C<concat> takes it: an object marked with
13
+ C<Symbol.isConcatSpreadable> gives its items one level deep, holes kept.
14
+
15
+ =end pod
16
+ */
17
+ function flattenDeep(items) {
18
+ const out = [];
19
+ const walk = (list) => list.forEach(item => {
20
+ if (isList(item))
21
+ return walk(item);
22
+ // concat on an empty list spreads what concat spreads, and copies nothing
23
+ const empty = [];
24
+ const parts = empty.concat(item);
25
+ for (let i = 0; i < parts.length; i++) {
26
+ if (Object.prototype.hasOwnProperty.call(parts, i))
27
+ out.push(parts[i]);
28
+ else
29
+ out.length++;
30
+ }
31
+ });
32
+ walk(items);
33
+ return out;
34
+ }
35
+ //# sourceMappingURL=flatten-deep.js.map
@@ -1,11 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- function flattenDeep(arr) {
4
- if (!Array.isArray(arr)) {
5
- return arr;
6
- }
7
- return arr.reduce((acc, val) => (Array.isArray(val) ? acc.concat(flattenDeep(val)) : acc.concat(val)), []);
8
- }
3
+ const flatten_deep_1 = require("./flatten-deep");
4
+ // a value that is not a list is passed on as it is
5
+ const flattenDeep = arr => (Array.isArray(arr) ? (0, flatten_deep_1.flattenDeep)(arr) : arr);
9
6
  function thisFunc(rules) {
10
7
  function interator(node, context) {
11
8
  if (node == null) {
@@ -4,6 +4,7 @@ exports.makeTransformer = void 0;
4
4
  exports.isNamedBlock = isNamedBlock;
5
5
  exports.isSemanticBlock = isSemanticBlock;
6
6
  const makeQuery_1 = require("./makeQuery");
7
+ const flatten_deep_1 = require("./flatten-deep");
7
8
  // the following names: MyBlock, myBlock are use for extending pod6
8
9
  function isNamedBlock(name) {
9
10
  return name && name !== name.toLowerCase() && name !== name.toUpperCase();
@@ -14,9 +15,6 @@ function isSemanticBlock(node) {
14
15
  const isTypeBlock = (node.type || '') === 'block';
15
16
  return isTypeBlock && name === name.toUpperCase();
16
17
  }
17
- function flattenDeep(arr) {
18
- return arr.reduce((acc, val) => (Array.isArray(val) ? acc.concat(flattenDeep(val)) : acc.concat(val)), []);
19
- }
20
18
  const makeTransformer = rule => {
21
19
  let rules = [];
22
20
  function use(key, fn) {
@@ -38,7 +36,7 @@ const makeTransformer = rule => {
38
36
  return node;
39
37
  }
40
38
  if (node instanceof Array) {
41
- return flattenDeep(node.map(item => visiter(item, context)));
39
+ return (0, flatten_deep_1.flattenDeep)(node.map(item => visiter(item, context)));
42
40
  }
43
41
  if ('string' === typeof node) {
44
42
  // convert string to lex node with type
package/lib/index.d.ts CHANGED
@@ -25,6 +25,7 @@ export type { LinkConfig } from './helpers/link-config';
25
25
  export { pluginCleanLocation } from './plugin-clean-location';
26
26
  export { toAnyRules } from './helpers/plugins';
27
27
  export { podlitePluggable, Podlite, PodliteExport, cleanIds, frozenIds, headingId } from './pluggableParser';
28
+ export { MAX_LIST_LEVEL } from './plugin-group-items';
28
29
  import { ConfigScope } from './helpers/configPropagation';
29
30
  export { mergeConfigSettings, propagateConfigDefaults, walkConfigScopes } from './helpers/configPropagation';
30
31
  export { blockNameOf, holderInside, isDirectiveNode, isWrapper } from './helpers/blockName';
package/lib/index.js CHANGED
@@ -39,8 +39,8 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
39
39
  return (mod && mod.__esModule) ? mod : { "default": mod };
40
40
  };
41
41
  Object.defineProperty(exports, "__esModule", { value: true });
42
- exports.guardedTextLeaves = exports.isCovered = exports.markGuarded = exports.isSetTarget = exports.isSetTransparent = exports.mergeSet = exports.applySetToFirst = exports.SelectorError = exports.getDocIDs = exports.filePathMatches = exports.outermost = exports.runSelector = exports.readSelector = exports.parseSelector = exports.Writer = exports.toMarkdown = exports.toHtml = exports.parseFormattingCodes = exports.parse = exports.isWrapper = exports.isDirectiveNode = exports.holderInside = exports.blockNameOf = exports.walkConfigScopes = exports.propagateConfigDefaults = exports.mergeConfigSettings = exports.headingId = exports.frozenIds = exports.cleanIds = exports.podlitePluggable = exports.toAnyRules = exports.pluginCleanLocation = exports.quoteAttribute = exports.fingerprint = exports.assignHeadingKeys = exports.readLinkConfig = exports.parseAttributes = exports.codeConfigWithDefaults = exports.makeAttrs = exports.toAny = exports.isSemanticBlock = exports.isNamedBlock = exports.makeTransformer = exports.makeInterator = exports.MARKUP_CODE_DEPTH_LIMIT = exports.ALIAS_EXPANSION_BUDGET = exports.ALIAS_EXPANSION_DEPTH = exports.expandAlias = exports.isTitleBlock = exports.titleParts = void 0;
43
- exports.version = exports.applyImageBase = exports.tocTitleText = exports.mayHoldTests = exports.canOwnTest = exports.testFoldedByAuthor = exports.testCaption = exports.applyFoldedSections = exports.renderCodeText = exports.getMaskedTextContent = void 0;
42
+ exports.isCovered = exports.markGuarded = exports.isSetTarget = exports.isSetTransparent = exports.mergeSet = exports.applySetToFirst = exports.SelectorError = exports.getDocIDs = exports.filePathMatches = exports.outermost = exports.runSelector = exports.readSelector = exports.parseSelector = exports.Writer = exports.toMarkdown = exports.toHtml = exports.parseFormattingCodes = exports.parse = exports.isWrapper = exports.isDirectiveNode = exports.holderInside = exports.blockNameOf = exports.walkConfigScopes = exports.propagateConfigDefaults = exports.mergeConfigSettings = exports.MAX_LIST_LEVEL = exports.headingId = exports.frozenIds = exports.cleanIds = exports.podlitePluggable = exports.toAnyRules = exports.pluginCleanLocation = exports.quoteAttribute = exports.fingerprint = exports.assignHeadingKeys = exports.readLinkConfig = exports.parseAttributes = exports.codeConfigWithDefaults = exports.makeAttrs = exports.toAny = exports.isSemanticBlock = exports.isNamedBlock = exports.makeTransformer = exports.makeInterator = exports.MARKUP_CODE_DEPTH_LIMIT = exports.ALIAS_EXPANSION_BUDGET = exports.ALIAS_EXPANSION_DEPTH = exports.expandAlias = exports.isTitleBlock = exports.titleParts = void 0;
43
+ exports.version = exports.applyImageBase = exports.tocTitleText = exports.mayHoldTests = exports.canOwnTest = exports.testFoldedByAuthor = exports.testCaption = exports.applyFoldedSections = exports.renderCodeText = exports.getMaskedTextContent = exports.guardedTextLeaves = void 0;
44
44
  exports.toAst = toAst;
45
45
  exports.getTextContentFromNode = getTextContentFromNode;
46
46
  exports.getPodContentFromNode = getPodContentFromNode;
@@ -108,6 +108,8 @@ const plugin_items_1 = __importDefault(require("./plugin-items"));
108
108
  const plugin_heading_1 = __importDefault(require("./plugin-heading"));
109
109
  const plugin_group_defn_1 = __importDefault(require("./plugin-group-defn"));
110
110
  const plugin_group_items_1 = __importDefault(require("./plugin-group-items"));
111
+ var plugin_group_items_2 = require("./plugin-group-items");
112
+ Object.defineProperty(exports, "MAX_LIST_LEVEL", { enumerable: true, get: function () { return plugin_group_items_2.MAX_LIST_LEVEL; } });
111
113
  const plugin_defn_fill_term_1 = __importDefault(require("./plugin-defn-fill-term"));
112
114
  const plugin_set_1 = __importDefault(require("./plugin-set"));
113
115
  const configPropagation_1 = require("./helpers/configPropagation");
@@ -19,6 +19,8 @@ var ids_2 = require("./helpers/ids");
19
19
  Object.defineProperty(exports, "cleanIds", { enumerable: true, get: function () { return ids_2.cleanIds; } });
20
20
  Object.defineProperty(exports, "frozenIds", { enumerable: true, get: function () { return ids_2.frozenIds; } });
21
21
  Object.defineProperty(exports, "headingId", { enumerable: true, get: function () { return ids_2.headingId; } });
22
+ // what the parser did to a table; a report that something written is missing is not one of them
23
+ const TABLE_REPAIRS = ['table-row-cells', 'table-mixed-separators', 'table-cell-outside-row'];
22
24
  const podlitePluggable = ({ plugins = {} } = {}) => {
23
25
  let instance = function () { };
24
26
  let _plugins = [];
@@ -61,11 +63,14 @@ const podlitePluggable = ({ plugins = {} } = {}) => {
61
63
  // one mistake inside a value reports twice: for the value and for the whole
62
64
  // attribute around it. The narrower report names the place to fix. Two reports of
63
65
  // one place keep the first; a warning about a markup code is about the code, not
64
- // a value, and stays
65
- const isCodeWarning = (d) => d.code.startsWith('markup-code-');
66
- const innermost = diagnostics.filter((d, k) => isCodeWarning(d) ||
66
+ // a value, and stays, as do warnings about a row of a table, its source and a list too deep
67
+ const stays = (d) => d.code.startsWith('markup-code-') ||
68
+ d.code.startsWith('table-source-') ||
69
+ d.code === 'list-too-deep' ||
70
+ TABLE_REPAIRS.includes(d.code);
71
+ const innermost = diagnostics.filter((d, k) => stays(d) ||
67
72
  !diagnostics.some((other, j) => other !== d &&
68
- !isCodeWarning(other) &&
73
+ !stays(other) &&
69
74
  other.location.start.offset >= d.location.start.offset &&
70
75
  other.location.end.offset <= d.location.end.offset &&
71
76
  (other.location.start.offset !== d.location.start.offset ||
@@ -1,2 +1,5 @@
1
- declare const _default: () => (tree: any) => any;
1
+ export declare const MAX_LIST_LEVEL = 50;
2
+ declare const _default: (opt?: {
3
+ diagnostics?: unknown[];
4
+ }) => (tree: any) => any;
2
5
  export default _default;
@@ -3,8 +3,11 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.MAX_LIST_LEVEL = void 0;
6
7
  const config_1 = __importDefault(require("./helpers/config"));
7
- exports.default = () => tree => {
8
+ // lists nest no deeper than this: deeper trees overflow the stack of the renderers
9
+ exports.MAX_LIST_LEVEL = 50;
10
+ exports.default = (opt = {}) => tree => {
8
11
  const isNodesEqual = (n1, n2) =>
9
12
  // if nodes items
10
13
  (n1.name === 'item' || n1.name === 'defn') &&
@@ -14,7 +17,37 @@ exports.default = () => tree => {
14
17
  isChecked(n1) === isChecked(n2);
15
18
  const isNumbered = node => Boolean((0, config_1.default)(node, {}).exists('numbered'));
16
19
  const isChecked = node => node.checked !== undefined;
17
- const group = (a, level = 1) => {
20
+ // the level a list is built at; the level the author wrote stays on the item
21
+ const nestAt = item => Math.min(Number(item.level), exports.MAX_LIST_LEVEL);
22
+ const tooDeep = item => item.name === 'item' && item.type === 'block' && Number(item.level) > exports.MAX_LIST_LEVEL;
23
+ const report = item => {
24
+ if (!Array.isArray(opt.diagnostics))
25
+ return;
26
+ opt.diagnostics.push({
27
+ severity: 'warning',
28
+ code: 'list-too-deep',
29
+ message: `list item at level ${Number(item.level)} is deeper than ${exports.MAX_LIST_LEVEL} levels; it is shown at level ${exports.MAX_LIST_LEVEL}`,
30
+ location: item.location,
31
+ });
32
+ };
33
+ // a list is the items of one content with nothing but blank lines between them
34
+ const reportDeepLists = content => {
35
+ let told = false;
36
+ content.forEach(node => {
37
+ if (node.type === 'blankline')
38
+ return;
39
+ if (node.name !== 'item' || node.type !== 'block')
40
+ told = false;
41
+ else if (!told && tooDeep(node)) {
42
+ report(node);
43
+ told = true;
44
+ }
45
+ });
46
+ };
47
+ // the content of a list is grouped again for its next level and is not told twice
48
+ const group = (a, level = 1, ofList = false) => {
49
+ if (!ofList)
50
+ reportDeepLists(a);
18
51
  const isInListMode = a => {
19
52
  return a.length > 0 && a[a.length - 1].type === 'list';
20
53
  };
@@ -26,21 +59,23 @@ exports.default = () => tree => {
26
59
  let lastItem = {};
27
60
  let result = a.reduce((a, i) => {
28
61
  // skip items out of level
29
- if (i.name === 'item' && i.type === 'block' && i.level < level) {
30
- return [...a, i];
62
+ if (i.name === 'item' && i.type === 'block' && nestAt(i) < level) {
63
+ a.push(i);
64
+ return a;
31
65
  }
32
66
  if (i.name === 'item' &&
33
67
  i.type === 'block' &&
34
68
  (!isInListMode(a) ||
35
69
  // different type of list and item
36
70
  // at the same level
37
- (Number(i.level) === level &&
71
+ // and an item past the limit in a list that already stands at the limit
72
+ ((nestAt(i) === level || (tooDeep(i) && Number(getList(a).level) === exports.MAX_LIST_LEVEL)) &&
38
73
  getList(a).list !== (isNumbered(i) ? 'ordered' : isChecked(i) ? 'task' : 'itemized')))) {
39
74
  // create empty list
40
75
  // list = ['ordered', 'variable', 'itemized']
41
76
  a.push({
42
77
  type: 'list',
43
- level: i.level,
78
+ level: tooDeep(i) ? exports.MAX_LIST_LEVEL : i.level,
44
79
  content: [],
45
80
  list: isNumbered(i) ? 'ordered' : isChecked(i) ? 'task' : 'itemized',
46
81
  });
@@ -65,7 +100,7 @@ exports.default = () => tree => {
65
100
  return result.map(item => {
66
101
  // process any item with content ( except formatting codes)
67
102
  if (item.content && item.type !== 'fcode') {
68
- item.content = group(item.content, Number(item.level || 0) + 1);
103
+ item.content = group(item.content, Number(item.level || 0) + 1, item.type === 'list');
69
104
  }
70
105
  return item;
71
106
  });
@@ -21,9 +21,7 @@ const config_1 = __importDefault(require("./helpers/config"));
21
21
  const scan_1 = require("./codes/scan");
22
22
  const configPropagation_1 = require("./helpers/configPropagation");
23
23
  const code_config_1 = require("./helpers/code-config");
24
- function flattenDeep(arr) {
25
- return arr.reduce((acc, val) => (Array.isArray(val) ? acc.concat(flattenDeep(val)) : acc.concat(val)), []);
26
- }
24
+ const flatten_deep_1 = require("./helpers/flatten-deep");
27
25
  // ─── CSV source for =table (spec §1672) ────────────────────────────────────
28
26
  // Parse CSV content per RFC 4180: comma delimiter, `"`-quoted fields with
29
27
  // `""` as embedded-quote escape. Supports LF or CRLF line endings. Leading
@@ -257,9 +255,12 @@ function normalizeCellCounts(tableNode, source = 'table', report = noReport) {
257
255
  if (expected === 0)
258
256
  return tableNode;
259
257
  let mutated = false;
258
+ // a report names its row by its place among the rows, the header and even rows counted
259
+ let rowNumber = 0;
260
260
  const newContent = tableNode.content.map(child => {
261
261
  if (!child || child.type !== 'block' || child.name !== 'row')
262
262
  return child;
263
+ rowNumber++;
263
264
  const cells = cellsOf(child);
264
265
  if (cells.length === expected)
265
266
  return child;
@@ -267,13 +268,13 @@ function normalizeCellCounts(tableNode, source = 'table', report = noReport) {
267
268
  const padding = [];
268
269
  for (let i = cells.length; i < expected; i++)
269
270
  padding.push(buildCellBlock(''));
270
- report('table-row-cells', `${source} row has ${cells.length} of ${expected} cells, padded with ${padding.length} empty. A row continued on the next line needs a blank line before the next row`, tableNode);
271
+ report('table-row-cells', `${source} row ${rowNumber} has ${cells.length} of ${expected} cells, padded with ${padding.length} empty. A row continued on the next line needs a blank line before the next row`, tableNode);
271
272
  mutated = true;
272
273
  return { ...child, content: [...child.content, ...padding] };
273
274
  }
274
275
  // cells.length > expected → truncate
275
276
  const dropped = cells.length - expected;
276
- report('table-row-cells', `${source} row has ${cells.length} of ${expected} cells, dropped ${dropped}`, tableNode);
277
+ report('table-row-cells', `${source} row ${rowNumber} has ${cells.length} of ${expected} cells, dropped ${dropped}`, tableNode);
277
278
  mutated = true;
278
279
  // Keep non-cell entries (e.g. blanklines) and the first `expected` cells
279
280
  let keepCells = expected;
@@ -392,10 +393,30 @@ const strbin = (str1, str2, cb) => {
392
393
  }
393
394
  return res.join('');
394
395
  };
395
- // Build a unified column-position mask across a set of lines. Used as a
396
- // fallback when a row spans multiple lines (continuation lines that align
397
- // content by character position rather than by separator). Returns a binary
398
- // string where `0` runs mark column ranges and `1` runs mark gaps.
396
+ // the norm puts a separator between every row on several lines, so the lines after the last one are a row too
397
+ const groupRows = (content) => {
398
+ const isTextRow = (c) => Boolean(c) && c.name === 'row' && c.type === 'text';
399
+ const groups = [[]];
400
+ content.forEach((c, i) => {
401
+ if (isTextRow(c))
402
+ groups[groups.length - 1].push(i);
403
+ else if (c && c.type === 'separator' && groups[groups.length - 1].length)
404
+ groups.push([]);
405
+ });
406
+ const filled = groups.filter(g => g.length);
407
+ if (filled.length < 2)
408
+ return content;
409
+ const firstOf = new Map(filled.map(g => [g[0], g]));
410
+ const merged = new Set(filled.flatMap(g => g.slice(1)));
411
+ return content.flatMap((c, i) => {
412
+ if (merged.has(i))
413
+ return [];
414
+ const group = firstOf.get(i);
415
+ if (!group || group.length === 1)
416
+ return [c];
417
+ return [{ ...c, value: group.map(k => content[k].value ?? '').join('') }];
418
+ });
419
+ };
399
420
  const makeMask = (lines, separators) => {
400
421
  const tmplLength = Math.max(...[...lines, ...separators].map(s => s.length));
401
422
  // a table held apart by spaces alone splits on two of them, as a row on one line
@@ -419,7 +440,7 @@ const makeMask = (lines, separators) => {
419
440
  // per-column substrings and aggregating across lines (continuation lines
420
441
  // append to the cell at the same column position).
421
442
  const extractColumnsByTemplate = (text, template) => {
422
- const lines = flattenDeep(text.split(/\n/).filter(s => s.length > 0));
443
+ const lines = (0, flatten_deep_1.flattenDeep)(text.split(/\n/).filter(s => s.length > 0));
423
444
  const cols = lines.map(line => {
424
445
  const re = /((1+|0+))/g;
425
446
  const columns = [];
@@ -467,6 +488,13 @@ const splitLineByPlus = (line, mask = line) => trimEdgeEmpty(cutAt(line, mask, /
467
488
  const splitLineByWhitespace = (line, mask = line) => cutAt(line, mask, /\s{2,}/g)
468
489
  .map(c => c.trim())
469
490
  .filter(c => c !== '');
491
+ // A line of a table split line by line keeps every piece: the empty cell
492
+ // between two bars and the one an edge bar stands for. A bar wins over a plus,
493
+ // so a plus written in the text of a barred line stays text.
494
+ const splitVisibleLine = (line, mask = line) => {
495
+ const separator = detectLineSeparator(mask) === 'plus' ? /(?<=^|\s)\+(?=\s|$)/g : /(?<=^|\s)\|(?=\s|$)/g;
496
+ return cutAt(line, mask, separator).map(c => c.trim());
497
+ };
470
498
  const splitLineCells = (line, mask = line) => {
471
499
  const trimmed = line.trim();
472
500
  if (trimmed === '')
@@ -614,6 +642,8 @@ exports.default = (opt = {}) => tree => {
614
642
  const recursed = visiter ? visiter(transformedContent, ctx) : transformedContent;
615
643
  return normalizeCellCounts({ ...attached, content: recursed }, 'table', report);
616
644
  }
645
+ const ownScope = scopes.get(node) || {};
646
+ node = { ...node, content: groupRows(node.content || []) };
617
647
  let rows = [];
618
648
  const collectValues = row => {
619
649
  rows.push(row.value);
@@ -635,19 +665,23 @@ exports.default = (opt = {}) => tree => {
635
665
  .split(/\n/) // split each row by eol
636
666
  .filter(str => str.length > 0); // filter empty strings ( after slit )
637
667
  // split each row into lines
638
- const lines = flattenDeep(rows.map(splitToLines));
639
- const separators = flattenDeep(seps.map(splitToLines));
640
- const codeScope = codeScopeOf(node, scopes.get(node) || {});
668
+ const lines = (0, flatten_deep_1.flattenDeep)(rows.map(splitToLines));
669
+ const separators = (0, flatten_deep_1.flattenDeep)(seps.map(splitToLines));
670
+ const codeScope = codeScopeOf(node, ownScope);
641
671
  const protect = (line) => protectCodes(line, codeScope);
642
672
  const masks = lines.map(protect);
643
673
  // Rule 3: warn on mixed separator types within a single table
644
674
  detectMixedSeparators(masks, report, node);
645
675
  // collect text rows
646
676
  let textRows = [];
677
+ let headRows = [];
647
678
  (0, makeTransformer_1.default)({
648
679
  'row:text': row => {
649
680
  textRows.push(row.value);
650
681
  },
682
+ 'head:text': head => {
683
+ headRows.push(head.value);
684
+ },
651
685
  })(node);
652
686
  const makeBlock = (name, content, extra = {}) => {
653
687
  return { ...extra, name, type: 'block', content: Array.isArray(content) ? content : [content] };
@@ -658,16 +692,25 @@ exports.default = (opt = {}) => tree => {
658
692
  // Routing: a whitespace-separated row on one line splits by its own
659
693
  // gaps. In a table held apart by spaces alone a row on several lines
660
694
  // takes its columns from its own lines, so a line of another row does
661
- // not close its gaps. Rows with a visible separator keep the shared
662
- // mask: an edge `|` carries a real empty cell that per-line splitting
663
- // would drop.
695
+ // not close its gaps. A table whose every line carries a bar or a plus,
696
+ // and whose header and rows each stand on one line, splits each line by
697
+ // its own separators. Other tables with a visible separator keep the
698
+ // shared mask, which lines up the continuation lines of a row.
664
699
  const columnTemplate = makeMask(masks, separators);
665
700
  const seenSeparatorKinds = new Set(masks.map(detectLineSeparator));
666
701
  const spacedOnly = seenSeparatorKinds.size === 1 && seenSeparatorKinds.has('whitespace');
667
702
  const useMixedSplitting = (seenSeparatorKinds.has('pipe') || seenSeparatorKinds.has('plus')) && seenSeparatorKinds.has('whitespace');
703
+ const lineCount = (value) => value.split(/\r?\n/).filter(l => l.trim() !== '').length;
704
+ // the only text row of a table turns each of its lines into a row
705
+ const byLines = !spacedOnly &&
706
+ !useMixedSplitting &&
707
+ headRows.every(value => lineCount(value) <= 1) &&
708
+ (textRows.length === 1 || textRows.every(value => lineCount(value) <= 1));
668
709
  const splitsItself = (line) => useMixedSplitting || detectLineSeparator(protect(line)) === 'whitespace';
669
710
  const splitToCells = (rowValue) => {
670
711
  const rowLines = rowValue.split(/\r?\n/).filter(l => l.trim() !== '');
712
+ if (byLines)
713
+ return rowLines.length ? splitVisibleLine(rowLines[0], protect(rowLines[0])) : [];
671
714
  if (rowLines.length <= 1 && splitsItself(rowValue))
672
715
  return rowToCells(rowValue, protect);
673
716
  const template = spacedOnly ? makeMask(rowLines.map(protect), separators) : columnTemplate;
@@ -676,11 +719,13 @@ exports.default = (opt = {}) => tree => {
676
719
  const res = (0, makeTransformer_1.default)({
677
720
  'row:text': row => {
678
721
  if (textRows.length == 1) {
679
- // No separator blocks: each line of the only text row becomes its own row
680
- const textRowsLines = flattenDeep([row.value].map(splitToLines));
681
- return textRowsLines.map(line => makeRow((splitsItself(line)
682
- ? splitLineCells(line, protect(line))
683
- : extractColumnsByTemplate(line, columnTemplate)).map(makeCell)));
722
+ // the only text row of the table: each of its lines becomes its own row
723
+ const textRowsLines = (0, flatten_deep_1.flattenDeep)([row.value].map(splitToLines));
724
+ return textRowsLines.map(line => makeRow((byLines
725
+ ? splitVisibleLine(line, protect(line))
726
+ : splitsItself(line)
727
+ ? splitLineCells(line, protect(line))
728
+ : extractColumnsByTemplate(line, columnTemplate)).map(makeCell)));
684
729
  }
685
730
  return makeRow(splitToCells(row.value).map(makeCell));
686
731
  },
package/lib/types.d.ts CHANGED
@@ -148,7 +148,7 @@ export interface RootBlock extends Omit<Block, 'location'> {
148
148
  }
149
149
  export interface ParseDiagnostic {
150
150
  severity: 'warning';
151
- code: 'value-unreadable' | 'directive-unreadable' | 'table-row-cells' | 'table-cell-outside-row' | 'table-mixed-separators' | 'table-source-unreadable' | 'table-source-empty' | 'table-source-deferred' | 'markup-code-unclosed' | 'markup-code-longer-run' | 'markup-code-foreign-closer' | 'markup-code-reserved' | 'markup-code-unsupported' | 'markup-code-unreadable' | 'markup-code-too-deep';
151
+ code: 'value-unreadable' | 'directive-unreadable' | 'table-row-cells' | 'table-cell-outside-row' | 'table-mixed-separators' | 'table-source-unreadable' | 'table-source-empty' | 'table-source-deferred' | 'markup-code-unclosed' | 'markup-code-longer-run' | 'markup-code-foreign-closer' | 'markup-code-reserved' | 'markup-code-unsupported' | 'markup-code-unreadable' | 'markup-code-too-deep' | 'list-too-deep';
152
152
  message: string;
153
153
  location: Location;
154
154
  }
package/lib/version.d.ts CHANGED
@@ -1 +1 @@
1
- export declare const version = "0.0.82";
1
+ export declare const version = "0.0.84";
package/lib/version.js CHANGED
@@ -2,5 +2,5 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.version = void 0;
4
4
  // generated by scripts/inject-version.mjs — do not edit by hand
5
- exports.version = '0.0.82';
5
+ exports.version = '0.0.84';
6
6
  //# sourceMappingURL=version.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@podlite/schema",
3
- "version": "0.0.82",
3
+ "version": "0.0.84",
4
4
  "description": "Parser and AST schema for Podlite: typed blocks with positions, selectors, validate, traverse, and transform.",
5
5
  "main": "./lib/index.js",
6
6
  "sideEffects": false,
@@ -72,9 +72,9 @@
72
72
  "ajv": "^8.20.0",
73
73
  "entities": "^4.5.0",
74
74
  "events": "^3.1.0",
75
- "json-pointer": "^0.6.1",
75
+ "json-pointer": "^0.6.2",
76
76
  "marked": "16.4.2",
77
- "nanoid": "3.1.30",
77
+ "nanoid": "^3.3.20",
78
78
  "slugify": "^1.6.6"
79
79
  },
80
80
  "devDependencies": {
@@ -2154,6 +2154,7 @@
2154
2154
  "code": {
2155
2155
  "enum": [
2156
2156
  "directive-unreadable",
2157
+ "list-too-deep",
2157
2158
  "markup-code-foreign-closer",
2158
2159
  "markup-code-longer-run",
2159
2160
  "markup-code-reserved",
@@ -2154,6 +2154,7 @@
2154
2154
  "code": {
2155
2155
  "enum": [
2156
2156
  "directive-unreadable",
2157
+ "list-too-deep",
2157
2158
  "markup-code-foreign-closer",
2158
2159
  "markup-code-longer-run",
2159
2160
  "markup-code-reserved",