@canopycanopycanopy/b-ber-grammar-renderer 3.0.8-nav.0 → 3.0.8-next.96
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/README.md +15 -4
- package/dist/index.d.ts +21 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +61 -76
- package/package.json +15 -19
package/README.md
CHANGED
|
@@ -1,9 +1,20 @@
|
|
|
1
|
-
#
|
|
1
|
+
# b-ber-grammar-renderer
|
|
2
2
|
|
|
3
|
-
The
|
|
3
|
+
The shared MarkdownIt container renderer factory used by block-level grammar packages. Exports a single `createRenderer` function that takes a `render` function, `markerOpen` and `markerClose` regexes, and a `context` object, and returns a MarkdownIt container plugin configuration object with `marker`, `minMarkers`, `markerOpen`, `markerClose`, and a `validateOpen` method. The `validateOpen` method enforces that every opening directive has a unique `id`, tracks open directive ids in global state (`state.cursor`), and validates that exit directives match a previously opened directive. Packages that need custom close-time behaviour (e.g. `b-ber-grammar-pullquote`) do not use this factory and implement their own renderer.
|
|
4
4
|
|
|
5
|
-
##
|
|
5
|
+
## Usage
|
|
6
6
|
|
|
7
|
+
Imported by `b-ber-grammar-dialogue`, `b-ber-grammar-gallery`, `b-ber-grammar-section`, and `b-ber-grammar-spread`:
|
|
8
|
+
|
|
9
|
+
```js
|
|
10
|
+
import createRenderer from '@canopycanopycanopy/b-ber-grammar-renderer'
|
|
11
|
+
// Returns a MarkdownIt container plugin config object
|
|
7
12
|
```
|
|
8
|
-
|
|
13
|
+
|
|
14
|
+
## Dev
|
|
15
|
+
|
|
9
16
|
```
|
|
17
|
+
npm test
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
Tests are in `__tests__/index.test.js`.
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
//#region src/index.d.ts
|
|
2
|
+
declare const renderer: ({
|
|
3
|
+
context,
|
|
4
|
+
render,
|
|
5
|
+
markerOpen,
|
|
6
|
+
markerClose
|
|
7
|
+
}: {
|
|
8
|
+
context?: {} | undefined;
|
|
9
|
+
render: any;
|
|
10
|
+
markerOpen: any;
|
|
11
|
+
markerClose: any;
|
|
12
|
+
}) => {
|
|
13
|
+
render: any;
|
|
14
|
+
marker: string;
|
|
15
|
+
minMarkers: number;
|
|
16
|
+
markerOpen: any;
|
|
17
|
+
markerClose: any;
|
|
18
|
+
validateOpen(params: any, line: any): boolean | undefined;
|
|
19
|
+
};
|
|
20
|
+
export = renderer;
|
|
21
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","names":[],"sources":["../src/index.ts"],"mappings":";cAWM,QAAA;EAAY,OAAA;EAAA,MAAA;EAAA,UAAA;EAAA;AAAA"}
|
package/dist/index.js
CHANGED
|
@@ -1,77 +1,62 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
var
|
|
4
|
-
var
|
|
5
|
-
|
|
6
|
-
|
|
1
|
+
//#region \0rolldown/runtime.js
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __copyProps = (to, from, except, desc) => {
|
|
9
|
+
if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
|
|
10
|
+
key = keys[i];
|
|
11
|
+
if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
|
|
12
|
+
get: ((k) => from[k]).bind(null, key),
|
|
13
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
|
|
19
|
+
value: mod,
|
|
20
|
+
enumerable: true
|
|
21
|
+
}) : target, mod));
|
|
22
|
+
//#endregion
|
|
23
|
+
let _canopycanopycanopy_b_ber_lib = require("@canopycanopycanopy/b-ber-lib");
|
|
24
|
+
let _canopycanopycanopy_b_ber_logger = require("@canopycanopycanopy/b-ber-logger");
|
|
25
|
+
_canopycanopycanopy_b_ber_logger = __toESM(_canopycanopycanopy_b_ber_logger);
|
|
26
|
+
let _canopycanopycanopy_b_ber_shapes_directives = require("@canopycanopycanopy/b-ber-shapes-directives");
|
|
27
|
+
let lodash_isUndefined_js = require("lodash/isUndefined.js");
|
|
28
|
+
lodash_isUndefined_js = __toESM(lodash_isUndefined_js);
|
|
29
|
+
//#region src/index.ts
|
|
30
|
+
const renderer = ({ context = {}, render, markerOpen, markerClose }) => ({
|
|
31
|
+
render,
|
|
32
|
+
marker: _canopycanopycanopy_b_ber_shapes_directives.BLOCK_DIRECTIVE_MARKER,
|
|
33
|
+
minMarkers: _canopycanopycanopy_b_ber_shapes_directives.BLOCK_DIRECTIVE_MARKER_MIN_LENGTH,
|
|
34
|
+
markerOpen,
|
|
35
|
+
markerClose,
|
|
36
|
+
validateOpen(params, line) {
|
|
37
|
+
const match = params.trim().match(markerOpen);
|
|
38
|
+
if (!match || !match.length) return false;
|
|
39
|
+
const [, type, id] = match;
|
|
40
|
+
if ((0, lodash_isUndefined_js.default)(id)) {
|
|
41
|
+
_canopycanopycanopy_b_ber_logger.default.error(`Missing [id] for [${type}:start] at ${context.fileName}.md:${line}`);
|
|
42
|
+
return false;
|
|
43
|
+
}
|
|
44
|
+
const index = _canopycanopycanopy_b_ber_lib.State.indexOf("cursor", { id });
|
|
45
|
+
const isOpening = type && type !== "exit";
|
|
46
|
+
const isClosing = type && type === "exit";
|
|
47
|
+
const inStore = index > -1;
|
|
48
|
+
_canopycanopycanopy_b_ber_logger.default.debug(`id: ${id}; isOpening: ${isOpening}; isClosing: ${isClosing}; type: ${type}, inStore: ${inStore}`);
|
|
49
|
+
const location = `${context.fileName}.md:${line}`;
|
|
50
|
+
if (isOpening && inStore) _canopycanopycanopy_b_ber_logger.default.error(`Duplicate [id] [${id}]. [id] must be unique at [${location}]`);
|
|
51
|
+
else if (isClosing && !inStore) return false;
|
|
52
|
+
else if (isOpening && !inStore) {
|
|
53
|
+
_canopycanopycanopy_b_ber_lib.State.add("cursor", {
|
|
54
|
+
id,
|
|
55
|
+
type
|
|
56
|
+
});
|
|
57
|
+
return true;
|
|
58
|
+
} else if (isClosing && inStore) return true;
|
|
59
|
+
}
|
|
7
60
|
});
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
var _indexOf = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/instance/index-of"));
|
|
11
|
-
var _lodash = _interopRequireDefault(require("lodash.isundefined"));
|
|
12
|
-
var _State = _interopRequireDefault(require("@canopycanopycanopy/b-ber-lib/State"));
|
|
13
|
-
var _bBerLogger = _interopRequireDefault(require("@canopycanopycanopy/b-ber-logger"));
|
|
14
|
-
var _bBerShapesDirectives = require("@canopycanopycanopy/b-ber-shapes-directives");
|
|
15
|
-
// Assign a default object to the `context` argument, since we'll refer to
|
|
16
|
-
// some of its properties during tests. the properties themselves don't
|
|
17
|
-
// need to be defined, though
|
|
18
|
-
const renderer = ({
|
|
19
|
-
context = {},
|
|
20
|
-
render,
|
|
21
|
-
markerOpen,
|
|
22
|
-
markerClose
|
|
23
|
-
}) => ({
|
|
24
|
-
render,
|
|
25
|
-
marker: _bBerShapesDirectives.BLOCK_DIRECTIVE_MARKER,
|
|
26
|
-
minMarkers: _bBerShapesDirectives.BLOCK_DIRECTIVE_MARKER_MIN_LENGTH,
|
|
27
|
-
markerOpen,
|
|
28
|
-
markerClose,
|
|
29
|
-
validateOpen(params, line) {
|
|
30
|
-
// Check to see if we've hit an opening/exit token, i.e., `::: <name>:<id>`
|
|
31
|
-
const match = (0, _trim.default)(params).call(params).match(markerOpen);
|
|
32
|
-
if (!match || !match.length) return false;
|
|
33
|
-
|
|
34
|
-
// It's a directive - check to see if it's well-formed.
|
|
35
|
-
const [, type, id] = match;
|
|
36
|
-
if ((0, _lodash.default)(id)) {
|
|
37
|
-
// The directive's missing an `id` attribute, so we extract the
|
|
38
|
-
// fileName from `context` which we've stored in back in
|
|
39
|
-
// `md/index.es6`, and passed into our `renderer`
|
|
40
|
-
_bBerLogger.default.error(`Missing [id] for [${exports.default.name}:start] at ${context.fileName}.md:${line}`);
|
|
41
|
-
|
|
42
|
-
// Let the parser know that this wasn't a match
|
|
43
|
-
return false;
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
// Add the `id` to the global state so that we can verify that the
|
|
47
|
-
// container is being properly closed in our `validateClose` method
|
|
48
|
-
const index = (0, _indexOf.default)(_State.default).call(_State.default, 'cursor', {
|
|
49
|
-
id
|
|
50
|
-
});
|
|
51
|
-
const isOpening = type && type !== 'exit';
|
|
52
|
-
const isClosing = type && type === 'exit';
|
|
53
|
-
const inStore = index > -1;
|
|
54
|
-
_bBerLogger.default.debug(`id: ${id}; isOpening: ${isOpening}; isClosing: ${isClosing}; type: ${type}, inStore: ${inStore}`);
|
|
55
|
-
const location = `${context.fileName}.md:${line}`;
|
|
56
|
-
if (isOpening && inStore) {
|
|
57
|
-
// It's a duplicate `id`
|
|
58
|
-
_bBerLogger.default.error(`Duplicate [id] [${id}]. [id] must be unique at [${location}]`);
|
|
59
|
-
} else if (isClosing && !inStore) {
|
|
60
|
-
// Trying to close an un-opened directive, but it might belong to a
|
|
61
|
-
// different directive type
|
|
62
|
-
return false;
|
|
63
|
-
} else if (isOpening && !inStore) {
|
|
64
|
-
// It's a new directive
|
|
65
|
-
_State.default.add('cursor', {
|
|
66
|
-
id,
|
|
67
|
-
type
|
|
68
|
-
});
|
|
69
|
-
return true;
|
|
70
|
-
} else if (isClosing && inStore) {
|
|
71
|
-
// It's the end of a directive, handle close in section.js
|
|
72
|
-
return true;
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
});
|
|
76
|
-
var _default = renderer;
|
|
77
|
-
exports.default = _default;
|
|
61
|
+
//#endregion
|
|
62
|
+
module.exports = renderer;
|
package/package.json
CHANGED
|
@@ -1,14 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@canopycanopycanopy/b-ber-grammar-renderer",
|
|
3
|
-
"version": "3.0.8-
|
|
3
|
+
"version": "3.0.8-next.96+7446845b",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"scripts": {
|
|
7
|
-
"
|
|
8
|
-
"
|
|
9
|
-
"prepare": "npm run clean && npm run prepare:dist",
|
|
10
|
-
"build": "npm run prepare",
|
|
11
|
-
"watch": "BABEL_ENV=production babel --config-file ../../babel.config.js -d dist/ src/ --watch src",
|
|
7
|
+
"build": "tsdown",
|
|
8
|
+
"typecheck": "tsc --noEmit",
|
|
12
9
|
"test": "jest"
|
|
13
10
|
},
|
|
14
11
|
"author": "Triple Canopy <b-ber@canopycanopycanopy.com> (https://triplecanopy.github.io/)",
|
|
@@ -17,20 +14,18 @@
|
|
|
17
14
|
"access": "public"
|
|
18
15
|
},
|
|
19
16
|
"devDependencies": {
|
|
20
|
-
"@
|
|
21
|
-
"@
|
|
22
|
-
"
|
|
23
|
-
"
|
|
24
|
-
"
|
|
25
|
-
"
|
|
17
|
+
"@swc/core": "^1.15.40",
|
|
18
|
+
"@swc/jest": "^0.2.39",
|
|
19
|
+
"jest": "^29.7.0",
|
|
20
|
+
"rimraf": "^2.7.1",
|
|
21
|
+
"tsdown": "^0.22.1",
|
|
22
|
+
"typescript": "^6.0.3"
|
|
26
23
|
},
|
|
27
24
|
"dependencies": {
|
|
28
|
-
"@canopycanopycanopy/b-ber-lib": "3.0.8-
|
|
29
|
-
"@canopycanopycanopy/b-ber-logger": "3.0.8-
|
|
30
|
-
"@canopycanopycanopy/b-ber-shapes-directives": "3.0.8-
|
|
31
|
-
"lodash": "^4.17.21"
|
|
32
|
-
"lodash.isundefined": "^3.0.1",
|
|
33
|
-
"tar": "^6.1.11"
|
|
25
|
+
"@canopycanopycanopy/b-ber-lib": "3.0.8-next.96+7446845b",
|
|
26
|
+
"@canopycanopycanopy/b-ber-logger": "3.0.8-next.96+7446845b",
|
|
27
|
+
"@canopycanopycanopy/b-ber-shapes-directives": "3.0.8-next.96+7446845b",
|
|
28
|
+
"lodash": "^4.17.21"
|
|
34
29
|
},
|
|
35
30
|
"files": [
|
|
36
31
|
"dist"
|
|
@@ -49,5 +44,6 @@
|
|
|
49
44
|
"url": "https://maxwellsimmer.com"
|
|
50
45
|
}
|
|
51
46
|
],
|
|
52
|
-
"gitHead": "
|
|
47
|
+
"gitHead": "7446845bcda4337bfbc9f75b55a1e0ca805023eb",
|
|
48
|
+
"types": "dist/index.d.ts"
|
|
53
49
|
}
|