@podlite/schema 0.0.69 → 0.0.71

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 (114) hide show
  1. package/CHANGELOG.podlite +96 -0
  2. package/esm/ast-helpers.d.ts +11 -0
  3. package/esm/ast-helpers.js +279 -27
  4. package/esm/ast-helpers.js.map +1 -1
  5. package/esm/ast-inerator.js +1 -1
  6. package/esm/block-names.d.ts +2 -2
  7. package/esm/block-names.js +7 -0
  8. package/esm/block-names.js.map +1 -1
  9. package/esm/blocks-helpers.d.ts +1 -1
  10. package/esm/blocks-helpers.js +3 -1
  11. package/esm/blocks-helpers.js.map +1 -1
  12. package/esm/exportAny.js +5 -5
  13. package/esm/exportHtml.js +95 -38
  14. package/esm/exportHtml.js.map +1 -1
  15. package/esm/exportMarkdown.js +120 -35
  16. package/esm/exportMarkdown.js.map +1 -1
  17. package/esm/grammar.js +588 -454
  18. package/esm/grammar.js.map +1 -1
  19. package/esm/guard.js +12 -2
  20. package/esm/guard.js.map +1 -1
  21. package/esm/helpers/blockName.d.ts +8 -0
  22. package/esm/helpers/blockName.js +60 -0
  23. package/esm/helpers/blockName.js.map +1 -0
  24. package/esm/helpers/configPropagation.d.ts +12 -2
  25. package/esm/helpers/configPropagation.js +51 -13
  26. package/esm/helpers/configPropagation.js.map +1 -1
  27. package/esm/helpers/corePlugins.d.ts +1 -1
  28. package/esm/helpers/corePlugins.js +7 -5
  29. package/esm/helpers/corePlugins.js.map +1 -1
  30. package/esm/helpers/handlers.js +3 -3
  31. package/esm/helpers/ids.js +1 -1
  32. package/esm/helpers/makeInterator.js +3 -2
  33. package/esm/helpers/makeInterator.js.map +1 -1
  34. package/esm/helpers/makeTransformer.js +1 -1
  35. package/esm/helpers/parseAttributes.js +1 -1
  36. package/esm/index.d.ts +13 -3
  37. package/esm/index.js +59 -47
  38. package/esm/index.js.map +1 -1
  39. package/esm/pluggableParser.d.ts +6 -2
  40. package/esm/pluggableParser.js +15 -15
  41. package/esm/pluggableParser.js.map +1 -1
  42. package/esm/plugin-clean-location.js +1 -1
  43. package/esm/plugin-data-table.js +7 -8
  44. package/esm/plugin-data-table.js.map +1 -1
  45. package/esm/plugin-defn-fill-term.js +1 -1
  46. package/esm/plugin-formatting-codes.js +70 -29
  47. package/esm/plugin-formatting-codes.js.map +1 -1
  48. package/esm/plugin-group-items.js +1 -1
  49. package/esm/plugin-set.js +15 -18
  50. package/esm/plugin-set.js.map +1 -1
  51. package/esm/plugin-tables.js +8 -3
  52. package/esm/plugin-tables.js.map +1 -1
  53. package/esm/query-helpers.js +1 -1
  54. package/esm/selectors.d.ts +25 -8
  55. package/esm/selectors.js +399 -142
  56. package/esm/selectors.js.map +1 -1
  57. package/esm/set-assign.d.ts +17 -0
  58. package/esm/set-assign.js +143 -0
  59. package/esm/set-assign.js.map +1 -0
  60. package/esm/test-display.d.ts +3 -0
  61. package/esm/test-display.js +58 -0
  62. package/esm/test-display.js.map +1 -0
  63. package/esm/toc-caption.d.ts +7 -0
  64. package/esm/toc-caption.js +23 -0
  65. package/esm/toc-caption.js.map +1 -0
  66. package/esm/types.d.ts +16 -1
  67. package/esm/version.d.ts +1 -1
  68. package/esm/version.js +1 -1
  69. package/esm/writerHtml.js +1 -1
  70. package/esm/writerMarkdown.js +1 -1
  71. package/lib/ast-helpers.d.ts +11 -0
  72. package/lib/ast-helpers.js +279 -26
  73. package/lib/block-names.d.ts +2 -2
  74. package/lib/block-names.js +7 -0
  75. package/lib/blocks-helpers.d.ts +1 -1
  76. package/lib/blocks-helpers.js +3 -1
  77. package/lib/exportHtml.js +84 -27
  78. package/lib/exportMarkdown.js +111 -26
  79. package/lib/grammar.js +588 -454
  80. package/lib/guard.js +11 -1
  81. package/lib/helpers/blockName.d.ts +8 -0
  82. package/lib/helpers/blockName.js +66 -0
  83. package/lib/helpers/configPropagation.d.ts +12 -2
  84. package/lib/helpers/configPropagation.js +54 -14
  85. package/lib/helpers/corePlugins.d.ts +1 -1
  86. package/lib/helpers/corePlugins.js +4 -2
  87. package/lib/helpers/makeInterator.js +3 -2
  88. package/lib/index.d.ts +13 -3
  89. package/lib/index.js +33 -6
  90. package/lib/pluggableParser.d.ts +6 -2
  91. package/lib/pluggableParser.js +5 -5
  92. package/lib/plugin-data-table.js +4 -5
  93. package/lib/plugin-formatting-codes.js +65 -24
  94. package/lib/plugin-set.js +15 -18
  95. package/lib/plugin-tables.js +6 -1
  96. package/lib/selectors.d.ts +25 -8
  97. package/lib/selectors.js +401 -141
  98. package/lib/set-assign.d.ts +17 -0
  99. package/lib/set-assign.js +150 -0
  100. package/lib/test-display.d.ts +3 -0
  101. package/lib/test-display.js +67 -0
  102. package/lib/toc-caption.d.ts +7 -0
  103. package/lib/toc-caption.js +27 -0
  104. package/lib/types.d.ts +16 -1
  105. package/lib/version.d.ts +1 -1
  106. package/lib/version.js +1 -1
  107. package/package.json +3 -3
  108. package/schema/AstTree.json +160 -0
  109. package/schema/PodliteDocument.json +160 -0
  110. package/esm/helpers/makeQuery.test.d.ts +0 -1
  111. package/esm/helpers/makeQuery.test.js +0 -51
  112. package/esm/helpers/makeQuery.test.js.map +0 -1
  113. package/lib/helpers/makeQuery.test.d.ts +0 -1
  114. package/lib/helpers/makeQuery.test.js +0 -51
package/lib/plugin-set.js CHANGED
@@ -1,20 +1,12 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- // Directives and =comment blocks pass =set attributes through to the next
4
- // real block instead of consuming them.
5
- const isTransparent = (node) => {
6
- if (!node || typeof node !== 'object')
7
- return false;
8
- if (node.type === 'set' || node.type === 'config' || node.type === 'alias' || node.type === 'blankline')
9
- return true;
10
- if (node.type === 'block' && (node.name === 'comment' || node.name === 'boundary' || node.name === 'include'))
11
- return true;
12
- return false;
13
- };
3
+ const set_assign_1 = require("./set-assign");
4
+ const blockName_1 = require("./helpers/blockName");
14
5
  const isBlock = (node) => node && typeof node === 'object' && node.type === 'block';
6
+ const isInclude = (node) => isBlock(node) && node.name === 'include';
15
7
  // Each content array is its own lexical scope: pending attributes never leak
16
- // into or out of a nested block.
17
- const applyInScope = (content) => {
8
+ // into or out of a nested block. `holder` is the block the content belongs to.
9
+ const applyInScope = (content, holder) => {
18
10
  let pending = [];
19
11
  const out = [];
20
12
  for (const node of content) {
@@ -29,11 +21,16 @@ const applyInScope = (content) => {
29
21
  }
30
22
  let next = node;
31
23
  if (isBlock(node) && Array.isArray(node.content)) {
32
- next = { ...node, content: applyInScope(node.content) };
24
+ next = { ...node, content: applyInScope(node.content, (0, blockName_1.holderInside)(node, holder)) };
25
+ }
26
+ // the target is chosen in the content the include resolves to
27
+ if (pending.length && isInclude(next)) {
28
+ next = { ...next, set: pending.map(c => ({ ...c, from: 'set' })) };
29
+ pending = [];
33
30
  }
34
- if (pending.length && isBlock(next) && !isTransparent(next)) {
31
+ if (pending.length && (0, set_assign_1.isSetTarget)(next, holder)) {
35
32
  const own = new Set((next.config || []).map((c) => c && c.name));
36
- const additions = pending.filter(c => !own.has(c.name));
33
+ const additions = pending.filter(c => !own.has(c.name)).map(c => ({ ...c, from: 'set' }));
37
34
  if (additions.length)
38
35
  next = { ...next, config: [...(next.config || []), ...additions] };
39
36
  pending = [];
@@ -47,9 +44,9 @@ const applyInScope = (content) => {
47
44
  };
48
45
  exports.default = () => (tree) => {
49
46
  if (Array.isArray(tree))
50
- return applyInScope(tree);
47
+ return applyInScope(tree, undefined);
51
48
  if (tree && typeof tree === 'object' && Array.isArray(tree.content)) {
52
- return { ...tree, content: applyInScope(tree.content) };
49
+ return { ...tree, content: applyInScope(tree.content, (0, blockName_1.holderInside)(tree, undefined)) };
53
50
  }
54
51
  return tree;
55
52
  };
@@ -501,6 +501,11 @@ exports.default = (opt = {}) => tree => {
501
501
  // =table data:<key> → resolve =data block with :key<key>
502
502
  // =table file:<path> → defer to host reader (not implemented here)
503
503
  const ref = detectSourceReference(node);
504
+ // a file source is read by whoever renders the table; the tree holds
505
+ // only its address, and a reader of the tree is told so
506
+ if (ref && ref.scheme === 'file') {
507
+ report('table-source-deferred', `source file:${ref.target} is left to the renderer, the table holds no rows`, node);
508
+ }
504
509
  if (ref && ref.scheme === 'data') {
505
510
  const dataBlock = findDataBlockByKey(tree, ref.target);
506
511
  if (!dataBlock) {
@@ -519,7 +524,7 @@ exports.default = (opt = {}) => tree => {
519
524
  const text = extractDataText(dataBlock);
520
525
  const rows = isCsv ? parseCsv(text) : parseTsv(text);
521
526
  if (rows.length === 0) {
522
- report('table-source-unreadable', `${isCsv ? 'CSV' : 'TSV'} source data:${ref.target} has no rows, table rendered as empty`, node);
527
+ report('table-source-empty', `${isCsv ? 'CSV' : 'TSV'} source data:${ref.target} has no rows, table rendered as empty`, node);
523
528
  return { ...node, content: [] };
524
529
  }
525
530
  const hasHeader = mimeParams.header === 'present';
@@ -8,13 +8,6 @@ export type SelectorDoc = {
8
8
  file: string;
9
9
  node: PodNode | PodliteDocument;
10
10
  };
11
- export type ValueSpec = {
12
- kind: 'angle';
13
- value: string;
14
- } | {
15
- kind: 'contains';
16
- value: string;
17
- };
18
11
  export type Condition = {
19
12
  modifier?: '!' | '?' | '!?';
20
13
  attrName: string;
@@ -30,6 +23,30 @@ export type ParsedSelector = {
30
23
  anchor?: string;
31
24
  patterns: Pattern[];
32
25
  };
26
+ export type ValueSpec = {
27
+ kind: 'angle';
28
+ value: string;
29
+ } | {
30
+ kind: 'contains';
31
+ value: string;
32
+ } | {
33
+ kind: 'paren';
34
+ value: string;
35
+ } | {
36
+ kind: 'in';
37
+ value: string;
38
+ };
33
39
  export declare const parseSelector: (selector: string) => ParsedSelector | undefined;
40
+ export declare const outermost: (blocks: PodNode[]) => PodNode[];
34
41
  export declare const filePathMatches: (docFile: string, target: string) => boolean;
35
- export declare const runSelector: <T extends SelectorDoc>(selector: string, docs: T[]) => T[] | PodNode[];
42
+ export declare const getDocIDs: (doc: SelectorDoc) => string[];
43
+ export declare class SelectorError extends Error {
44
+ readonly kind: 'resolution' | 'format' | 'address';
45
+ constructor(kind: 'resolution' | 'format' | 'address', message: string);
46
+ }
47
+ export type SelectorOptions = {
48
+ home?: SelectorDoc[];
49
+ readFile?: (document: string) => SelectorDoc[] | undefined;
50
+ readSource?: (scheme: 'file' | 'doc', document: string) => SelectorDoc[] | undefined;
51
+ };
52
+ export declare const runSelector: <T extends SelectorDoc>(selector: string, docs: T[], options?: SelectorOptions) => T[] | PodNode[];