@podlite/schema 0.0.55 → 0.0.57

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/lib/index.d.ts CHANGED
@@ -1,8 +1,9 @@
1
1
  import { ErrorObject } from 'ajv';
2
- import { PodNode } from './types';
2
+ import { ParseDiagnostic, PodNode } from './types';
3
3
  export { PodliteDocument } from './types';
4
4
  export { AstTree } from './types';
5
5
  export * from './types';
6
+ export * from './block-names';
6
7
  export * from './blocks-helpers';
7
8
  export * from './query-helpers';
8
9
  export * from './ast-helpers';
@@ -68,6 +69,7 @@ export type parseOpt = {
68
69
  skipChain?: number;
69
70
  podMode?: number;
70
71
  mode?: 'pod' | 'md';
72
+ diagnostics?: ParseDiagnostic[];
71
73
  };
72
74
  declare function makeTree(): {
73
75
  (): void;
package/lib/index.js CHANGED
@@ -50,9 +50,11 @@ exports.isValidateError = isValidateError;
50
50
  exports.toTree = makeTree;
51
51
  const ajv_1 = __importDefault(require("ajv"));
52
52
  const pointer = __importStar(require("json-pointer"));
53
+ const block_names_1 = require("./block-names");
53
54
  const jsonShemes = __importStar(require("../schema"));
54
55
  const ast_inerator_1 = require("./ast-inerator");
55
56
  __exportStar(require("./types"), exports);
57
+ __exportStar(require("./block-names"), exports);
56
58
  __exportStar(require("./blocks-helpers"), exports);
57
59
  __exportStar(require("./query-helpers"), exports);
58
60
  __exportStar(require("./ast-helpers"), exports);
@@ -187,8 +189,8 @@ function makeTree() {
187
189
  return chain;
188
190
  }
189
191
  function parse(src, opt = { skipChain: 0, podMode: 1 }) {
190
- const { skipChain = 0, podMode = 1 } = opt;
191
- let tree = parser.parse(src, { podMode });
192
+ const { skipChain = 0, podMode = 1, diagnostics } = opt;
193
+ let tree = parser.parse(src, { podMode, diagnostics, blockNames: block_names_1.BLOCK_NAMES });
192
194
  if (!skipChain) {
193
195
  for (let i = 0; i < plugins.length; i++) {
194
196
  const plugin = plugins[i];
@@ -30,9 +30,18 @@ const podlitePluggable = ({ plugins = {} } = {}) => {
30
30
  return instance;
31
31
  };
32
32
  instance.parse = (text, opt = { skipChain: 0, podMode: 1 }) => {
33
- const rawTree = (0, _1.toTree)().use(ids_1.default).parse(text, opt);
33
+ const diagnostics = opt.diagnostics || [];
34
+ const rawTree = (0, _1.toTree)()
35
+ .use(ids_1.default)
36
+ .parse(text, { ...opt, diagnostics });
37
+ // one mistake inside a value reports twice: for the value and for the whole
38
+ // attribute around it. The narrower report names the place to fix
39
+ const innermost = diagnostics.filter(d => !diagnostics.some(other => other !== d &&
40
+ other.location.start.offset >= d.location.start.offset &&
41
+ other.location.end.offset <= d.location.end.offset));
42
+ diagnostics.splice(0, diagnostics.length, ...innermost);
34
43
  const root = (0, _1.mkRootBlock)({ margin: '' }, rawTree);
35
- return root;
44
+ return diagnostics.length ? { ...root, diagnostics } : root;
36
45
  };
37
46
  instance.toAst = ast => {
38
47
  return instance.toAstResult(ast).interator;
@@ -1,5 +1,26 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ // At this point the leading content element is still an unparsed text node;
4
+ // formatting codes are built from its value further down the pipeline. Cut the
5
+ // marker out of that value and leave the node in place — replacing the array
6
+ // with a plain string ends the chain early and drops every L<>, C<> and B< >
7
+ // written on the same line.
8
+ const stripMarker = (para, re) => {
9
+ para.text = para.text.replace(re, '');
10
+ if (para.type !== 'para')
11
+ return;
12
+ if (!Array.isArray(para.content)) {
13
+ para.content = [para.text];
14
+ return;
15
+ }
16
+ const first = para.content[0];
17
+ if (typeof first === 'string') {
18
+ para.content[0] = first.replace(re, '');
19
+ }
20
+ else if (first && typeof first.value === 'string') {
21
+ first.value = first.value.replace(re, '');
22
+ }
23
+ };
3
24
  exports.default = () => tree => {
4
25
  const visit = node => {
5
26
  if (Array.isArray(node)) {
@@ -27,10 +48,7 @@ exports.default = () => tree => {
27
48
  const checkboxMatch = checkboxRe.exec(startText.text);
28
49
  if (checkboxMatch) {
29
50
  node.checked = checkboxMatch[1] === 'x';
30
- startText.text = startText.text.replace(checkboxRe, '');
31
- if (startText.type === 'para') {
32
- startText.content = [startText.text];
33
- }
51
+ stripMarker(startText, checkboxRe);
34
52
  node.config = node.config || [];
35
53
  node.config.push({
36
54
  name: 'checked',
@@ -42,10 +60,7 @@ exports.default = () => tree => {
42
60
  let re = /^(\s*#\s*)/;
43
61
  const match = re.exec(startText.text);
44
62
  if (match) {
45
- startText.text = startText.text.replace(re, '');
46
- if (startText.type === 'para') {
47
- startText.content = [startText.text];
48
- }
63
+ stripMarker(startText, re);
49
64
  node.config = node.config || [];
50
65
  node.config.push({
51
66
  name: 'numbered',
package/lib/types.d.ts CHANGED
@@ -35,6 +35,7 @@ export interface RulesStrict {
35
35
  'X<>': RuleHandler<FormattingCodeX>;
36
36
  'S<>': RuleHandler<FormattingCodeS>;
37
37
  'L<>': RuleHandler<FormattingCodeL>;
38
+ 'W<>': RuleHandler<FormattingCodeW>;
38
39
  'U<>': RuleHandler<FormattingCodeAny>;
39
40
  'Z<>': RuleHandler<FormattingCodeAny>;
40
41
  'O<>': RuleHandler<FormattingCodeAny>;
@@ -134,6 +135,13 @@ export interface BlockCaption extends Omit<Block, 'content' | 'location' | 'marg
134
135
  export interface RootBlock extends Omit<Block, 'location'> {
135
136
  name: 'root';
136
137
  content: AstTree;
138
+ diagnostics?: Array<ParseDiagnostic>;
139
+ }
140
+ export interface ParseDiagnostic {
141
+ severity: 'warning';
142
+ code: 'value-unreadable' | 'directive-unreadable';
143
+ message: string;
144
+ location: Location;
137
145
  }
138
146
  export interface FormattingCodeB {
139
147
  type: 'fcode';
@@ -210,6 +218,12 @@ export interface FormattingCodeL {
210
218
  meta: string | null;
211
219
  content: string | Text | [Text];
212
220
  }
221
+ export interface FormattingCodeW {
222
+ type: 'fcode';
223
+ name: 'W';
224
+ meta: string | null;
225
+ content: string | Text | [Text];
226
+ }
213
227
  export interface FormattingCodeI {
214
228
  type: 'fcode';
215
229
  name: 'I';
@@ -262,10 +276,11 @@ export interface ConfigItemKV {
262
276
  }
263
277
  export interface BrokenConfigItem extends Omit<ConfigItem, 'type'> {
264
278
  }
279
+ export type ConfigItemType = 'boolean' | 'number' | 'string' | 'array' | 'map';
265
280
  export interface ConfigItem {
266
281
  name: string;
267
282
  value: boolean | string | number | Array<string | number | boolean> | ConfigItemKV;
268
- type: string;
283
+ type: ConfigItemType;
269
284
  isFalse?: boolean;
270
285
  }
271
286
  export interface BlockConfig {
@@ -386,7 +401,7 @@ export interface BlockFormula extends Omit<BlockNamed, 'content'> {
386
401
  name: 'formula';
387
402
  content: [Verbatim];
388
403
  }
389
- export type FormattingCodes = FormattingCodeA | FormattingCodeC | FormattingCodeB | FormattingCodeD | FormattingCodeE | FormattingCodeF | FormattingCodeI | FormattingCodeL | FormattingCodeN | FormattingCodeX | FormattingCodeZ | FormattingCodeV | FormattingCodeS | FormattingCodeAny;
404
+ export type FormattingCodes = FormattingCodeA | FormattingCodeC | FormattingCodeB | FormattingCodeD | FormattingCodeE | FormattingCodeF | FormattingCodeI | FormattingCodeL | FormattingCodeW | FormattingCodeN | FormattingCodeX | FormattingCodeZ | FormattingCodeV | FormattingCodeS | FormattingCodeAny;
390
405
  export type PodNode = Ambient | BlockPod | BlockData | BlockFormula | BlockCode | BlankLine | BlockNested | BlockMarkdown | BlockOutput | BlockInput | BlockInclude | BlockPara | BlockHead | BlockComment | BlockDefn | string | Para | Text | Code | BlockNamed | BlockAny | Verbatim | BlockTable | List | BlockConfig | BlockItem | Alias | BlockToc | BlockPicture | BlockImage | Image | RootBlock | Separator | BlockCaption | FormattingCodes | Toc;
391
406
  export type Node = PodNode;
392
407
  export type AstTree = Array<PodNode>;
package/lib/version.d.ts CHANGED
@@ -1 +1 @@
1
- export declare const version = "0.0.55";
1
+ export declare const version = "0.0.57";
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.55';
5
+ exports.version = '0.0.57';
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.55",
3
+ "version": "0.0.57",
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,
@@ -123,6 +123,9 @@
123
123
  {
124
124
  "$ref": "#/definitions/FormattingCodeL"
125
125
  },
126
+ {
127
+ "$ref": "#/definitions/FormattingCodeW"
128
+ },
126
129
  {
127
130
  "$ref": "#/definitions/FormattingCodeN"
128
131
  },
@@ -331,7 +334,7 @@
331
334
  ]
332
335
  },
333
336
  "type": {
334
- "type": "string"
337
+ "$ref": "#/definitions/ConfigItemType"
335
338
  },
336
339
  "isFalse": {
337
340
  "type": "boolean"
@@ -343,6 +346,16 @@
343
346
  "value"
344
347
  ]
345
348
  },
349
+ "ConfigItemType": {
350
+ "enum": [
351
+ "array",
352
+ "boolean",
353
+ "map",
354
+ "number",
355
+ "string"
356
+ ],
357
+ "type": "string"
358
+ },
346
359
  "BlockData": {
347
360
  "type": "object",
348
361
  "properties": {
@@ -1098,6 +1111,9 @@
1098
1111
  {
1099
1112
  "$ref": "#/definitions/FormattingCodeL"
1100
1113
  },
1114
+ {
1115
+ "$ref": "#/definitions/FormattingCodeW"
1116
+ },
1101
1117
  {
1102
1118
  "$ref": "#/definitions/FormattingCodeN"
1103
1119
  },
@@ -1279,6 +1295,12 @@
1279
1295
  "content": {
1280
1296
  "$ref": "#/definitions/AstTree"
1281
1297
  },
1298
+ "diagnostics": {
1299
+ "type": "array",
1300
+ "items": {
1301
+ "$ref": "#/definitions/ParseDiagnostic"
1302
+ }
1303
+ },
1282
1304
  "margin": {
1283
1305
  "type": "string"
1284
1306
  },
@@ -1316,6 +1338,34 @@
1316
1338
  "$ref": "#/definitions/PodNode"
1317
1339
  }
1318
1340
  },
1341
+ "ParseDiagnostic": {
1342
+ "type": "object",
1343
+ "properties": {
1344
+ "severity": {
1345
+ "type": "string",
1346
+ "const": "warning"
1347
+ },
1348
+ "code": {
1349
+ "enum": [
1350
+ "directive-unreadable",
1351
+ "value-unreadable"
1352
+ ],
1353
+ "type": "string"
1354
+ },
1355
+ "message": {
1356
+ "type": "string"
1357
+ },
1358
+ "location": {
1359
+ "$ref": "#/definitions/Location"
1360
+ }
1361
+ },
1362
+ "required": [
1363
+ "code",
1364
+ "location",
1365
+ "message",
1366
+ "severity"
1367
+ ]
1368
+ },
1319
1369
  "Image": {
1320
1370
  "type": "object",
1321
1371
  "properties": {
@@ -1945,6 +1995,9 @@
1945
1995
  {
1946
1996
  "$ref": "#/definitions/FormattingCodeL"
1947
1997
  },
1998
+ {
1999
+ "$ref": "#/definitions/FormattingCodeW"
2000
+ },
1948
2001
  {
1949
2002
  "$ref": "#/definitions/FormattingCodeN"
1950
2003
  },
@@ -2213,6 +2266,51 @@
2213
2266
  "type"
2214
2267
  ]
2215
2268
  },
2269
+ "FormattingCodeW": {
2270
+ "type": "object",
2271
+ "properties": {
2272
+ "type": {
2273
+ "type": "string",
2274
+ "const": "fcode"
2275
+ },
2276
+ "name": {
2277
+ "type": "string",
2278
+ "const": "W"
2279
+ },
2280
+ "meta": {
2281
+ "type": [
2282
+ "null",
2283
+ "string"
2284
+ ]
2285
+ },
2286
+ "content": {
2287
+ "anyOf": [
2288
+ {
2289
+ "$ref": "#/definitions/Text"
2290
+ },
2291
+ {
2292
+ "type": "array",
2293
+ "items": [
2294
+ {
2295
+ "$ref": "#/definitions/Text"
2296
+ }
2297
+ ],
2298
+ "minItems": 1,
2299
+ "maxItems": 1
2300
+ },
2301
+ {
2302
+ "type": "string"
2303
+ }
2304
+ ]
2305
+ }
2306
+ },
2307
+ "required": [
2308
+ "content",
2309
+ "meta",
2310
+ "name",
2311
+ "type"
2312
+ ]
2313
+ },
2216
2314
  "FormattingCodeN": {
2217
2315
  "type": "object",
2218
2316
  "properties": {
@@ -2252,6 +2350,9 @@
2252
2350
  {
2253
2351
  "$ref": "#/definitions/FormattingCodeL"
2254
2352
  },
2353
+ {
2354
+ "$ref": "#/definitions/FormattingCodeW"
2355
+ },
2255
2356
  {
2256
2357
  "$ref": "#/definitions/FormattingCodeN"
2257
2358
  },
@@ -2334,6 +2435,9 @@
2334
2435
  {
2335
2436
  "$ref": "#/definitions/FormattingCodeL"
2336
2437
  },
2438
+ {
2439
+ "$ref": "#/definitions/FormattingCodeW"
2440
+ },
2337
2441
  {
2338
2442
  "$ref": "#/definitions/FormattingCodeN"
2339
2443
  },
@@ -2470,6 +2574,9 @@
2470
2574
  {
2471
2575
  "$ref": "#/definitions/FormattingCodeL"
2472
2576
  },
2577
+ {
2578
+ "$ref": "#/definitions/FormattingCodeW"
2579
+ },
2473
2580
  {
2474
2581
  "$ref": "#/definitions/FormattingCodeN"
2475
2582
  },
@@ -123,6 +123,9 @@
123
123
  {
124
124
  "$ref": "#/definitions/FormattingCodeL"
125
125
  },
126
+ {
127
+ "$ref": "#/definitions/FormattingCodeW"
128
+ },
126
129
  {
127
130
  "$ref": "#/definitions/FormattingCodeN"
128
131
  },
@@ -331,7 +334,7 @@
331
334
  ]
332
335
  },
333
336
  "type": {
334
- "type": "string"
337
+ "$ref": "#/definitions/ConfigItemType"
335
338
  },
336
339
  "isFalse": {
337
340
  "type": "boolean"
@@ -343,6 +346,16 @@
343
346
  "value"
344
347
  ]
345
348
  },
349
+ "ConfigItemType": {
350
+ "enum": [
351
+ "array",
352
+ "boolean",
353
+ "map",
354
+ "number",
355
+ "string"
356
+ ],
357
+ "type": "string"
358
+ },
346
359
  "BlockData": {
347
360
  "type": "object",
348
361
  "properties": {
@@ -1098,6 +1111,9 @@
1098
1111
  {
1099
1112
  "$ref": "#/definitions/FormattingCodeL"
1100
1113
  },
1114
+ {
1115
+ "$ref": "#/definitions/FormattingCodeW"
1116
+ },
1101
1117
  {
1102
1118
  "$ref": "#/definitions/FormattingCodeN"
1103
1119
  },
@@ -1279,6 +1295,12 @@
1279
1295
  "content": {
1280
1296
  "$ref": "#/definitions/AstTree"
1281
1297
  },
1298
+ "diagnostics": {
1299
+ "type": "array",
1300
+ "items": {
1301
+ "$ref": "#/definitions/ParseDiagnostic"
1302
+ }
1303
+ },
1282
1304
  "margin": {
1283
1305
  "type": "string"
1284
1306
  },
@@ -1316,6 +1338,34 @@
1316
1338
  "$ref": "#/definitions/PodNode"
1317
1339
  }
1318
1340
  },
1341
+ "ParseDiagnostic": {
1342
+ "type": "object",
1343
+ "properties": {
1344
+ "severity": {
1345
+ "type": "string",
1346
+ "const": "warning"
1347
+ },
1348
+ "code": {
1349
+ "enum": [
1350
+ "directive-unreadable",
1351
+ "value-unreadable"
1352
+ ],
1353
+ "type": "string"
1354
+ },
1355
+ "message": {
1356
+ "type": "string"
1357
+ },
1358
+ "location": {
1359
+ "$ref": "#/definitions/Location"
1360
+ }
1361
+ },
1362
+ "required": [
1363
+ "code",
1364
+ "location",
1365
+ "message",
1366
+ "severity"
1367
+ ]
1368
+ },
1319
1369
  "Image": {
1320
1370
  "type": "object",
1321
1371
  "properties": {
@@ -1945,6 +1995,9 @@
1945
1995
  {
1946
1996
  "$ref": "#/definitions/FormattingCodeL"
1947
1997
  },
1998
+ {
1999
+ "$ref": "#/definitions/FormattingCodeW"
2000
+ },
1948
2001
  {
1949
2002
  "$ref": "#/definitions/FormattingCodeN"
1950
2003
  },
@@ -2213,6 +2266,51 @@
2213
2266
  "type"
2214
2267
  ]
2215
2268
  },
2269
+ "FormattingCodeW": {
2270
+ "type": "object",
2271
+ "properties": {
2272
+ "type": {
2273
+ "type": "string",
2274
+ "const": "fcode"
2275
+ },
2276
+ "name": {
2277
+ "type": "string",
2278
+ "const": "W"
2279
+ },
2280
+ "meta": {
2281
+ "type": [
2282
+ "null",
2283
+ "string"
2284
+ ]
2285
+ },
2286
+ "content": {
2287
+ "anyOf": [
2288
+ {
2289
+ "$ref": "#/definitions/Text"
2290
+ },
2291
+ {
2292
+ "type": "array",
2293
+ "items": [
2294
+ {
2295
+ "$ref": "#/definitions/Text"
2296
+ }
2297
+ ],
2298
+ "minItems": 1,
2299
+ "maxItems": 1
2300
+ },
2301
+ {
2302
+ "type": "string"
2303
+ }
2304
+ ]
2305
+ }
2306
+ },
2307
+ "required": [
2308
+ "content",
2309
+ "meta",
2310
+ "name",
2311
+ "type"
2312
+ ]
2313
+ },
2216
2314
  "FormattingCodeN": {
2217
2315
  "type": "object",
2218
2316
  "properties": {
@@ -2252,6 +2350,9 @@
2252
2350
  {
2253
2351
  "$ref": "#/definitions/FormattingCodeL"
2254
2352
  },
2353
+ {
2354
+ "$ref": "#/definitions/FormattingCodeW"
2355
+ },
2255
2356
  {
2256
2357
  "$ref": "#/definitions/FormattingCodeN"
2257
2358
  },
@@ -2334,6 +2435,9 @@
2334
2435
  {
2335
2436
  "$ref": "#/definitions/FormattingCodeL"
2336
2437
  },
2438
+ {
2439
+ "$ref": "#/definitions/FormattingCodeW"
2440
+ },
2337
2441
  {
2338
2442
  "$ref": "#/definitions/FormattingCodeN"
2339
2443
  },
@@ -2470,6 +2574,9 @@
2470
2574
  {
2471
2575
  "$ref": "#/definitions/FormattingCodeL"
2472
2576
  },
2577
+ {
2578
+ "$ref": "#/definitions/FormattingCodeW"
2579
+ },
2473
2580
  {
2474
2581
  "$ref": "#/definitions/FormattingCodeN"
2475
2582
  },