@podlite/schema 0.0.57 → 0.0.59

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.
@@ -7,6 +7,7 @@ export declare const cleanIds: (src?: {
7
7
  skipChain: number;
8
8
  podMode: number;
9
9
  }) => (tree: any) => any;
10
+ export declare const headingId: (text: string) => string;
10
11
  export declare const slugifyText: (text: string) => string;
11
12
  /**
12
13
  * Add set id to 'id' to each blocks
@@ -3,7 +3,7 @@ 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.setAllLinksToAnchor = exports.frozenIds = exports.slugifyText = exports.cleanIds = void 0;
6
+ exports.setAllLinksToAnchor = exports.frozenIds = exports.slugifyText = exports.headingId = exports.cleanIds = void 0;
7
7
  const __1 = require("..");
8
8
  const nanoid_1 = require("nanoid");
9
9
  const slugify_1 = __importDefault(require("slugify"));
@@ -27,7 +27,14 @@ const cleanIds = (src = { skipChain: 0, podMode: 1 }) => tree => {
27
27
  return transformerBlocks(tree, {});
28
28
  };
29
29
  exports.cleanIds = cleanIds;
30
- // TODO: refactor linking for blocks
30
+ // A heading carries its own text as the identifier. Shaping it for a particular
31
+ // output — collapsing separators, dropping punctuation, numbering repeats — is the
32
+ // exporter's job (see getSafeNodeId), not the parser's. Slugifying here also
33
+ // transliterated cyrillic, so «Приветствие Мир» became Privetstvie-Mir and the
34
+ // original name could not be recovered.
35
+ const headingId = (text) => text.trim().replace(/\s+/g, ' ');
36
+ exports.headingId = headingId;
37
+ // kept for callers outside the tree layer
31
38
  const slugifyText = (text) => {
32
39
  return (0, slugify_1.default)(text.trim(), {});
33
40
  };
@@ -76,7 +83,7 @@ const middleware = () => tree => {
76
83
  return node;
77
84
  }
78
85
  else if (node.name == 'head') {
79
- return { ...node, id: (0, exports.slugifyText)((0, __1.getTextContentFromNode)(node)) };
86
+ return { ...node, id: (0, exports.headingId)((0, __1.getTextContentFromNode)(node)) };
80
87
  }
81
88
  else {
82
89
  return { ...node, id: (0, nanoid_1.nanoid)() };
@@ -526,25 +526,18 @@ exports.default = () => tree => {
526
526
  const makeRow = cells => makeBlock('row', cells);
527
527
  const makeHeaderRow = cells => makeBlock('row', cells, { config: [{ name: 'header', value: true, type: 'boolean' }] });
528
528
  const makeCell = text => makeBlock('cell', { type: 'text', value: text });
529
- // Routing: per-line separator detection (Rule 1) is used only when a
530
- // line with a visible separator (`|` or `+`) coexists with one that
531
- // has only whitespace separation the Scenario 2 case where the
532
- // legacy positional mask collapses columns. Tables with a uniform
533
- // separator, or with both visible kinds (pipe + plus) handled by the
534
- // shared mask, fall back to the legacy positional template, which
535
- // preserves continuation-line alignment in multi-line rows and keeps
536
- // byte-for-byte AST/HTML output stable.
529
+ // Routing: a whitespace-separated row on one line splits by its own
530
+ // gaps two spaces are enough there, while the positional mask needs
531
+ // three. Rows with a visible separator keep the mask: an edge `|`
532
+ // carries a real empty cell that per-line splitting would drop.
537
533
  const columnTemplate = makeMask(lines, separators);
538
534
  const seenSeparatorKinds = new Set(lines.map(detectLineSeparator));
539
- const hasVisible = seenSeparatorKinds.has('pipe') || seenSeparatorKinds.has('plus');
540
- const hasWhitespace = seenSeparatorKinds.has('whitespace');
541
- const useMixedSplitting = hasVisible && hasWhitespace;
535
+ const useMixedSplitting = (seenSeparatorKinds.has('pipe') || seenSeparatorKinds.has('plus')) && seenSeparatorKinds.has('whitespace');
536
+ const splitsItself = (line) => useMixedSplitting || detectLineSeparator(line) === 'whitespace';
542
537
  const splitToCells = (rowValue) => {
543
- if (useMixedSplitting) {
544
- const rowLines = rowValue.split(/\r?\n/).filter(l => l.trim() !== '');
545
- if (rowLines.length <= 1)
546
- return rowToCells(rowValue);
547
- }
538
+ const rowLines = rowValue.split(/\r?\n/).filter(l => l.trim() !== '');
539
+ if (rowLines.length <= 1 && splitsItself(rowValue))
540
+ return rowToCells(rowValue);
548
541
  return extractColumnsByTemplate(rowValue, columnTemplate);
549
542
  };
550
543
  const res = (0, makeTransformer_1.default)({
@@ -552,10 +545,7 @@ exports.default = () => tree => {
552
545
  if (textRows.length == 1) {
553
546
  // No separator blocks: each line of the only text row becomes its own row
554
547
  const textRowsLines = flattenDeep([row.value].map(splitToLines));
555
- if (useMixedSplitting) {
556
- return textRowsLines.map(line => makeRow(splitLineCells(line).map(makeCell)));
557
- }
558
- return textRowsLines.map(line => makeRow(extractColumnsByTemplate(line, columnTemplate).map(makeCell)));
548
+ return textRowsLines.map(line => makeRow((splitsItself(line) ? splitLineCells(line) : extractColumnsByTemplate(line, columnTemplate)).map(makeCell)));
559
549
  }
560
550
  return makeRow(splitToCells(row.value).map(makeCell));
561
551
  },
package/lib/version.d.ts CHANGED
@@ -1 +1 @@
1
- export declare const version = "0.0.57";
1
+ export declare const version = "0.0.59";
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.57';
5
+ exports.version = '0.0.59';
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.57",
3
+ "version": "0.0.59",
4
4
  "description": "AST tools and schema for Podlite markup language — validate, traverse, and transform document trees",
5
5
  "main": "./lib/index.js",
6
6
  "sideEffects": false,