@podlite/schema 0.0.11 → 0.0.13

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 (70) hide show
  1. package/CHANGELOG.md +36 -4
  2. package/LICENSE +1 -1
  3. package/README.md +40 -0
  4. package/lib/ast-helpers.d.ts +1 -1
  5. package/lib/ast-helpers.js +2 -1
  6. package/lib/ast-inerator.d.ts +0 -1
  7. package/lib/ast-inerator.js +7 -15
  8. package/lib/blocks-helpers.d.ts +1 -1
  9. package/lib/blocks-helpers.js +15 -12
  10. package/lib/exportAny.d.ts +19 -0
  11. package/lib/exportAny.js +72 -0
  12. package/lib/exportHtml.d.ts +15 -0
  13. package/lib/exportHtml.js +284 -0
  14. package/lib/grammar.d.ts +14 -0
  15. package/lib/grammar.js +6396 -0
  16. package/lib/grammarfc.d.ts +14 -0
  17. package/lib/grammarfc.js +3363 -0
  18. package/lib/helpers/config.d.ts +12 -0
  19. package/lib/helpers/config.js +56 -0
  20. package/lib/helpers/corePlugins.d.ts +12 -0
  21. package/lib/helpers/corePlugins.js +26 -0
  22. package/lib/helpers/handlers.d.ts +47 -0
  23. package/lib/helpers/handlers.js +120 -0
  24. package/lib/helpers/ids.d.ts +18 -0
  25. package/lib/helpers/ids.js +74 -0
  26. package/lib/helpers/makeInterator.d.ts +5 -0
  27. package/lib/helpers/makeInterator.js +54 -0
  28. package/lib/helpers/makeQuery.d.ts +47 -0
  29. package/lib/helpers/makeQuery.js +107 -0
  30. package/lib/helpers/makeQuery.test.d.ts +1 -0
  31. package/lib/helpers/makeQuery.test.js +51 -0
  32. package/lib/helpers/makeTransformer.d.ts +7 -0
  33. package/lib/helpers/makeTransformer.js +67 -0
  34. package/lib/helpers/plugins.d.ts +2 -0
  35. package/lib/helpers/plugins.js +27 -0
  36. package/lib/index.d.ts +64 -0
  37. package/lib/index.js +85 -5
  38. package/lib/pluggableParser.d.ts +27 -0
  39. package/lib/pluggableParser.js +80 -0
  40. package/lib/plugin-clean-location.d.ts +2 -0
  41. package/lib/plugin-clean-location.js +26 -0
  42. package/lib/plugin-defn-fill-term.d.ts +2 -0
  43. package/lib/plugin-defn-fill-term.js +55 -0
  44. package/lib/plugin-formatting-codes.d.ts +3 -0
  45. package/lib/plugin-formatting-codes.js +76 -0
  46. package/lib/plugin-group-defn.d.ts +2 -0
  47. package/lib/plugin-group-defn.js +73 -0
  48. package/lib/plugin-group-items.d.ts +2 -0
  49. package/lib/plugin-group-items.js +84 -0
  50. package/lib/plugin-heading.d.ts +2 -0
  51. package/lib/plugin-heading.js +35 -0
  52. package/lib/plugin-items.d.ts +2 -0
  53. package/lib/plugin-items.js +43 -0
  54. package/lib/plugin-tables.d.ts +5 -0
  55. package/lib/plugin-tables.js +146 -0
  56. package/lib/plugin-vmargin.d.ts +3 -0
  57. package/lib/plugin-vmargin.js +31 -0
  58. package/lib/query-helpers.d.ts +2 -1
  59. package/lib/query-helpers.js +10 -10
  60. package/lib/types.d.ts +69 -69
  61. package/lib/types.js +1 -0
  62. package/lib/writer.d.ts +30 -0
  63. package/lib/writer.js +106 -0
  64. package/lib/writerHtml.d.ts +11 -0
  65. package/lib/writerHtml.js +34 -0
  66. package/package.json +18 -10
  67. package/schema/index.d.ts +3 -3
  68. package/index.js +0 -2
  69. package/lib/helpers.d.ts +0 -1
  70. package/lib/helpers.js +0 -5
@@ -0,0 +1,84 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ const config_1 = __importDefault(require("./helpers/config"));
7
+ exports.default = () => tree => {
8
+ const isNodesEqual = (n1, n2) =>
9
+ // if nodes items
10
+ (n1.name === 'item' || n1.name === 'defn') &&
11
+ n2.name === n1.name &&
12
+ n1['level'] === n2.level &&
13
+ isNumbered(n1) === isNumbered(n2);
14
+ const isNumbered = node => Boolean((0, config_1.default)(node, {}).exists('numbered'));
15
+ const group = (a, level = 1) => {
16
+ const isInListMode = a => {
17
+ return a.length > 0 && a[a.length - 1].type === 'list';
18
+ };
19
+ const getList = a => {
20
+ if (isInListMode(a))
21
+ return a[a.length - 1];
22
+ };
23
+ const isInsertableToList = (l, i) => (i.name && i.name === 'item' && i.type && i.type === 'block') || i.type === 'blankline';
24
+ let lastItem = {};
25
+ let result = a.reduce((a, i) => {
26
+ // skip items out of level
27
+ if (i.name === 'item' && i.type === 'block' && i.level < level) {
28
+ return [...a, i];
29
+ }
30
+ if (i.name === 'item' &&
31
+ i.type === 'block' &&
32
+ (!isInListMode(a) ||
33
+ // different type of list and item
34
+ // at the same level
35
+ (i.level === level && getList(a).list !== (isNumbered(i) ? 'ordered' : 'itemized')))) {
36
+ // create empty list
37
+ // list = ['ordered', 'variable', 'itemized']
38
+ a.push({
39
+ type: 'list',
40
+ level: i.level,
41
+ content: [],
42
+ list: isNumbered(i) ? 'ordered' : 'itemized',
43
+ });
44
+ }
45
+ // main logic
46
+ if (isInListMode(a) && isInsertableToList(getList(a), i)) {
47
+ // getlist and push item to them
48
+ getList(a).content.push(i);
49
+ }
50
+ else {
51
+ a.push(i);
52
+ }
53
+ return a;
54
+ }, []);
55
+ // convert grouped items into object 'itemlist'
56
+ /**
57
+ * { type = 'list',
58
+ * ordered = [true, false]
59
+ * content = [ .... ]
60
+ * list = ['ordered', 'variable', 'itemized']
61
+ */
62
+ return result.map(item => {
63
+ // process any item with content ( except formatting codes)
64
+ if (item.content && item.type !== 'fcode') {
65
+ item.content = group(item.content, item.level + 1);
66
+ }
67
+ return item;
68
+ });
69
+ };
70
+ const visit = node => {
71
+ if (Array.isArray(node)) {
72
+ node = group(node);
73
+ }
74
+ else {
75
+ if (node.type === 'block' && node.name !== 'table') {
76
+ node.content = group(node.content);
77
+ }
78
+ }
79
+ return node;
80
+ };
81
+ tree = visit(tree);
82
+ return tree;
83
+ };
84
+ //# sourceMappingURL=plugin-group-items.js.map
@@ -0,0 +1,2 @@
1
+ declare const _default: () => (tree: any) => any;
2
+ export default _default;
@@ -0,0 +1,35 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.default = () => tree => {
4
+ const visit = node => {
5
+ if (Array.isArray(node)) {
6
+ node.forEach(i => {
7
+ visit(i);
8
+ });
9
+ }
10
+ else {
11
+ if (node && node.type === 'block') {
12
+ const matchHead = /^head(\d+)?/.exec(node.name);
13
+ if (matchHead) {
14
+ node.name = 'head';
15
+ node.level = matchHead[1] || 1;
16
+ if (node.content[0]) {
17
+ const startText = node.content[0];
18
+ if (startText.text) {
19
+ let re = /(\s*#\s*)/;
20
+ const match = re.exec(startText.text);
21
+ if (match) {
22
+ startText.text = startText.text.replace(re, '');
23
+ node.config = { ...node.config, ...{ numbered: true } };
24
+ }
25
+ }
26
+ }
27
+ }
28
+ visit(node.content);
29
+ }
30
+ }
31
+ };
32
+ visit(tree);
33
+ return tree;
34
+ };
35
+ //# sourceMappingURL=plugin-heading.js.map
@@ -0,0 +1,2 @@
1
+ declare const _default: () => (tree: any) => any;
2
+ export default _default;
@@ -0,0 +1,43 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.default = () => tree => {
4
+ const visit = node => {
5
+ if (Array.isArray(node)) {
6
+ node.forEach(i => {
7
+ visit(i);
8
+ });
9
+ }
10
+ else {
11
+ if (node && node.type === 'block') {
12
+ const matchItem = /^item(\d+)?/.exec(node.name);
13
+ if (matchItem) {
14
+ node.name = 'item';
15
+ node.level = matchItem[1] || 1;
16
+ if (node.content[0]) {
17
+ const startText = node.content[0];
18
+ if (startText.text) {
19
+ let re = /^(\s*#\s*)/;
20
+ const match = re.exec(startText.text);
21
+ if (match) {
22
+ startText.text = startText.text.replace(re, '');
23
+ if (startText.type === 'para') {
24
+ startText.content = [startText.text];
25
+ }
26
+ node.config = node.config || [];
27
+ node.config.push({
28
+ name: 'numbered',
29
+ value: true,
30
+ type: 'boolean',
31
+ });
32
+ }
33
+ }
34
+ }
35
+ }
36
+ visit(node.content);
37
+ }
38
+ }
39
+ };
40
+ visit(tree);
41
+ return tree;
42
+ };
43
+ //# sourceMappingURL=plugin-items.js.map
@@ -0,0 +1,5 @@
1
+ declare const _default: () => (tree: any) => any;
2
+ /**
3
+ * Main transforms
4
+ */
5
+ export default _default;
@@ -0,0 +1,146 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ /**
7
+ * Plugin for fill term's for defn. From S26:
8
+ * The first non-blank line of content is treated as a term being defined,
9
+ * and the remaining content is treated as the definition for the term.
10
+ */
11
+ const makeTransformer_1 = __importDefault(require("./helpers/makeTransformer"));
12
+ function flattenDeep(arr) {
13
+ return arr.reduce((acc, val) => (Array.isArray(val) ? acc.concat(flattenDeep(val)) : acc.concat(val)), []);
14
+ }
15
+ /**
16
+ * Helpers section
17
+ */
18
+ // run cb in symbols pair
19
+ const strbin = (str1, str2, cb) => {
20
+ let res = [];
21
+ for (let i = 0; str1.length > i; i++) {
22
+ res.push(cb(parseInt(str1[i], 10), parseInt(str2[i], 10)));
23
+ }
24
+ return res.join('');
25
+ };
26
+ // Create mask for extract columns
27
+ const makeMask = (lines, separators) => {
28
+ // calculate template length
29
+ const tmplLength = Math.max(...[...lines, ...separators].map(s => s.length));
30
+ // make bin mask for each string
31
+ const masks = lines.map(str => {
32
+ /** make mask for each line
33
+ ' The Shoveller | Eddie Stevens | King Arthur\'s singing shovel',
34
+ '0000000011111111111110001111111111111000001111111111111111111111111111' ]
35
+ then not(mask) ... then & masks
36
+ */
37
+ // enlarge string to tmplLength
38
+ let tstr = str + ' '.repeat(tmplLength - str.length);
39
+ let mask = [];
40
+ const re = /\s+[+|\s]\s/g;
41
+ let match;
42
+ while ((match = re.exec(tstr)) != null) {
43
+ const tmpMask = '1'.repeat(match.index) + '0'.repeat(match[0].length);
44
+ mask.push(tmpMask + '1'.repeat(tmplLength - tmpMask.length));
45
+ }
46
+ return mask.reduce((a, b) => {
47
+ return strbin(a, b, (i1, i2) => i1 & i2);
48
+ }, '1'.repeat(tmplLength));
49
+ });
50
+ // make result mask
51
+ const inverted = masks.map(m => strbin(m, '', i1 => (i1 == 0 ? 1 : 0)));
52
+ const columnTemplate = inverted.reduce((a, b) => {
53
+ return strbin(a, b, (i1, i2) => i1 & i2);
54
+ }, '1'.repeat(tmplLength));
55
+ return columnTemplate;
56
+ };
57
+ const extractColumnsByTemplate = (text, template) => {
58
+ const lines = flattenDeep(text
59
+ .split(/\n/) // split each row by eol
60
+ .filter(str => str.length > 0));
61
+ const cols = lines.map(line => {
62
+ const re = /((1+|0+))/g;
63
+ let columns = [];
64
+ let match;
65
+ while ((match = re.exec(template)) != null) {
66
+ if (match[0][0] == 1)
67
+ continue;
68
+ const s = line.substring(match.index, match.index + match[0].length);
69
+ columns.push(s);
70
+ }
71
+ return columns;
72
+ });
73
+ let result = [];
74
+ result = cols.reduce((a, b) => {
75
+ for (let i = 0; i < b.length; i++) {
76
+ a[i] = (a[i] === undefined ? '' : a[i]) + ' ' + b[i];
77
+ }
78
+ return a;
79
+ }, []);
80
+ return result;
81
+ };
82
+ /**
83
+ * Main transforms
84
+ */
85
+ exports.default = () => tree => {
86
+ const transformer = (0, makeTransformer_1.default)({
87
+ table: node => {
88
+ let rows = [];
89
+ const collectValues = row => {
90
+ rows.push(row.value);
91
+ };
92
+ // collect separators for calculate max length of rows
93
+ let seps = [];
94
+ (0, makeTransformer_1.default)({
95
+ 'row:text': collectValues,
96
+ 'head:text': collectValues,
97
+ ':separator': sep => {
98
+ seps.push(sep.text);
99
+ },
100
+ })(node);
101
+ // add table-caption
102
+ // if table empty return node as is
103
+ if (!rows.length)
104
+ return node;
105
+ const splitToLines = row => row
106
+ .split(/\n/) // split each row by eol
107
+ .filter(str => str.length > 0); // filter empty strings ( after slit )
108
+ // split each row into lines
109
+ const lines = flattenDeep(rows.map(splitToLines));
110
+ const separators = flattenDeep(seps.map(splitToLines));
111
+ // collect text rows
112
+ let textRows = [];
113
+ (0, makeTransformer_1.default)({
114
+ 'row:text': row => {
115
+ textRows.push(row.value);
116
+ },
117
+ })(node);
118
+ const columnTemplate = makeMask(lines, separators);
119
+ const makeBlock = (name, content, ...attr) => {
120
+ return { ...attr, name, type: 'block', content: Array.isArray(content) ? content : [content] };
121
+ };
122
+ // make columns
123
+ const res = (0, makeTransformer_1.default)({
124
+ 'row:text': row => {
125
+ if (textRows.length == 1) {
126
+ // split each text row into lines
127
+ const textRowsLines = flattenDeep([row.value].map(splitToLines));
128
+ return textRowsLines.map(rowValue => {
129
+ const res = extractColumnsByTemplate(rowValue, columnTemplate);
130
+ return makeBlock('table_row', res.map(col => makeBlock('table_cell', { type: 'text', value: col })));
131
+ });
132
+ }
133
+ const res = extractColumnsByTemplate(row.value, columnTemplate);
134
+ return makeBlock('table_row', res.map(col => makeBlock('table_cell', { type: 'text', value: col })));
135
+ },
136
+ 'head:text': head => {
137
+ const res = extractColumnsByTemplate(head.value, columnTemplate);
138
+ return makeBlock('table_head', res.map(col => makeBlock('table_cell', { type: 'text', value: col })));
139
+ },
140
+ })(node);
141
+ return res;
142
+ },
143
+ });
144
+ return transformer(tree, {});
145
+ };
146
+ //# sourceMappingURL=plugin-tables.js.map
@@ -0,0 +1,3 @@
1
+ import { ParserPlugin } from './';
2
+ declare const middle: ParserPlugin;
3
+ export default middle;
@@ -0,0 +1,31 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const middle = () => tree => {
4
+ const visit_node = (node, context = {}) => {
5
+ // if( (node.type || "").match(/(code|text)/) ) {
6
+ if (node.type == 'code' || node.type == 'text') {
7
+ if (node.margin && context.margin && context.margin.length > 0 && context.margin.length == node.margin.length) {
8
+ ;
9
+ node.type = 'para';
10
+ }
11
+ if (node.type === 'code') {
12
+ // remove parent margin
13
+ var regex = new RegExp(`^[ \t]{0,${node.margin.length}}`, 'gm');
14
+ node.text = node.text.replace(regex, '');
15
+ }
16
+ }
17
+ if (node.type === 'block') {
18
+ context.margin = typeof node.margin !== 'string' ? '' : node.margin;
19
+ let newctx = { ...context };
20
+ newctx.nest = (newctx.nest || 0) + 1;
21
+ node.content.map(n => {
22
+ visit_node(n, context);
23
+ });
24
+ }
25
+ };
26
+ var ctx = {};
27
+ tree.forEach(n => visit_node(n, ctx));
28
+ return tree;
29
+ };
30
+ exports.default = middle;
31
+ //# sourceMappingURL=plugin-vmargin.js.map
@@ -1,3 +1,4 @@
1
+ import { PodNode } from './types';
1
2
  declare type Query = ((par: Object) => Boolean) | any;
2
3
  /**
3
4
  * compileQuery - compile a query to a function
@@ -23,5 +24,5 @@ export declare const compileQuery: (...obj: Query[]) => (any: any) => any;
23
24
  * @param queries
24
25
  * @returns array of matched nodes
25
26
  */
26
- export declare const getFromTree: (tree: any, ...queries: string[] | any) => any;
27
+ export declare const getFromTree: (tree: any, ...queries: string[] | any) => PodNode[];
27
28
  export {};
@@ -1,10 +1,7 @@
1
1
  "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
2
  Object.defineProperty(exports, "__esModule", { value: true });
6
3
  exports.getFromTree = exports.compileQuery = void 0;
7
- const makeTransformer_1 = __importDefault(require("pod6/built/helpers/makeTransformer"));
4
+ const _1 = require("./");
8
5
  /**
9
6
  * compileQuery - compile a query to a function
10
7
 
@@ -34,7 +31,7 @@ const compileQuery = (...obj) => {
34
31
  }
35
32
  else {
36
33
  // obj should accomplished if some queries is true
37
- if (compiledQueries.some((fn) => fn(item).length > 0)) {
34
+ if (compiledQueries.some(fn => fn(item).length > 0)) {
38
35
  result.push(item);
39
36
  }
40
37
  }
@@ -46,7 +43,7 @@ exports.compileQuery = compileQuery;
46
43
  const compileAtomQuery = (obj) => {
47
44
  const queries = [];
48
45
  if (obj instanceof Array) {
49
- throw new Error("Wrong query parameter [Array], should be [Function] or [Object]");
46
+ throw new Error('Wrong query parameter [Array], should be [Function] or [Object]');
50
47
  }
51
48
  else if (typeof obj === 'function') {
52
49
  queries.push(obj);
@@ -54,7 +51,7 @@ const compileAtomQuery = (obj) => {
54
51
  else {
55
52
  for (const entry of Object.entries(obj)) {
56
53
  const [key, value] = entry;
57
- const checkValue = (val) => {
54
+ const checkValue = val => {
58
55
  if (value instanceof Array) {
59
56
  return value.includes(val);
60
57
  }
@@ -84,7 +81,7 @@ const compileAtomQuery = (obj) => {
84
81
  result.push(...AND(item));
85
82
  }
86
83
  // obj should accomplished if all queries to be true
87
- if (queries.every((fn) => fn(item))) {
84
+ if (queries.every(fn => fn(item))) {
88
85
  result.push(item);
89
86
  }
90
87
  });
@@ -103,12 +100,14 @@ const getFromTree = (tree, ...queries) => {
103
100
  }
104
101
  let results = [];
105
102
  let rules = {};
106
- const transformer = (0, makeTransformer_1.default)({ '*:*': (node, ctx) => {
103
+ const transformer = (0, _1.makeTransformer)({
104
+ '*:*': (node, ctx) => {
107
105
  results.push(node);
108
106
  if ('content' in node) {
109
107
  return { node, content: transformer(node.content, { ...ctx }) };
110
108
  }
111
- } });
109
+ },
110
+ });
112
111
  transformer(tree, {});
113
112
  //convert queries
114
113
  const queryAtoms = [];
@@ -134,3 +133,4 @@ const getFromTree = (tree, ...queries) => {
134
133
  return (0, exports.compileQuery)(...queryAtoms)(results);
135
134
  };
136
135
  exports.getFromTree = getFromTree;
136
+ //# sourceMappingURL=query-helpers.js.map