@podlite/schema 0.0.62 → 0.0.64

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 (53) hide show
  1. package/CHANGELOG.podlite +18 -0
  2. package/esm/exportHtml.js +24 -6
  3. package/esm/exportHtml.js.map +1 -1
  4. package/esm/exportMarkdown.js +12 -6
  5. package/esm/exportMarkdown.js.map +1 -1
  6. package/esm/grammarfc.js +1668 -475
  7. package/esm/grammarfc.js.map +1 -1
  8. package/esm/helpers/config.d.ts +1 -0
  9. package/esm/helpers/config.js +8 -0
  10. package/esm/helpers/config.js.map +1 -1
  11. package/esm/helpers/configPropagation.d.ts +1 -1
  12. package/esm/helpers/configPropagation.js +2 -1
  13. package/esm/helpers/configPropagation.js.map +1 -1
  14. package/esm/helpers/link-config.d.ts +8 -0
  15. package/esm/helpers/link-config.js +23 -0
  16. package/esm/helpers/link-config.js.map +1 -0
  17. package/esm/helpers/makeInterator.js +23 -0
  18. package/esm/helpers/makeInterator.js.map +1 -1
  19. package/esm/index.d.ts +6 -2
  20. package/esm/index.js +10 -2
  21. package/esm/index.js.map +1 -1
  22. package/esm/plugin-data-table.js +5 -1
  23. package/esm/plugin-data-table.js.map +1 -1
  24. package/esm/plugin-formatting-codes.js +8 -4
  25. package/esm/plugin-formatting-codes.js.map +1 -1
  26. package/esm/plugin-tables.d.ts +1 -1
  27. package/esm/plugin-tables.js +12 -5
  28. package/esm/plugin-tables.js.map +1 -1
  29. package/esm/types.d.ts +2 -0
  30. package/esm/version.d.ts +1 -1
  31. package/esm/version.js +1 -1
  32. package/lib/exportHtml.js +57 -6
  33. package/lib/exportMarkdown.js +45 -6
  34. package/lib/grammarfc.js +1668 -475
  35. package/lib/helpers/config.d.ts +1 -0
  36. package/lib/helpers/config.js +10 -1
  37. package/lib/helpers/configPropagation.d.ts +1 -1
  38. package/lib/helpers/configPropagation.js +2 -1
  39. package/lib/helpers/link-config.d.ts +8 -0
  40. package/lib/helpers/link-config.js +27 -0
  41. package/lib/helpers/makeInterator.js +23 -0
  42. package/lib/index.d.ts +6 -2
  43. package/lib/index.js +13 -3
  44. package/lib/plugin-data-table.js +5 -1
  45. package/lib/plugin-formatting-codes.js +8 -4
  46. package/lib/plugin-tables.d.ts +1 -1
  47. package/lib/plugin-tables.js +12 -5
  48. package/lib/types.d.ts +2 -0
  49. package/lib/version.d.ts +1 -1
  50. package/lib/version.js +1 -1
  51. package/package.json +1 -1
  52. package/schema/AstTree.json +12 -0
  53. package/schema/PodliteDocument.json +12 -0
@@ -9,5 +9,6 @@ export interface Attr {
9
9
  (): {};
10
10
  exists(name: string): boolean;
11
11
  }
12
+ export declare const codeConfigWithDefaults: (node: any, ctx?: Context) => any;
12
13
  export declare const makeAttrs: (node: any, ctx?: Context) => Attr;
13
14
  export default makeAttrs;
@@ -1,6 +1,15 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.makeAttrs = void 0;
3
+ exports.makeAttrs = exports.codeConfigWithDefaults = void 0;
4
+ // A markup code is pre-configured under its name followed by a pair of angles.
5
+ // The declaration comes first, so a value written on the code itself is read
6
+ // last and wins.
7
+ const codeConfigWithDefaults = (node, ctx = {}) => {
8
+ const declared = ctx.config ? ctx.config[`${node.name}<>`] : undefined;
9
+ const own = Array.isArray(node.config) ? node.config : [];
10
+ return Array.isArray(declared) ? [...declared, ...own] : own;
11
+ };
12
+ exports.codeConfigWithDefaults = codeConfigWithDefaults;
4
13
  const makeAttrs = (node, ctx = {}) => {
5
14
  const config = node.config instanceof Array ? node.config : [];
6
15
  // add config's from ctx
@@ -1,3 +1,3 @@
1
1
  import { PodNode, PodliteDocument } from '../types';
2
- export declare const propagateConfigDefaults: <T extends PodliteDocument | PodNode>(ast: T) => T;
2
+ export declare const propagateConfigDefaults: <T extends PodliteDocument | PodNode | unknown[]>(ast: T) => T;
3
3
  export default propagateConfigDefaults;
@@ -43,7 +43,8 @@ const walk = (node, config) => {
43
43
  }
44
44
  }
45
45
  if (anyNode.content !== undefined) {
46
- walk(anyNode.content, config);
46
+ // a block is a lexical scope: what is declared inside it stays inside
47
+ walk(anyNode.content, anyNode.type === 'block' ? { ...config } : config);
47
48
  }
48
49
  };
49
50
  const propagateConfigDefaults = (ast) => {
@@ -0,0 +1,8 @@
1
+ import { ConfigItem } from '../types';
2
+ export type LinkConfig = {
3
+ newContext?: boolean;
4
+ title?: string;
5
+ lang?: string;
6
+ download?: boolean | string;
7
+ };
8
+ export declare const readLinkConfig: (config?: ConfigItem[]) => LinkConfig;
@@ -0,0 +1,27 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.readLinkConfig = void 0;
4
+ const last = (config, name) => config.filter(item => item.name === name).slice(-1)[0];
5
+ const asText = (item) => item && (item.type === 'string' || item.type === 'number') ? String(item.value) : undefined;
6
+ const readLinkConfig = (config) => {
7
+ if (!Array.isArray(config) || config.length === 0)
8
+ return {};
9
+ const result = {};
10
+ const openInNew = last(config, 'new');
11
+ if (openInNew)
12
+ result.newContext = openInNew.value !== false;
13
+ const title = asText(last(config, 'title'));
14
+ if (title !== undefined)
15
+ result.title = title;
16
+ const lang = asText(last(config, 'lang'));
17
+ if (lang !== undefined)
18
+ result.lang = lang;
19
+ const download = last(config, 'download');
20
+ if (download) {
21
+ const name = asText(download);
22
+ result.download = name !== undefined ? name : download.value !== false;
23
+ }
24
+ return result;
25
+ };
26
+ exports.readLinkConfig = readLinkConfig;
27
+ //# sourceMappingURL=link-config.js.map
@@ -19,6 +19,29 @@ function thisFunc(rules) {
19
19
  // convert string to lex node with type
20
20
  return interator({ type: 'text', value: node }, context);
21
21
  }
22
+ // a block is a lexical scope: a =config or =alias written inside it must not
23
+ // reach what follows the block. The context object itself is kept, since
24
+ // rules count cells and mark rows through it
25
+ if (node.type === 'block' && context) {
26
+ const outer = { config: context.config, alias: context.alias };
27
+ const had = { config: context.hasOwnProperty('config'), alias: context.hasOwnProperty('alias') };
28
+ context.config = { ...outer.config };
29
+ context.alias = { ...outer.alias };
30
+ try {
31
+ return dispatch(node, context);
32
+ }
33
+ finally {
34
+ for (const key of ['config', 'alias']) {
35
+ if (had[key])
36
+ context[key] = outer[key];
37
+ else
38
+ delete context[key];
39
+ }
40
+ }
41
+ }
42
+ return dispatch(node, context);
43
+ }
44
+ function dispatch(node, context) {
22
45
  // get first rule for this node
23
46
  const reversed = rules.slice();
24
47
  reversed.reverse();
package/lib/index.d.ts CHANGED
@@ -11,8 +11,10 @@ export * from './helpers/handlers';
11
11
  export { makeInterator } from './ast-inerator';
12
12
  export { makeTransformer, isNamedBlock, isSemanticBlock } from './helpers/makeTransformer';
13
13
  export { toAny } from './exportAny';
14
- export { makeAttrs } from './helpers/config';
14
+ export { makeAttrs, codeConfigWithDefaults } from './helpers/config';
15
15
  export { parseAttributes } from './helpers/parseAttributes';
16
+ export { readLinkConfig } from './helpers/link-config';
17
+ export type { LinkConfig } from './helpers/link-config';
16
18
  export { pluginCleanLocation } from './plugin-clean-location';
17
19
  export { toAnyRules } from './helpers/plugins';
18
20
  export { podlitePluggable, Podlite, PodliteExport, cleanIds, frozenIds } from './pluggableParser';
@@ -79,7 +81,9 @@ declare function makeTree(): {
79
81
  export { makeTree as toTree };
80
82
  declare const parse: Function;
81
83
  export { parse as parse };
82
- export { parse as parseFormattingCodes } from './grammarfc';
84
+ export declare const parseFormattingCodes: (text: string, options?: {
85
+ [key: string]: any;
86
+ }) => any[];
83
87
  export { default as toHtml } from './exportHtml';
84
88
  export { default as toMarkdown } from './exportMarkdown';
85
89
  export { default as Writer } from './writer';
package/lib/index.js CHANGED
@@ -39,7 +39,7 @@ 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.version = exports.applyImageBase = exports.runSelector = exports.parseSelector = exports.Writer = exports.toMarkdown = exports.toHtml = exports.parseFormattingCodes = exports.parse = exports.frozenIds = exports.cleanIds = exports.podlitePluggable = exports.toAnyRules = exports.pluginCleanLocation = exports.parseAttributes = exports.makeAttrs = exports.toAny = exports.isSemanticBlock = exports.isNamedBlock = exports.makeTransformer = exports.makeInterator = void 0;
42
+ exports.version = exports.applyImageBase = exports.runSelector = exports.parseSelector = exports.Writer = exports.toMarkdown = exports.toHtml = exports.parseFormattingCodes = exports.parse = exports.frozenIds = exports.cleanIds = exports.podlitePluggable = exports.toAnyRules = exports.pluginCleanLocation = exports.readLinkConfig = exports.parseAttributes = exports.codeConfigWithDefaults = exports.makeAttrs = exports.toAny = exports.isSemanticBlock = exports.isNamedBlock = exports.makeTransformer = exports.makeInterator = void 0;
43
43
  exports.toAst = toAst;
44
44
  exports.getTextContentFromNode = getTextContentFromNode;
45
45
  exports.getPodContentFromNode = getPodContentFromNode;
@@ -69,8 +69,11 @@ var exportAny_1 = require("./exportAny");
69
69
  Object.defineProperty(exports, "toAny", { enumerable: true, get: function () { return exportAny_1.toAny; } });
70
70
  var config_1 = require("./helpers/config");
71
71
  Object.defineProperty(exports, "makeAttrs", { enumerable: true, get: function () { return config_1.makeAttrs; } });
72
+ Object.defineProperty(exports, "codeConfigWithDefaults", { enumerable: true, get: function () { return config_1.codeConfigWithDefaults; } });
72
73
  var parseAttributes_1 = require("./helpers/parseAttributes");
73
74
  Object.defineProperty(exports, "parseAttributes", { enumerable: true, get: function () { return parseAttributes_1.parseAttributes; } });
75
+ var link_config_1 = require("./helpers/link-config");
76
+ Object.defineProperty(exports, "readLinkConfig", { enumerable: true, get: function () { return link_config_1.readLinkConfig; } });
74
77
  var plugin_clean_location_1 = require("./plugin-clean-location");
75
78
  Object.defineProperty(exports, "pluginCleanLocation", { enumerable: true, get: function () { return plugin_clean_location_1.pluginCleanLocation; } });
76
79
  var plugins_1 = require("./helpers/plugins");
@@ -80,6 +83,8 @@ Object.defineProperty(exports, "podlitePluggable", { enumerable: true, get: func
80
83
  Object.defineProperty(exports, "cleanIds", { enumerable: true, get: function () { return pluggableParser_1.cleanIds; } });
81
84
  Object.defineProperty(exports, "frozenIds", { enumerable: true, get: function () { return pluggableParser_1.frozenIds; } });
82
85
  const parser = __importStar(require("./grammar"));
86
+ const grammarfc_1 = require("./grammarfc");
87
+ const parseAttributes_2 = require("./helpers/parseAttributes");
83
88
  const plugin_vmargin_1 = __importDefault(require("./plugin-vmargin"));
84
89
  const plugin_formatting_codes_1 = __importDefault(require("./plugin-formatting-codes"));
85
90
  const plugin_items_1 = __importDefault(require("./plugin-items"));
@@ -88,6 +93,7 @@ const plugin_group_defn_1 = __importDefault(require("./plugin-group-defn"));
88
93
  const plugin_group_items_1 = __importDefault(require("./plugin-group-items"));
89
94
  const plugin_defn_fill_term_1 = __importDefault(require("./plugin-defn-fill-term"));
90
95
  const plugin_set_1 = __importDefault(require("./plugin-set"));
96
+ const configPropagation_1 = require("./helpers/configPropagation");
91
97
  const plugin_tables_1 = __importDefault(require("./plugin-tables"));
92
98
  const plugin_data_table_1 = __importDefault(require("./plugin-data-table"));
93
99
  function toAst() {
@@ -162,6 +168,7 @@ function isValidateError(result, src) {
162
168
  }
163
169
  return undefined;
164
170
  }
171
+ const configDefaults_plug = () => tree => (0, configPropagation_1.propagateConfigDefaults)(tree);
165
172
  function makeTree() {
166
173
  var plugins = [];
167
174
  chain.use = use;
@@ -173,6 +180,9 @@ function makeTree() {
173
180
  chain.use(plugin_defn_fill_term_1.default);
174
181
  chain.use(plugin_tables_1.default);
175
182
  chain.use(plugin_data_table_1.default);
183
+ // pre-configured attributes must sit on the blocks before markup codes are
184
+ // parsed, since :allow decides which of them are read at all
185
+ chain.use(configDefaults_plug);
176
186
  chain.use(plugin_formatting_codes_1.default);
177
187
  // save order for the next two plugins
178
188
  chain.use(plugin_group_items_1.default);
@@ -205,8 +215,8 @@ function makeTree() {
205
215
  }
206
216
  const parse = makeTree().parse;
207
217
  exports.parse = parse;
208
- var grammarfc_1 = require("./grammarfc");
209
- Object.defineProperty(exports, "parseFormattingCodes", { enumerable: true, get: function () { return grammarfc_1.parse; } });
218
+ const parseFormattingCodes = (text, options = {}) => (0, grammarfc_1.parse)(text, { parseAttributes: parseAttributes_2.parseAttributes, ...options });
219
+ exports.parseFormattingCodes = parseFormattingCodes;
210
220
  var exportHtml_1 = require("./exportHtml");
211
221
  Object.defineProperty(exports, "toHtml", { enumerable: true, get: function () { return __importDefault(exportHtml_1).default; } });
212
222
  var exportMarkdown_1 = require("./exportMarkdown");
@@ -137,7 +137,11 @@ function processDataTable(node, tree) {
137
137
  if (renameMap) {
138
138
  rows = applyRename(rows, renameMap, hasHeader);
139
139
  }
140
- const filledNode = { ...node, name: 'table', content: (0, plugin_tables_1.csvToTableContent)(rows, hasHeader) };
140
+ const filledNode = {
141
+ ...node,
142
+ name: 'table',
143
+ content: (0, plugin_tables_1.csvToTableContent)(rows, hasHeader, attrs.getAllValues('allow')),
144
+ };
141
145
  return (0, plugin_tables_1.normalizeCellCounts)(filledNode, 'data-table');
142
146
  }
143
147
  exports.default = () => tree => {
@@ -40,15 +40,16 @@ const fcparser = __importStar(require("./grammarfc"));
40
40
  const makeTransformer_1 = __importDefault(require("./helpers/makeTransformer"));
41
41
  const makeTransformer_2 = require("./helpers/makeTransformer");
42
42
  const config_1 = __importDefault(require("./helpers/config"));
43
+ const parseAttributes_1 = require("./helpers/parseAttributes");
43
44
  const middle = () => tree => {
44
45
  const transformerBlocks = (0, makeTransformer_1.default)({
45
46
  ':para': (n, ctx, visiter) => {
46
47
  return (0, makeTransformer_1.default)({
47
48
  ':text': (n, ctx) => {
48
- return fcparser.parse(n.value);
49
+ return fcparser.parse(n.value, { parseAttributes: parseAttributes_1.parseAttributes });
49
50
  },
50
51
  ':verbatim': (n, ctx) => {
51
- return fcparser.parse(n.value);
52
+ return fcparser.parse(n.value, { parseAttributes: parseAttributes_1.parseAttributes });
52
53
  },
53
54
  })(n, { ...ctx });
54
55
  return n;
@@ -70,10 +71,13 @@ const middle = () => tree => {
70
71
  return n;
71
72
  if (isVerbatimDefault && allowValues.length === 0)
72
73
  return n;
74
+ // a cell built from data carries its own set; declared empty means no code acts
75
+ if (name === 'cell' && conf.exists('allow') && allowValues.length === 0)
76
+ return n;
73
77
  const allowed = allowValues.sort();
74
78
  const transformer = (0, makeTransformer_1.default)({
75
- ':verbatim': (n, ctx) => fcparser.parse(n.value, { allowed }),
76
- ':text': (n, ctx) => fcparser.parse(n.value, { allowed }),
79
+ ':verbatim': (n, ctx) => fcparser.parse(n.value, { allowed, parseAttributes: parseAttributes_1.parseAttributes }),
80
+ ':text': (n, ctx) => fcparser.parse(n.value, { allowed, parseAttributes: parseAttributes_1.parseAttributes }),
77
81
  ':block': (n, ctx) => transformerBlocks(n, { ...ctx }),
78
82
  });
79
83
  return { ...n, content: transformer(n.content, { ...ctx }) };
@@ -6,7 +6,7 @@ export declare function parseMimeType(raw: any): {
6
6
  };
7
7
  export declare function findDataBlockByKey(tree: any, key: any): any;
8
8
  export declare function extractDataText(dataNode: any): any;
9
- export declare function csvToTableContent(csvRows: any, hasHeader?: boolean): any;
9
+ export declare function csvToTableContent(csvRows: any, hasHeader?: boolean, allow?: string[]): any;
10
10
  export declare function normalizeCellCounts(tableNode: any, source?: string): any;
11
11
  declare const _default: () => (tree: any) => any;
12
12
  export default _default;
@@ -178,13 +178,19 @@ function detectSourceReference(tableNode) {
178
178
  return null;
179
179
  return { scheme: m[1], target: m[2] };
180
180
  }
181
- function buildCellBlock(text) {
182
- return {
181
+ function buildCellBlock(text, allow) {
182
+ const block = {
183
183
  name: 'cell',
184
184
  type: 'block',
185
185
  margin: '',
186
186
  content: [{ type: 'text', value: text }],
187
187
  };
188
+ // a value read from data is not markup, so the cell carries the set of codes
189
+ // that may act inside it, empty unless the block declared :allow
190
+ if (allow) {
191
+ block.config = [{ name: 'allow', value: [...allow], type: 'array' }];
192
+ }
193
+ return block;
188
194
  }
189
195
  function buildRowBlock(cells, isHeader) {
190
196
  const block = {
@@ -204,9 +210,9 @@ function buildRowBlock(cells, isHeader) {
204
210
  // `:header`. Default behaviour leaves all rows unmarked, matching authors
205
211
  // who use a structured table with explicit `=begin row :header` or a
206
212
  // Markdown GFM table.
207
- function csvToTableContent(csvRows, hasHeader = false) {
213
+ function csvToTableContent(csvRows, hasHeader = false, allow = []) {
208
214
  return csvRows.map((row, i) => {
209
- const cells = row.map(v => buildCellBlock(v.trim()));
215
+ const cells = row.map(v => buildCellBlock(v.trim(), allow));
210
216
  return buildRowBlock(cells, hasHeader && i === 0);
211
217
  });
212
218
  }
@@ -468,7 +474,8 @@ exports.default = () => tree => {
468
474
  return { ...node, content: [] };
469
475
  }
470
476
  const hasHeader = mimeParams.header === 'present';
471
- const filledNode = { ...node, content: csvToTableContent(rows, hasHeader) };
477
+ const allow = (0, config_1.default)(node, {}).getAllValues('allow');
478
+ const filledNode = { ...node, content: csvToTableContent(rows, hasHeader, allow) };
472
479
  return normalizeCellCounts(filledNode, `table data:${ref.target}`);
473
480
  }
474
481
  // Rule 4: source not tabular → render as code block so content remains visible
package/lib/types.d.ts CHANGED
@@ -216,12 +216,14 @@ export interface FormattingCodeL {
216
216
  type: 'fcode';
217
217
  name: 'L';
218
218
  meta: string | null;
219
+ config?: ConfigItem[];
219
220
  content: string | Text | [Text];
220
221
  }
221
222
  export interface FormattingCodeW {
222
223
  type: 'fcode';
223
224
  name: 'W';
224
225
  meta: string | null;
226
+ config?: ConfigItem[];
225
227
  content: string | Text | [Text];
226
228
  }
227
229
  export interface FormattingCodeI {
package/lib/version.d.ts CHANGED
@@ -1 +1 @@
1
- export declare const version = "0.0.62";
1
+ export declare const version = "0.0.64";
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.62';
5
+ exports.version = '0.0.64';
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.62",
3
+ "version": "0.0.64",
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,
@@ -2238,6 +2238,12 @@
2238
2238
  "string"
2239
2239
  ]
2240
2240
  },
2241
+ "config": {
2242
+ "type": "array",
2243
+ "items": {
2244
+ "$ref": "#/definitions/ConfigItem"
2245
+ }
2246
+ },
2241
2247
  "content": {
2242
2248
  "anyOf": [
2243
2249
  {
@@ -2283,6 +2289,12 @@
2283
2289
  "string"
2284
2290
  ]
2285
2291
  },
2292
+ "config": {
2293
+ "type": "array",
2294
+ "items": {
2295
+ "$ref": "#/definitions/ConfigItem"
2296
+ }
2297
+ },
2286
2298
  "content": {
2287
2299
  "anyOf": [
2288
2300
  {
@@ -2238,6 +2238,12 @@
2238
2238
  "string"
2239
2239
  ]
2240
2240
  },
2241
+ "config": {
2242
+ "type": "array",
2243
+ "items": {
2244
+ "$ref": "#/definitions/ConfigItem"
2245
+ }
2246
+ },
2241
2247
  "content": {
2242
2248
  "anyOf": [
2243
2249
  {
@@ -2283,6 +2289,12 @@
2283
2289
  "string"
2284
2290
  ]
2285
2291
  },
2292
+ "config": {
2293
+ "type": "array",
2294
+ "items": {
2295
+ "$ref": "#/definitions/ConfigItem"
2296
+ }
2297
+ },
2286
2298
  "content": {
2287
2299
  "anyOf": [
2288
2300
  {