@podlite/schema 0.0.70 → 0.0.72

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 (97) hide show
  1. package/CHANGELOG.podlite +82 -0
  2. package/esm/ast-helpers.d.ts +11 -0
  3. package/esm/ast-helpers.js +277 -25
  4. package/esm/ast-helpers.js.map +1 -1
  5. package/esm/block-names.d.ts +2 -2
  6. package/esm/block-names.js +7 -0
  7. package/esm/block-names.js.map +1 -1
  8. package/esm/blocks-helpers.d.ts +1 -1
  9. package/esm/blocks-helpers.js +3 -1
  10. package/esm/blocks-helpers.js.map +1 -1
  11. package/esm/exportHtml.js +85 -28
  12. package/esm/exportHtml.js.map +1 -1
  13. package/esm/exportMarkdown.js +112 -27
  14. package/esm/exportMarkdown.js.map +1 -1
  15. package/esm/grammar.js +588 -454
  16. package/esm/grammar.js.map +1 -1
  17. package/esm/guard.js +11 -1
  18. package/esm/guard.js.map +1 -1
  19. package/esm/helpers/blockName.d.ts +8 -0
  20. package/esm/helpers/blockName.js +60 -0
  21. package/esm/helpers/blockName.js.map +1 -0
  22. package/esm/helpers/configPropagation.d.ts +12 -2
  23. package/esm/helpers/configPropagation.js +51 -13
  24. package/esm/helpers/configPropagation.js.map +1 -1
  25. package/esm/helpers/corePlugins.d.ts +1 -1
  26. package/esm/helpers/corePlugins.js +4 -2
  27. package/esm/helpers/corePlugins.js.map +1 -1
  28. package/esm/helpers/makeInterator.js +3 -2
  29. package/esm/helpers/makeInterator.js.map +1 -1
  30. package/esm/index.d.ts +13 -3
  31. package/esm/index.js +15 -5
  32. package/esm/index.js.map +1 -1
  33. package/esm/pluggableParser.d.ts +6 -2
  34. package/esm/pluggableParser.js +5 -5
  35. package/esm/pluggableParser.js.map +1 -1
  36. package/esm/plugin-data-table.js +4 -5
  37. package/esm/plugin-data-table.js.map +1 -1
  38. package/esm/plugin-formatting-codes.js +65 -24
  39. package/esm/plugin-formatting-codes.js.map +1 -1
  40. package/esm/plugin-set.js +15 -18
  41. package/esm/plugin-set.js.map +1 -1
  42. package/esm/plugin-tables.js +6 -1
  43. package/esm/plugin-tables.js.map +1 -1
  44. package/esm/selectors.d.ts +25 -8
  45. package/esm/selectors.js +398 -141
  46. package/esm/selectors.js.map +1 -1
  47. package/esm/set-assign.d.ts +17 -0
  48. package/esm/set-assign.js +143 -0
  49. package/esm/set-assign.js.map +1 -0
  50. package/esm/test-display.d.ts +3 -0
  51. package/esm/test-display.js +58 -0
  52. package/esm/test-display.js.map +1 -0
  53. package/esm/toc-caption.d.ts +7 -0
  54. package/esm/toc-caption.js +23 -0
  55. package/esm/toc-caption.js.map +1 -0
  56. package/esm/types.d.ts +16 -1
  57. package/esm/version.d.ts +1 -1
  58. package/esm/version.js +1 -1
  59. package/lib/ast-helpers.d.ts +11 -0
  60. package/lib/ast-helpers.js +279 -26
  61. package/lib/block-names.d.ts +2 -2
  62. package/lib/block-names.js +7 -0
  63. package/lib/blocks-helpers.d.ts +1 -1
  64. package/lib/blocks-helpers.js +3 -1
  65. package/lib/exportHtml.js +84 -27
  66. package/lib/exportMarkdown.js +111 -26
  67. package/lib/grammar.js +588 -454
  68. package/lib/guard.js +11 -1
  69. package/lib/helpers/blockName.d.ts +8 -0
  70. package/lib/helpers/blockName.js +66 -0
  71. package/lib/helpers/configPropagation.d.ts +12 -2
  72. package/lib/helpers/configPropagation.js +54 -14
  73. package/lib/helpers/corePlugins.d.ts +1 -1
  74. package/lib/helpers/corePlugins.js +4 -2
  75. package/lib/helpers/makeInterator.js +3 -2
  76. package/lib/index.d.ts +13 -3
  77. package/lib/index.js +30 -5
  78. package/lib/pluggableParser.d.ts +6 -2
  79. package/lib/pluggableParser.js +5 -5
  80. package/lib/plugin-data-table.js +4 -5
  81. package/lib/plugin-formatting-codes.js +65 -24
  82. package/lib/plugin-set.js +15 -18
  83. package/lib/plugin-tables.js +6 -1
  84. package/lib/selectors.d.ts +25 -8
  85. package/lib/selectors.js +401 -141
  86. package/lib/set-assign.d.ts +17 -0
  87. package/lib/set-assign.js +150 -0
  88. package/lib/test-display.d.ts +3 -0
  89. package/lib/test-display.js +67 -0
  90. package/lib/toc-caption.d.ts +7 -0
  91. package/lib/toc-caption.js +27 -0
  92. package/lib/types.d.ts +16 -1
  93. package/lib/version.d.ts +1 -1
  94. package/lib/version.js +1 -1
  95. package/package.json +1 -1
  96. package/schema/AstTree.json +160 -0
  97. package/schema/PodliteDocument.json +160 -0
package/lib/guard.js CHANGED
@@ -11,8 +11,9 @@ const config_1 = __importDefault(require("./helpers/config"));
11
11
  // with the node, so whatever pulls the node out cannot strip the cover off it.
12
12
  const GUARD_CODE = 'G';
13
13
  const isGuardCode = (node) => node.type === 'fcode' && node.name === GUARD_CODE;
14
+ // a paragraph or code written without a marker is masked by the settings it was given
14
15
  const isMaskedBlock = (node) => {
15
- if (node.type !== 'block')
16
+ if (node.type !== 'block' && node.type !== 'para' && node.type !== 'code')
16
17
  return false;
17
18
  const conf = (0, config_1.default)(node, {});
18
19
  return conf.exists('masked') && Boolean(conf.getFirstValue('masked'));
@@ -28,6 +29,12 @@ const isCovered = (node, ctx) => {
28
29
  return Boolean(node?.guarded);
29
30
  };
30
31
  exports.isCovered = isCovered;
32
+ const isCaptionNode = (value) => typeof value === 'object' &&
33
+ value !== null &&
34
+ 'type' in value &&
35
+ value.type === 'block' &&
36
+ 'name' in value &&
37
+ value.name === 'caption';
31
38
  const markGuarded = (node, inherited = false) => {
32
39
  if (!node || typeof node !== 'object')
33
40
  return node;
@@ -41,6 +48,9 @@ const markGuarded = (node, inherited = false) => {
41
48
  target.guarded = true;
42
49
  if (Array.isArray(target.content))
43
50
  target.content.forEach(child => (0, exports.markGuarded)(child, covered));
51
+ // a caption parsed from an attribute value sits beside the content, not in it
52
+ if ('caption' in target && isCaptionNode(target.caption))
53
+ (0, exports.markGuarded)(target.caption, covered);
44
54
  return node;
45
55
  };
46
56
  exports.markGuarded = markGuarded;
@@ -0,0 +1,8 @@
1
+ export type Walked = {
2
+ type?: string;
3
+ name?: string;
4
+ content?: unknown;
5
+ };
6
+ export declare const isWrapper: (node: Walked) => boolean;
7
+ export declare const blockNameOf: (node: Walked, holder: Walked | undefined) => string | undefined;
8
+ export declare const holderInside: (node: Walked, holder: Walked | undefined) => Walked | undefined;
@@ -0,0 +1,66 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.holderInside = exports.blockNameOf = exports.isWrapper = void 0;
4
+ /*
5
+ =begin pod :kind<module>
6
+
7
+ =head2 blockName
8
+
9
+ Which node of a tree is a block, and of what name: one rule for the selection,
10
+ the settings of C<=config> and the assignments of C<=set>.
11
+
12
+ =end pod
13
+ */
14
+ const makeTransformer_1 = require("./makeTransformer");
15
+ // Within these blocks text written without a marker is a paragraph and lines
16
+ // set in from the margin are a code block. Anywhere else a para node is the
17
+ // text of the block around it: of an explicit =para, of a heading.
18
+ const IMPLICIT_HOLDERS = new Set(['root', 'pod', 'item', 'defn', 'nested', 'cell']);
19
+ // A node outside any block is in the document, and a document is a pod.
20
+ const holdsImplicit = (holder) => holder === undefined ||
21
+ (holder.type === 'block' &&
22
+ (IMPLICIT_HOLDERS.has(holder.name ?? '') || (Boolean(holder.name) && (0, makeTransformer_1.isSemanticBlock)(holder))));
23
+ // Wrappers the tree adds around written blocks: the document, the blocks of a
24
+ // Markdown section, a heading folded together with its text. No author writes
25
+ // them, so no pattern finds them; the walk goes through.
26
+ const WRAPPERS = new Set(['root', '_folded_section']);
27
+ const isWrapper = (node) => node.type === 'block' && WRAPPERS.has(node.name ?? '');
28
+ exports.isWrapper = isWrapper;
29
+ /*
30
+ =begin pod :kind<export>
31
+
32
+ =head2 blockNameOf
33
+
34
+ The name of the block a node stands for: the name of a block written with a
35
+ directive, C<para> or C<code> for one written without, none for anything else.
36
+ C<holder> is the block whose content holds the node; none means the document.
37
+ A paragraph node is a block only where text without a marker is a paragraph:
38
+ inside an explicit C<=para> or a heading it is that block's own text. The term
39
+ of a C<=defn> is its heading, not a paragraph.
40
+
41
+ =end pod
42
+ */
43
+ const blockNameOf = (node, holder) => {
44
+ if (node.type === 'block')
45
+ return (0, exports.isWrapper)(node) ? undefined : node.name;
46
+ if (node.type === 'code')
47
+ return 'code';
48
+ if (node.type === 'para' && node.name !== 'term' && holdsImplicit(holder))
49
+ return 'para';
50
+ return undefined;
51
+ };
52
+ exports.blockNameOf = blockNameOf;
53
+ /*
54
+ =begin pod :kind<export>
55
+
56
+ =head2 holderInside
57
+
58
+ The holder for the content of C<node>, given the holder of C<node> itself. A
59
+ folded section is a wrapper the tree adds around a heading and its text; the
60
+ text stands where it was written.
61
+
62
+ =end pod
63
+ */
64
+ const holderInside = (node, holder) => node.type === 'block' && node.name === '_folded_section' ? holder : node;
65
+ exports.holderInside = holderInside;
66
+ //# sourceMappingURL=blockName.js.map
@@ -1,3 +1,13 @@
1
- import { PodNode, PodliteDocument } from '../types';
2
- export declare const propagateConfigDefaults: <T extends PodliteDocument | PodNode | unknown[]>(ast: T) => T;
1
+ import { ConfigItem, PodNode, PodliteDocument } from '../types';
2
+ export type ConfigScope = Record<string, ConfigItem[]>;
3
+ export declare const mergeConfigSettings: (nearer: ConfigItem[] | undefined, farther: ConfigItem[] | undefined) => ConfigItem[];
4
+ export type ScopedBlock = {
5
+ type?: string;
6
+ name?: string;
7
+ level?: string | number;
8
+ config?: ConfigItem[];
9
+ content?: unknown;
10
+ };
11
+ export declare const walkConfigScopes: (ast: PodliteDocument | PodNode | unknown[], inherited: ConfigScope, visit: (block: ScopedBlock, scope: ConfigScope) => void) => void;
12
+ export declare const propagateConfigDefaults: <T extends PodliteDocument | PodNode | unknown[]>(ast: T, inherited?: ConfigScope) => T;
3
13
  export default propagateConfigDefaults;
@@ -1,10 +1,20 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.propagateConfigDefaults = void 0;
3
+ exports.propagateConfigDefaults = exports.walkConfigScopes = exports.mergeConfigSettings = void 0;
4
+ const blockName_1 = require("./blockName");
5
+ // the nearer declaration decides an option, the farther one fills in the rest
6
+ const mergeConfigSettings = (nearer, farther) => {
7
+ const near = Array.isArray(nearer) ? nearer : [];
8
+ const far = Array.isArray(farther) ? farther : [];
9
+ const seen = new Set(near.map(c => c && c.name).filter(Boolean));
10
+ const rest = far.filter(c => c && c.name && !seen.has(c.name));
11
+ return rest.length ? [...near, ...rest] : near;
12
+ };
13
+ exports.mergeConfigSettings = mergeConfigSettings;
4
14
  const mergeDefaults = (own, defaults) => {
5
15
  const ownArr = Array.isArray(own) ? own : [];
6
16
  const seen = new Set(ownArr.map(c => c && c.name).filter(Boolean));
7
- const additions = defaults.filter(c => c && c.name && !seen.has(c.name));
17
+ const additions = defaults.filter(c => c && c.name && !seen.has(c.name)).map(c => ({ ...c, from: 'config' }));
8
18
  if (additions.length === 0)
9
19
  return ownArr;
10
20
  return [...ownArr, ...additions];
@@ -22,33 +32,63 @@ const lookupKeys = (node) => {
22
32
  keys.push(node.name);
23
33
  return keys;
24
34
  };
25
- const walk = (node, config) => {
35
+ const walk = (node, config, holder, visit, implicit) => {
26
36
  if (Array.isArray(node)) {
27
37
  for (const child of node)
28
- walk(child, config);
38
+ walk(child, config, holder, visit, implicit);
29
39
  return;
30
40
  }
31
41
  if (!node || typeof node !== 'object')
32
42
  return;
33
43
  const anyNode = node;
34
44
  if (anyNode.type === 'config' && typeof anyNode.name === 'string' && Array.isArray(anyNode.config)) {
35
- config[anyNode.name] = anyNode.config;
45
+ config[anyNode.name] = (0, exports.mergeConfigSettings)(anyNode.config, config[anyNode.name]);
36
46
  }
37
47
  else if (anyNode.type === 'block') {
38
- for (const key of lookupKeys(anyNode)) {
39
- const defaults = config[key];
40
- if (defaults && defaults.length) {
41
- anyNode.config = mergeDefaults(anyNode.config, defaults);
42
- }
43
- }
48
+ visit(anyNode, config);
49
+ }
50
+ else if (implicit) {
51
+ const name = (0, blockName_1.blockNameOf)(anyNode, holder);
52
+ if (name !== undefined)
53
+ implicit(anyNode, name, config);
44
54
  }
45
55
  if (anyNode.content !== undefined) {
46
56
  // a block is a lexical scope: what is declared inside it stays inside
47
- walk(anyNode.content, anyNode.type === 'block' ? { ...config } : config);
57
+ const scope = anyNode.type === 'block' ? { ...config } : config;
58
+ walk(anyNode.content, scope, (0, blockName_1.holderInside)(anyNode, holder), visit, implicit);
48
59
  }
49
60
  };
50
- const propagateConfigDefaults = (ast) => {
51
- walk(ast, {});
61
+ const applyDefaults = (block, config) => {
62
+ for (const key of lookupKeys(block)) {
63
+ const defaults = config[key];
64
+ if (defaults && defaults.length) {
65
+ block.config = mergeDefaults(block.config, defaults);
66
+ }
67
+ }
68
+ };
69
+ const applyImplicitDefaults = (node, name, config) => {
70
+ const defaults = config[name];
71
+ if (defaults && defaults.length)
72
+ node.config = mergeDefaults(node.config, defaults);
73
+ };
74
+ /*
75
+ =begin pod :kind<export>
76
+
77
+ =head2 walkConfigScopes
78
+
79
+ Calls C<visit> for each block of a tree, in document order, with the C<=config>
80
+ settings in effect where the block stands: those handed in as C<inherited> and
81
+ those declared before the block in the blocks around it. A block is a scope: what
82
+ is declared inside it stays inside. The settings object is the walk's own and
83
+ changes as it goes on; a visitor that keeps it copies it. The content a visitor
84
+ gives a block is walked next, as the content of that block.
85
+
86
+ =end pod
87
+ */
88
+ const walkConfigScopes = (ast, inherited, visit) => walk(ast, { ...inherited }, undefined, visit);
89
+ exports.walkConfigScopes = walkConfigScopes;
90
+ const propagateConfigDefaults = (ast, inherited = {}) => {
91
+ walk(ast, { ...inherited }, undefined, applyDefaults, applyImplicitDefaults);
52
92
  return ast;
53
93
  };
54
94
  exports.propagateConfigDefaults = propagateConfigDefaults;
@@ -1,6 +1,6 @@
1
1
  export declare const core: {
2
2
  ':image': {
3
- toHtml: (writer: any) => (node: any) => void;
3
+ toHtml: (writer: any) => (node: any, ctx: any) => void;
4
4
  };
5
5
  image: {
6
6
  toHtml: import("./makeQuery").RuleHandler<any>;
@@ -3,10 +3,12 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.core = void 0;
4
4
  const __1 = require("..");
5
5
  const ast_helpers_1 = require("../ast-helpers");
6
+ const guard_1 = require("../guard");
7
+ const handlers_1 = require("./handlers");
6
8
  const html_attr_1 = require("./html-attr");
7
9
  exports.core = {
8
10
  ':image': {
9
- toHtml: writer => node => {
11
+ toHtml: writer => (node, ctx) => {
10
12
  if (typeof node !== 'string' && 'type' in node && node.type === 'image') {
11
13
  writer.writeRaw(`<img`);
12
14
  writer.writeRaw(` src="${(0, html_attr_1.quoteAttribute)(String(node.src ?? ''))}"`);
@@ -15,7 +17,7 @@ exports.core = {
15
17
  // is left out
16
18
  const alt = (0, ast_helpers_1.writtenValue)(node.alt);
17
19
  if (alt !== undefined) {
18
- writer.writeRaw(` alt="${(0, html_attr_1.quoteAttribute)(alt)}"`);
20
+ writer.writeRaw(` alt="${(0, html_attr_1.quoteAttribute)((0, guard_1.isCovered)(node, ctx) ? (0, handlers_1.maskText)(alt) : alt)}"`);
19
21
  }
20
22
  writer.writeRaw(`/>`);
21
23
  }
@@ -21,8 +21,9 @@ function thisFunc(rules) {
21
21
  }
22
22
  // a block is a lexical scope: a =config or =alias written inside it must not
23
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) {
24
+ // rules count cells and mark rows through it. A folded section is put
25
+ // around written blocks and is no scope of its own
26
+ if (node.type === 'block' && node.name !== '_folded_section' && context) {
26
27
  const outer = { config: context.config, alias: context.alias };
27
28
  const had = { config: context.hasOwnProperty('config'), alias: context.hasOwnProperty('alias') };
28
29
  context.config = { ...outer.config };
package/lib/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { ErrorObject } from 'ajv';
2
- import { ParseDiagnostic, PodNode } from './types';
2
+ import { ParseDiagnostic, PodNode, RecognitionEvent } from './types';
3
3
  export { PodliteDocument } from './types';
4
4
  export { AstTree } from './types';
5
5
  export * from './types';
@@ -20,6 +20,10 @@ export type { LinkConfig } from './helpers/link-config';
20
20
  export { pluginCleanLocation } from './plugin-clean-location';
21
21
  export { toAnyRules } from './helpers/plugins';
22
22
  export { podlitePluggable, Podlite, PodliteExport, cleanIds, frozenIds, headingId } from './pluggableParser';
23
+ import { ConfigScope } from './helpers/configPropagation';
24
+ export { mergeConfigSettings, propagateConfigDefaults, walkConfigScopes } from './helpers/configPropagation';
25
+ export { blockNameOf, holderInside } from './helpers/blockName';
26
+ export type { ConfigScope, ScopedBlock } from './helpers/configPropagation';
23
27
  export declare function toAst(): {};
24
28
  export type SchemaValidationError = ErrorObject<string, Record<string, any>>;
25
29
  export declare function getTextContentFromNode(node: PodNode): string;
@@ -74,6 +78,8 @@ export type parseOpt = {
74
78
  podMode?: number;
75
79
  mode?: 'pod' | 'md';
76
80
  diagnostics?: ParseDiagnostic[];
81
+ recognition?: RecognitionEvent[];
82
+ config?: ConfigScope;
77
83
  };
78
84
  declare function makeTree(): {
79
85
  (): void;
@@ -89,9 +95,13 @@ export declare const parseFormattingCodes: (text: string, options?: {
89
95
  export { default as toHtml } from './exportHtml';
90
96
  export { default as toMarkdown } from './exportMarkdown';
91
97
  export { default as Writer } from './writer';
92
- export { parseSelector, runSelector, filePathMatches } from './selectors';
98
+ export { parseSelector, runSelector, outermost, filePathMatches, getDocIDs, SelectorError } from './selectors';
99
+ export { applySetToFirst, mergeSet, isSetTransparent, isSetTarget } from './set-assign';
100
+ export type { SetOutcome } from './set-assign';
93
101
  export { markGuarded, isCovered } from './guard';
94
102
  export { applyFoldedSections } from './folded-sections';
95
- export type { SelectorDoc, ParsedSelector } from './selectors';
103
+ export { testCaption, testFoldedByAuthor } from './test-display';
104
+ export { tocTitleText } from './toc-caption';
105
+ export type { SelectorDoc, ParsedSelector, SelectorOptions } from './selectors';
96
106
  export { applyImageBase } from './image-base';
97
107
  export { version } from './version';
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.applyFoldedSections = exports.isCovered = exports.markGuarded = exports.filePathMatches = exports.runSelector = exports.parseSelector = exports.Writer = exports.toMarkdown = exports.toHtml = exports.parseFormattingCodes = exports.parse = exports.headingId = exports.frozenIds = exports.cleanIds = exports.podlitePluggable = exports.toAnyRules = exports.pluginCleanLocation = exports.quoteAttribute = exports.readLinkConfig = exports.parseAttributes = exports.codeConfigWithDefaults = exports.makeAttrs = exports.toAny = exports.isSemanticBlock = exports.isNamedBlock = exports.makeTransformer = exports.makeInterator = void 0;
42
+ exports.version = exports.applyImageBase = exports.tocTitleText = exports.testFoldedByAuthor = exports.testCaption = exports.applyFoldedSections = exports.isCovered = exports.markGuarded = exports.isSetTarget = exports.isSetTransparent = exports.mergeSet = exports.applySetToFirst = exports.SelectorError = exports.getDocIDs = exports.filePathMatches = exports.outermost = exports.runSelector = exports.parseSelector = exports.Writer = exports.toMarkdown = exports.toHtml = exports.parseFormattingCodes = exports.parse = 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.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;
@@ -98,6 +98,13 @@ const plugin_group_items_1 = __importDefault(require("./plugin-group-items"));
98
98
  const plugin_defn_fill_term_1 = __importDefault(require("./plugin-defn-fill-term"));
99
99
  const plugin_set_1 = __importDefault(require("./plugin-set"));
100
100
  const configPropagation_1 = require("./helpers/configPropagation");
101
+ var configPropagation_2 = require("./helpers/configPropagation");
102
+ Object.defineProperty(exports, "mergeConfigSettings", { enumerable: true, get: function () { return configPropagation_2.mergeConfigSettings; } });
103
+ Object.defineProperty(exports, "propagateConfigDefaults", { enumerable: true, get: function () { return configPropagation_2.propagateConfigDefaults; } });
104
+ Object.defineProperty(exports, "walkConfigScopes", { enumerable: true, get: function () { return configPropagation_2.walkConfigScopes; } });
105
+ var blockName_1 = require("./helpers/blockName");
106
+ Object.defineProperty(exports, "blockNameOf", { enumerable: true, get: function () { return blockName_1.blockNameOf; } });
107
+ Object.defineProperty(exports, "holderInside", { enumerable: true, get: function () { return blockName_1.holderInside; } });
101
108
  const plugin_tables_1 = __importDefault(require("./plugin-tables"));
102
109
  const plugin_data_table_1 = __importDefault(require("./plugin-data-table"));
103
110
  function toAst() {
@@ -174,17 +181,22 @@ function isValidateError(result, src) {
174
181
  }
175
182
  return undefined;
176
183
  }
177
- const configDefaults_plug = () => tree => (0, configPropagation_1.propagateConfigDefaults)(tree);
184
+ const configDefaults_plug = opt => tree => (0, configPropagation_1.propagateConfigDefaults)(tree, opt.config);
178
185
  function makeTree() {
179
186
  var plugins = [];
180
187
  chain.use = use;
181
188
  chain.parse = parse;
182
189
  chain.use(plugin_vmargin_1.default);
190
+ // the term of a =defn is cut out before =set looks for its target: a term is
191
+ // no target, the definition after it is
192
+ chain.use(plugin_defn_fill_term_1.default);
183
193
  chain.use(plugin_set_1.default);
184
194
  chain.use(plugin_items_1.default);
185
195
  chain.use(plugin_heading_1.default);
186
- chain.use(plugin_defn_fill_term_1.default);
187
196
  chain.use(plugin_tables_1.default);
197
+ // a data table is read by its attributes, so those a =config gives it must be
198
+ // on it by then; the rows it turns into get theirs in the pass below
199
+ chain.use(configDefaults_plug);
188
200
  chain.use(plugin_data_table_1.default);
189
201
  // pre-configured attributes must sit on the blocks before markup codes are
190
202
  // parsed, since :allow decides which of them are read at all
@@ -205,8 +217,8 @@ function makeTree() {
205
217
  return chain;
206
218
  }
207
219
  function parse(src, opt = { skipChain: 0, podMode: 1 }) {
208
- const { skipChain = 0, podMode = 1, diagnostics } = opt;
209
- let tree = parser.parse(src, { podMode, diagnostics, blockNames: block_names_1.BLOCK_NAMES });
220
+ const { skipChain = 0, podMode = 1, diagnostics, recognition } = opt;
221
+ let tree = parser.parse(src, { podMode, diagnostics, recognition, blockNames: block_names_1.BLOCK_NAMES });
210
222
  if (!skipChain) {
211
223
  for (let i = 0; i < plugins.length; i++) {
212
224
  const plugin = plugins[i];
@@ -232,12 +244,25 @@ Object.defineProperty(exports, "Writer", { enumerable: true, get: function () {
232
244
  var selectors_1 = require("./selectors");
233
245
  Object.defineProperty(exports, "parseSelector", { enumerable: true, get: function () { return selectors_1.parseSelector; } });
234
246
  Object.defineProperty(exports, "runSelector", { enumerable: true, get: function () { return selectors_1.runSelector; } });
247
+ Object.defineProperty(exports, "outermost", { enumerable: true, get: function () { return selectors_1.outermost; } });
235
248
  Object.defineProperty(exports, "filePathMatches", { enumerable: true, get: function () { return selectors_1.filePathMatches; } });
249
+ Object.defineProperty(exports, "getDocIDs", { enumerable: true, get: function () { return selectors_1.getDocIDs; } });
250
+ Object.defineProperty(exports, "SelectorError", { enumerable: true, get: function () { return selectors_1.SelectorError; } });
251
+ var set_assign_1 = require("./set-assign");
252
+ Object.defineProperty(exports, "applySetToFirst", { enumerable: true, get: function () { return set_assign_1.applySetToFirst; } });
253
+ Object.defineProperty(exports, "mergeSet", { enumerable: true, get: function () { return set_assign_1.mergeSet; } });
254
+ Object.defineProperty(exports, "isSetTransparent", { enumerable: true, get: function () { return set_assign_1.isSetTransparent; } });
255
+ Object.defineProperty(exports, "isSetTarget", { enumerable: true, get: function () { return set_assign_1.isSetTarget; } });
236
256
  var guard_1 = require("./guard");
237
257
  Object.defineProperty(exports, "markGuarded", { enumerable: true, get: function () { return guard_1.markGuarded; } });
238
258
  Object.defineProperty(exports, "isCovered", { enumerable: true, get: function () { return guard_1.isCovered; } });
239
259
  var folded_sections_1 = require("./folded-sections");
240
260
  Object.defineProperty(exports, "applyFoldedSections", { enumerable: true, get: function () { return folded_sections_1.applyFoldedSections; } });
261
+ var test_display_1 = require("./test-display");
262
+ Object.defineProperty(exports, "testCaption", { enumerable: true, get: function () { return test_display_1.testCaption; } });
263
+ Object.defineProperty(exports, "testFoldedByAuthor", { enumerable: true, get: function () { return test_display_1.testFoldedByAuthor; } });
264
+ var toc_caption_1 = require("./toc-caption");
265
+ Object.defineProperty(exports, "tocTitleText", { enumerable: true, get: function () { return toc_caption_1.tocTitleText; } });
241
266
  var image_base_1 = require("./image-base");
242
267
  Object.defineProperty(exports, "applyImageBase", { enumerable: true, get: function () { return image_base_1.applyImageBase; } });
243
268
  var version_1 = require("./version");
@@ -1,4 +1,5 @@
1
1
  import { Plugins, PodliteDocument, parseOpt } from '.';
2
+ import { ConfigScope } from './helpers/configPropagation';
2
3
  export { cleanIds, frozenIds, headingId } from './helpers/ids';
3
4
  export interface podlitePluggableOpt {
4
5
  plugins?: Plugins;
@@ -12,14 +13,17 @@ export interface PodliteExport {
12
13
  defenitions: any;
13
14
  interator: any;
14
15
  }
16
+ export type ToAstOpt = {
17
+ config?: ConfigScope;
18
+ };
15
19
  export interface Podlite {
16
- toAstResult: (ast: PodliteDocument) => PodliteExport;
20
+ toAstResult: (ast: PodliteDocument, opt?: ToAstOpt) => PodliteExport;
17
21
  (): any;
18
22
  use: (plugin: Plugins) => Podlite;
19
23
  parse: (text: string, opt?: parseOpt) => PodliteDocument;
20
24
  toHtml: (ast: PodliteDocument) => PodliteExport;
21
25
  toMarkdown: (ast: PodliteDocument) => PodliteExport;
22
- toAst: (ast: PodliteDocument) => PodliteDocument;
26
+ toAst: (ast: PodliteDocument, opt?: ToAstOpt) => PodliteDocument;
23
27
  getPlugins: () => Array<Plugins>;
24
28
  }
25
29
  export declare const podlitePluggable: (params?: podlitePluggableOpt) => Podlite;
@@ -46,10 +46,10 @@ const podlitePluggable = ({ plugins = {} } = {}) => {
46
46
  const root = (0, _1.mkRootBlock)({ margin: '' }, rawTree);
47
47
  return diagnostics.length ? { ...root, diagnostics } : root;
48
48
  };
49
- instance.toAst = ast => {
50
- return instance.toAstResult(ast).interator;
49
+ instance.toAst = (ast, opt) => {
50
+ return instance.toAstResult(ast, opt).interator;
51
51
  };
52
- instance.toAstResult = ast => {
52
+ instance.toAstResult = (ast, opt = {}) => {
53
53
  // get plugins for Ast
54
54
  const toAstPlugins = (0, _1.toAnyRules)('toAst', instance.getPlugins());
55
55
  const result = (0, _1.toAny)()
@@ -78,7 +78,7 @@ const podlitePluggable = ({ plugins = {} } = {}) => {
78
78
  .use(toAstAfterPlugins)
79
79
  .run(ast);
80
80
  if (resultAfter && resultAfter.interator) {
81
- (0, configPropagation_1.propagateConfigDefaults)(resultAfter.interator);
81
+ (0, configPropagation_1.propagateConfigDefaults)(resultAfter.interator, opt.config);
82
82
  (0, itemNumbering_1.promoteOrderedLists)(resultAfter.interator);
83
83
  (0, headingNumbering_1.attachHeadingNumberPrefix)(resultAfter.interator);
84
84
  (0, guard_1.markGuarded)(resultAfter.interator);
@@ -87,7 +87,7 @@ const podlitePluggable = ({ plugins = {} } = {}) => {
87
87
  return resultAfter;
88
88
  }
89
89
  if (result && result.interator) {
90
- (0, configPropagation_1.propagateConfigDefaults)(result.interator);
90
+ (0, configPropagation_1.propagateConfigDefaults)(result.interator, opt.config);
91
91
  (0, itemNumbering_1.promoteOrderedLists)(result.interator);
92
92
  (0, headingNumbering_1.attachHeadingNumberPrefix)(result.interator);
93
93
  (0, guard_1.markGuarded)(result.interator);
@@ -95,10 +95,9 @@ function processDataTable(node, tree, report) {
95
95
  report('table-source-unreadable', `no =data block found for data:${target}, table rendered as empty`, node);
96
96
  return { ...node, name: 'table', content: [] };
97
97
  }
98
- if (mimeAttr) {
99
- throw new Error(`:mime-type cannot be declared with :src<data:${target}> (inherited from referenced block)`);
100
- }
101
- const dataMime = (0, config_1.default)(dataBlock, {}).getFirstValue('mime-type');
98
+ // the format of the referenced block yields only to one written on the table itself
99
+ const own = (Array.isArray(node.config) ? node.config : []).find(c => c && c.name === 'mime-type');
100
+ const dataMime = own && own.from === undefined ? mimeAttr : (0, config_1.default)(dataBlock, {}).getFirstValue('mime-type');
102
101
  if (!dataMime) {
103
102
  report('table-source-unreadable', `=data block ${target} has no :mime-type, table rendered as empty`, node);
104
103
  return { ...node, name: 'table', content: [] };
@@ -129,7 +128,7 @@ function processDataTable(node, tree, report) {
129
128
  }
130
129
  let rows = isCsv ? (0, plugin_tables_1.parseCsv)(csvText) : (0, plugin_tables_1.parseTsv)(csvText);
131
130
  if (rows.length === 0) {
132
- report('table-source-unreadable', `${isCsv ? 'CSV' : 'TSV'} source has no rows, table rendered as empty`, node);
131
+ report('table-source-empty', `${isCsv ? 'CSV' : 'TSV'} source has no rows, table rendered as empty`, node);
133
132
  return { ...node, name: 'table', content: [] };
134
133
  }
135
134
  if (columns) {
@@ -41,45 +41,66 @@ 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
43
  const parseAttributes_1 = require("./helpers/parseAttributes");
44
+ const blockName_1 = require("./helpers/blockName");
44
45
  // `=config C<> :allow<I>` names a markup code, not a block: the trailing angles
45
46
  // are the marker, and what it declares belongs to the code they name
46
47
  const codeConfigOwner = (name) => typeof name === 'string' && /^[A-Z]<>$/.test(name) ? name[0] : null;
47
- const collectAllowedIn = (content, inherited) => {
48
- if (!Array.isArray(content))
49
- return inherited;
50
- let map = inherited;
51
- for (const child of content) {
52
- if (!child || typeof child !== 'object')
53
- continue;
54
- const node = child;
55
- if (node.type !== 'config')
56
- continue;
57
- const owner = codeConfigOwner(node.name);
58
- if (!owner)
59
- continue;
60
- if (map === inherited)
61
- map = { ...inherited };
62
- map[owner] = (0, config_1.default)(node, {}).getAllValues('allow');
63
- }
64
- return map;
48
+ // a declaration acts from where it is written, and one without :allow leaves
49
+ // the codes an earlier declaration allowed
50
+ const declareAllowedIn = (node, scope) => {
51
+ if (!node || typeof node !== 'object')
52
+ return;
53
+ const owner = codeConfigOwner('name' in node ? node.name : undefined);
54
+ if (!owner)
55
+ return;
56
+ const conf = (0, config_1.default)(node, {});
57
+ if (conf.exists('allow'))
58
+ scope[owner] = conf.getAllValues('allow');
59
+ };
60
+ const inheritedAllowedIn = (config = {}) => {
61
+ const scope = {};
62
+ for (const name of Object.keys(config))
63
+ declareAllowedIn({ name, config: config[name] }, scope);
64
+ return scope;
65
65
  };
66
- const middle = () => tree => {
66
+ // the codes a paragraph or code written without a marker allows: those =config
67
+ // or =set gave it, none declared means the default of its block type
68
+ const allowOf = (node) => {
69
+ const conf = (0, config_1.default)(node, {});
70
+ return conf.exists('allow') ? conf.getAllValues('allow') : undefined;
71
+ };
72
+ const middle = opt => tree => {
67
73
  const transformerBlocks = (0, makeTransformer_1.default)({
68
74
  ':para': (n, ctx, visiter) => {
69
75
  const allowedIn = ctx.allowedIn;
76
+ const allowed = allowOf(n);
70
77
  return (0, makeTransformer_1.default)({
71
78
  ':text': (n, ctx) => {
72
- return fcparser.parse(n.value, { allowedIn, parseAttributes: parseAttributes_1.parseAttributes });
79
+ return fcparser.parse(n.value, { allowed, allowedIn, parseAttributes: parseAttributes_1.parseAttributes });
73
80
  },
74
81
  ':verbatim': (n, ctx) => {
75
- return fcparser.parse(n.value, { allowedIn, parseAttributes: parseAttributes_1.parseAttributes });
82
+ return fcparser.parse(n.value, { allowed, allowedIn, parseAttributes: parseAttributes_1.parseAttributes });
76
83
  },
77
84
  })(n, { ...ctx });
78
85
  return n;
79
86
  },
87
+ // code is verbatim unless :allow names the codes read in it
88
+ ':code': (n, ctx) => {
89
+ const allowed = allowOf(n) || [];
90
+ if (allowed.length === 0)
91
+ return n;
92
+ const allowedIn = ctx.allowedIn;
93
+ return (0, makeTransformer_1.default)({
94
+ ':verbatim': (node) => fcparser.parse(node.value, { allowed, allowedIn, parseAttributes: parseAttributes_1.parseAttributes }),
95
+ })(n, { ...ctx });
96
+ },
97
+ ':config': (n, ctx) => {
98
+ declareAllowedIn(n, ctx.allowedIn);
99
+ return n;
100
+ },
80
101
  ':block': (n, ctx, visiter) => {
81
102
  // a block is a lexical scope: a code configured inside it stays inside
82
- const allowedIn = collectAllowedIn('content' in n ? n.content : undefined, ctx.allowedIn || {});
103
+ const allowedIn = { ...(ctx.allowedIn || {}) };
83
104
  // only =pod may have childs blocks
84
105
  if ('name' in n && n.name === 'pod')
85
106
  return {
@@ -90,9 +111,15 @@ const middle = () => tree => {
90
111
  const name = 'name' in n ? n.name : '';
91
112
  // Blocks whose content is verbatim by default — fcode parsing only
92
113
  // kicks in when :allow opts in (per spec, "Formatting within code blocks").
93
- const isVerbatimDefault = ['code', 'data', 'markdown', 'picture', 'formula'].includes(name);
114
+ const isVerbatimDefault = ['code', 'data', 'picture', 'formula', 'assert', 'resource'].includes(name);
94
115
  if ((0, makeTransformer_2.isNamedBlock)(name))
95
116
  return n;
117
+ // a fixture body is a document of its own, so :allow does not reach it
118
+ if (name === 'fixture')
119
+ return n;
120
+ // a markdown body is Markdown whatever :allow says
121
+ if (name === 'markdown')
122
+ return n;
96
123
  // A table owns rows, and the text sits in the cells, so :allow written on
97
124
  // the table reaches them. The nearest declaration wins: cell, row, table.
98
125
  const inheritsAllow = name === 'row' || name === 'cell';
@@ -110,16 +137,30 @@ const middle = () => tree => {
110
137
  const literal = inheritsAllow && declared !== undefined && declared.length === 0;
111
138
  const allowed = [...allowValues].sort();
112
139
  const inner = { ...ctx, allowedIn, allowFromTable: passesAllow };
140
+ // code written without a marker is verbatim unless its own :allow names codes
141
+ const ownCode = (node, ctx) => transformerBlocks(node, { ...ctx, allowedIn });
142
+ // a paragraph written without a marker reads codes as an explicit =para does;
143
+ // the own text of a block, a term among them, and the text of a cell read the
144
+ // codes of the block they belong to
145
+ const ownPara = (node, ctx) => (0, blockName_1.blockNameOf)(node, n) !== 'para' || (inheritsAllow && allowOf(node) === undefined)
146
+ ? { ...node, content: transformer(node.content, ctx) }
147
+ : transformerBlocks(node, { ...ctx, allowedIn });
113
148
  const transformer = (0, makeTransformer_1.default)({
114
149
  ':verbatim': (node, ctx) => literal ? node : fcparser.parse(node.value, { allowed, allowedIn, parseAttributes: parseAttributes_1.parseAttributes }),
115
150
  ':text': (node, ctx) => literal ? node : fcparser.parse(node.value, { allowed, allowedIn, parseAttributes: parseAttributes_1.parseAttributes }),
151
+ ':para': ownPara,
152
+ ':code': ownCode,
153
+ ':config': (node, ctx) => {
154
+ declareAllowedIn(node, allowedIn);
155
+ return node;
156
+ },
116
157
  ':block': (node, ctx) => transformerBlocks(node, { ...ctx, allowedIn, allowFromTable: passesAllow }),
117
158
  });
118
159
  return { ...n, content: transformer(n.content, inner) };
119
160
  },
120
161
  });
121
162
  // a document needs no enclosing block, so the top level is a scope of its own
122
- return transformerBlocks(tree, { allowedIn: collectAllowedIn(tree, {}) });
163
+ return transformerBlocks(tree, { allowedIn: inheritedAllowedIn(opt.config) });
123
164
  };
124
165
  exports.default = middle;
125
166
  //# sourceMappingURL=plugin-formatting-codes.js.map