@podlite/schema 0.0.78 → 0.0.79

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.
@@ -0,0 +1,10 @@
1
+ export declare const ALIAS_EXPANSION_DEPTH = 8;
2
+ export declare const ALIAS_EXPANSION_BUDGET = 10000;
3
+ export declare const expandAlias: <T>(ctx: {
4
+ [key: string]: any;
5
+ }, term: string, walk: () => T, warn: (message: string) => void) => {
6
+ expanded: true;
7
+ result: T;
8
+ } | {
9
+ expanded: false;
10
+ };
@@ -0,0 +1,57 @@
1
+ "use strict";
2
+ /*
3
+ =begin pod
4
+
5
+ =TITLE How far an alias is expanded
6
+
7
+ C<A<>> is replaced by the text of its alias, and that text is read and walked
8
+ again, so an alias may name another one, or itself. One use of C<A<>> in a text
9
+ starts an expansion; the expansions inside it share its state. An alias already
10
+ on the way is a cycle; a chain deeper than C<ALIAS_EXPANSION_DEPTH> or more
11
+ than C<ALIAS_EXPANSION_BUDGET> replacements in one expansion stops it. What is
12
+ refused is written as C<A<name>>, as an alias that is not defined, and is told
13
+ once per expansion.
14
+
15
+ A footnote walks its content later, when the expansion it stands in is over; it
16
+ starts an expansion of its own.
17
+
18
+ =end pod
19
+ */
20
+ Object.defineProperty(exports, "__esModule", { value: true });
21
+ exports.expandAlias = exports.ALIAS_EXPANSION_BUDGET = exports.ALIAS_EXPANSION_DEPTH = void 0;
22
+ exports.ALIAS_EXPANSION_DEPTH = 8;
23
+ exports.ALIAS_EXPANSION_BUDGET = 10000;
24
+ const KEY = 'aliasExpansion';
25
+ // Expands `term` through `walk` when the limits let it, and returns true; returns
26
+ // false when it is refused, after telling why once per expansion. The state lives
27
+ // on ctx, so copies of ctx made inside the walk share it.
28
+ const expandAlias = (ctx, term, walk, warn) => {
29
+ const open = ctx[KEY];
30
+ const state = open && open.chain.length ? open : { chain: [], spent: 0, told: false };
31
+ const refuse = (message) => {
32
+ if (!state.told)
33
+ warn(message);
34
+ state.told = true;
35
+ return { expanded: false };
36
+ };
37
+ if (state.chain.includes(term)) {
38
+ return refuse(`alias ${term} expands into itself: ${[...state.chain, term].join(' → ')}`);
39
+ }
40
+ if (state.chain.length >= exports.ALIAS_EXPANSION_DEPTH) {
41
+ return refuse(`alias ${term} expands deeper than ${exports.ALIAS_EXPANSION_DEPTH} levels: ${state.chain.join(' → ')} → ${term}`);
42
+ }
43
+ if (state.spent >= exports.ALIAS_EXPANSION_BUDGET) {
44
+ return refuse(`alias expansion ${state.chain[0] ?? term} makes more than ${exports.ALIAS_EXPANSION_BUDGET} replacements`);
45
+ }
46
+ state.spent++;
47
+ state.chain.push(term);
48
+ ctx[KEY] = state;
49
+ try {
50
+ return { expanded: true, result: walk() };
51
+ }
52
+ finally {
53
+ state.chain.pop();
54
+ }
55
+ };
56
+ exports.expandAlias = expandAlias;
57
+ //# sourceMappingURL=alias.js.map
package/lib/index.d.ts CHANGED
@@ -8,6 +8,8 @@ export * from './attribute-names';
8
8
  export * from './blocks-helpers';
9
9
  export * from './query-helpers';
10
10
  export * from './ast-helpers';
11
+ export { expandAlias, ALIAS_EXPANSION_DEPTH, ALIAS_EXPANSION_BUDGET } from './helpers/alias';
12
+ export { MARKUP_CODE_DEPTH_LIMIT } from './codes/read';
11
13
  export * from './helpers/handlers';
12
14
  export { makeInterator } from './ast-inerator';
13
15
  export { makeTransformer, isNamedBlock, isSemanticBlock } from './helpers/makeTransformer';
@@ -101,7 +103,7 @@ export { applySetToFirst, mergeSet, isSetTransparent, isSetTarget } from './set-
101
103
  export type { SetOutcome } from './set-assign';
102
104
  export { markGuarded, isCovered, guardedTextLeaves, getMaskedTextContent, renderCodeText } from './guard';
103
105
  export { applyFoldedSections } from './folded-sections';
104
- export { testCaption, testFoldedByAuthor } from './test-display';
106
+ export { testCaption, testFoldedByAuthor, canOwnTest, mayHoldTests } from './test-display';
105
107
  export { tocTitleText } from './toc-caption';
106
108
  export type { SelectorDoc, ParsedSelector, SelectorOptions } from './selectors';
107
109
  export { applyImageBase } from './image-base';
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.tocTitleText = exports.testFoldedByAuthor = exports.testCaption = exports.applyFoldedSections = exports.renderCodeText = exports.getMaskedTextContent = 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 = void 0;
43
- exports.version = exports.applyImageBase = void 0;
42
+ exports.renderCodeText = exports.getMaskedTextContent = 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 = void 0;
43
+ exports.version = exports.applyImageBase = exports.tocTitleText = exports.mayHoldTests = exports.canOwnTest = exports.testFoldedByAuthor = exports.testCaption = exports.applyFoldedSections = void 0;
44
44
  exports.toAst = toAst;
45
45
  exports.getTextContentFromNode = getTextContentFromNode;
46
46
  exports.getPodContentFromNode = getPodContentFromNode;
@@ -60,6 +60,12 @@ __exportStar(require("./attribute-names"), exports);
60
60
  __exportStar(require("./blocks-helpers"), exports);
61
61
  __exportStar(require("./query-helpers"), exports);
62
62
  __exportStar(require("./ast-helpers"), exports);
63
+ var alias_1 = require("./helpers/alias");
64
+ Object.defineProperty(exports, "expandAlias", { enumerable: true, get: function () { return alias_1.expandAlias; } });
65
+ Object.defineProperty(exports, "ALIAS_EXPANSION_DEPTH", { enumerable: true, get: function () { return alias_1.ALIAS_EXPANSION_DEPTH; } });
66
+ Object.defineProperty(exports, "ALIAS_EXPANSION_BUDGET", { enumerable: true, get: function () { return alias_1.ALIAS_EXPANSION_BUDGET; } });
67
+ var read_1 = require("./codes/read");
68
+ Object.defineProperty(exports, "MARKUP_CODE_DEPTH_LIMIT", { enumerable: true, get: function () { return read_1.MARKUP_CODE_DEPTH_LIMIT; } });
63
69
  __exportStar(require("./helpers/handlers"), exports);
64
70
  var ast_inerator_2 = require("./ast-inerator");
65
71
  Object.defineProperty(exports, "makeInterator", { enumerable: true, get: function () { return ast_inerator_2.makeInterator; } });
@@ -91,7 +97,7 @@ Object.defineProperty(exports, "cleanIds", { enumerable: true, get: function ()
91
97
  Object.defineProperty(exports, "frozenIds", { enumerable: true, get: function () { return pluggableParser_1.frozenIds; } });
92
98
  Object.defineProperty(exports, "headingId", { enumerable: true, get: function () { return pluggableParser_1.headingId; } });
93
99
  const parser = __importStar(require("./grammar"));
94
- const read_1 = require("./codes/read");
100
+ const read_2 = require("./codes/read");
95
101
  const parseAttributes_2 = require("./helpers/parseAttributes");
96
102
  const plugin_vmargin_1 = __importDefault(require("./plugin-vmargin"));
97
103
  const plugin_formatting_codes_1 = __importDefault(require("./plugin-formatting-codes"));
@@ -239,7 +245,7 @@ function makeTree() {
239
245
  }
240
246
  const parse = makeTree().parse;
241
247
  exports.parse = parse;
242
- const parseFormattingCodes = (text, options = {}) => (0, read_1.readCodes)(text, { parseAttributes: parseAttributes_2.parseAttributes, ...options });
248
+ const parseFormattingCodes = (text, options = {}) => (0, read_2.readCodes)(text, { parseAttributes: parseAttributes_2.parseAttributes, ...options });
243
249
  exports.parseFormattingCodes = parseFormattingCodes;
244
250
  var exportHtml_1 = require("./exportHtml");
245
251
  Object.defineProperty(exports, "toHtml", { enumerable: true, get: function () { return __importDefault(exportHtml_1).default; } });
@@ -271,6 +277,8 @@ Object.defineProperty(exports, "applyFoldedSections", { enumerable: true, get: f
271
277
  var test_display_1 = require("./test-display");
272
278
  Object.defineProperty(exports, "testCaption", { enumerable: true, get: function () { return test_display_1.testCaption; } });
273
279
  Object.defineProperty(exports, "testFoldedByAuthor", { enumerable: true, get: function () { return test_display_1.testFoldedByAuthor; } });
280
+ Object.defineProperty(exports, "canOwnTest", { enumerable: true, get: function () { return test_display_1.canOwnTest; } });
281
+ Object.defineProperty(exports, "mayHoldTests", { enumerable: true, get: function () { return test_display_1.mayHoldTests; } });
274
282
  var toc_caption_1 = require("./toc-caption");
275
283
  Object.defineProperty(exports, "tocTitleText", { enumerable: true, get: function () { return toc_caption_1.tocTitleText; } });
276
284
  var image_base_1 = require("./image-base");
@@ -1,3 +1,5 @@
1
1
  export declare const testCaption: (node: any, ctx: any) => string;
2
2
  export declare const testFoldedByAuthor: (node: any, ctx: any) => boolean | undefined;
3
3
  export declare const longestBacktickRun: (text: string) => number;
4
+ export declare const canOwnTest: (node: unknown) => boolean;
5
+ export declare const mayHoldTests: (node: unknown) => boolean;
@@ -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.longestBacktickRun = exports.testFoldedByAuthor = exports.testCaption = void 0;
6
+ exports.mayHoldTests = exports.canOwnTest = exports.longestBacktickRun = exports.testFoldedByAuthor = exports.testCaption = void 0;
7
7
  const config_1 = __importDefault(require("./helpers/config"));
8
8
  const ast_helpers_1 = require("./ast-helpers");
9
9
  /*
@@ -64,4 +64,70 @@ exports.testFoldedByAuthor = testFoldedByAuthor;
64
64
  // A fence has to be longer than any run of backticks inside what it encloses.
65
65
  const longestBacktickRun = (text) => Math.max(0, ...(text.match(/`+/g) || []).map(run => run.length));
66
66
  exports.longestBacktickRun = longestBacktickRun;
67
+ // a heading, a directive, a comment or data says nothing a test could check, and a
68
+ // directive wrapped into a group would lose the reach it has over what follows
69
+ const NOT_A_TEST_OWNER = new Set([
70
+ 'head',
71
+ 'comment',
72
+ 'data',
73
+ 'test',
74
+ 'fixture',
75
+ 'assert',
76
+ 'resource',
77
+ 'include',
78
+ 'toc',
79
+ 'pod',
80
+ ]);
81
+ const isRecord = (value) => typeof value === 'object' && value !== null;
82
+ /*
83
+ =begin pod :kind<export>
84
+
85
+ =head2 canOwnTest
86
+
87
+ Whether a node can be the block a C<=test> right after it belongs to. A test
88
+ belongs to the nearest preceding sibling that is not itself a test; when that
89
+ sibling cannot own it, the page draws the test with no rule and the linter warns.
90
+ A paragraph, a list and code can; so can any block but a heading, a directive, a
91
+ comment, data, a part of a test, a table of contents and the blocks the tree adds,
92
+ whose names begin with C<_>.
93
+
94
+ =end pod
95
+ */
96
+ const canOwnTest = (node) => {
97
+ if (!isRecord(node))
98
+ return false;
99
+ if (node.type === 'para' || node.type === 'list' || node.type === 'code')
100
+ return true;
101
+ if (node.type !== 'block' || typeof node.name !== 'string')
102
+ return false;
103
+ return !node.name.startsWith('_') && !NOT_A_TEST_OWNER.has(node.name);
104
+ };
105
+ exports.canOwnTest = canOwnTest;
106
+ // source, data and the parts of a test hold no tests of their own
107
+ const HOLDS_NO_TESTS = new Set([
108
+ 'test',
109
+ 'fixture',
110
+ 'assert',
111
+ 'resource',
112
+ 'code',
113
+ 'comment',
114
+ 'data',
115
+ 'markdown',
116
+ 'input',
117
+ 'output',
118
+ 'formula',
119
+ ]);
120
+ /*
121
+ =begin pod :kind<export>
122
+
123
+ =head2 mayHoldTests
124
+
125
+ Whether a test can stand among the children of a node, so that a pass over the
126
+ tests of a document goes into it: no for a test itself and its parts, and for
127
+ code, comments, data, Markdown, input, output and formulas.
128
+
129
+ =end pod
130
+ */
131
+ const mayHoldTests = (node) => !isRecord(node) || !HOLDS_NO_TESTS.has(String(node.name));
132
+ exports.mayHoldTests = mayHoldTests;
67
133
  //# sourceMappingURL=test-display.js.map
package/lib/types.d.ts CHANGED
@@ -147,7 +147,7 @@ export interface RootBlock extends Omit<Block, 'location'> {
147
147
  }
148
148
  export interface ParseDiagnostic {
149
149
  severity: 'warning';
150
- 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';
150
+ 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
151
  message: string;
152
152
  location: Location;
153
153
  }
package/lib/version.d.ts CHANGED
@@ -1 +1 @@
1
- export declare const version = "0.0.78";
1
+ export declare const version = "0.0.79";
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.78';
5
+ exports.version = '0.0.79';
6
6
  //# sourceMappingURL=version.js.map
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@podlite/schema",
3
- "version": "0.0.78",
4
- "description": "AST tools and schema for Podlite markup language — validate, traverse, and transform document trees",
3
+ "version": "0.0.79",
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,
7
7
  "exports": {
@@ -1981,6 +1981,7 @@
1981
1981
  "markup-code-foreign-closer",
1982
1982
  "markup-code-longer-run",
1983
1983
  "markup-code-reserved",
1984
+ "markup-code-too-deep",
1984
1985
  "markup-code-unclosed",
1985
1986
  "markup-code-unreadable",
1986
1987
  "markup-code-unsupported",
@@ -1981,6 +1981,7 @@
1981
1981
  "markup-code-foreign-closer",
1982
1982
  "markup-code-longer-run",
1983
1983
  "markup-code-reserved",
1984
+ "markup-code-too-deep",
1984
1985
  "markup-code-unclosed",
1985
1986
  "markup-code-unreadable",
1986
1987
  "markup-code-unsupported",