@canopycanopycanopy/b-ber-grammar-section 3.0.8-nav-memo.4 → 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 +15 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +83 -114
- package/package.json +18 -22
package/README.md
CHANGED
|
@@ -1,9 +1,20 @@
|
|
|
1
|
-
#
|
|
1
|
+
# b-ber-grammar-section
|
|
2
2
|
|
|
3
|
-
The
|
|
3
|
+
The universal block-container directive handler. Matches all container-type directives defined in `BLOCK_DIRECTIVES` (chapter, part, appendix, preface, and many others from the EPUB 3 Structural Semantic Vocabulary), as well as `exit`. Opening tokens emit a `<section id="..." class="..." epub:type="...">` with HTML comments marking the start; exit tokens close the element and remove the id from state. For `gallery` and `spread` directives in `reader`/`web` builds, the exit handler emits the additional closing tags required by those directives' multi-element scaffolds. Uses `b-ber-parser-section` as the MarkdownIt plugin and delegates open/close validation to `b-ber-grammar-renderer`.
|
|
4
4
|
|
|
5
|
-
##
|
|
5
|
+
## Usage
|
|
6
6
|
|
|
7
|
+
Registered as a MarkdownIt plugin by the rendering engine:
|
|
8
|
+
|
|
9
|
+
```js
|
|
10
|
+
import section from '@canopycanopycanopy/b-ber-grammar-section'
|
|
11
|
+
// { plugin, name: 'section', renderer }
|
|
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,15 @@
|
|
|
1
|
+
//#region src/index.d.ts
|
|
2
|
+
declare const _default: {
|
|
3
|
+
plugin: (md: any, name: string, options?: any) => void;
|
|
4
|
+
name: string;
|
|
5
|
+
renderer: (args: any) => {
|
|
6
|
+
render: any;
|
|
7
|
+
marker: string;
|
|
8
|
+
minMarkers: number;
|
|
9
|
+
markerOpen: any;
|
|
10
|
+
markerClose: any;
|
|
11
|
+
validateOpen(params: any, line: any): boolean | undefined;
|
|
12
|
+
};
|
|
13
|
+
};
|
|
14
|
+
export = _default;
|
|
15
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","names":[],"sources":["../src/index.ts"],"mappings":""}
|
package/dist/index.js
CHANGED
|
@@ -1,134 +1,103 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
var
|
|
4
|
-
var
|
|
5
|
-
var
|
|
6
|
-
var
|
|
7
|
-
var
|
|
8
|
-
var
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
});
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
var
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
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_grammar_attributes = require("@canopycanopycanopy/b-ber-grammar-attributes");
|
|
24
|
+
let _canopycanopycanopy_b_ber_grammar_renderer = require("@canopycanopycanopy/b-ber-grammar-renderer");
|
|
25
|
+
_canopycanopycanopy_b_ber_grammar_renderer = __toESM(_canopycanopycanopy_b_ber_grammar_renderer);
|
|
26
|
+
let _canopycanopycanopy_b_ber_lib = require("@canopycanopycanopy/b-ber-lib");
|
|
27
|
+
let _canopycanopycanopy_b_ber_logger = require("@canopycanopycanopy/b-ber-logger");
|
|
28
|
+
_canopycanopycanopy_b_ber_logger = __toESM(_canopycanopycanopy_b_ber_logger);
|
|
29
|
+
let _canopycanopycanopy_b_ber_parser_section = require("@canopycanopycanopy/b-ber-parser-section");
|
|
30
|
+
_canopycanopycanopy_b_ber_parser_section = __toESM(_canopycanopycanopy_b_ber_parser_section);
|
|
31
|
+
let _canopycanopycanopy_b_ber_shapes_directives = require("@canopycanopycanopy/b-ber-shapes-directives");
|
|
32
|
+
let lodash_find_js = require("lodash/find.js");
|
|
33
|
+
lodash_find_js = __toESM(lodash_find_js);
|
|
34
|
+
//#region src/index.ts
|
|
35
|
+
const containers = Array.from(_canopycanopycanopy_b_ber_shapes_directives.BLOCK_DIRECTIVES).join("|");
|
|
35
36
|
const MARKER_OPEN_RE = new RegExp(`^(${containers}|exit)(?::([^\\s]+)(\\s.*)?)?$`);
|
|
36
37
|
const MARKER_CLOSE_RE = /(exit)(?::([^\s]+))?/;
|
|
37
|
-
|
|
38
|
-
// `context` must be available in this `render` method and is passed
|
|
39
|
-
// into `createRenderer` below. Default for `context` is set for use
|
|
40
|
-
// during tests
|
|
41
|
-
|
|
42
38
|
function isGallery(directive) {
|
|
43
|
-
|
|
39
|
+
return directive && directive.type === "gallery" && (_canopycanopycanopy_b_ber_lib.State.build === "web" || _canopycanopycanopy_b_ber_lib.State.build === "reader");
|
|
44
40
|
}
|
|
45
41
|
function isSpread(directive) {
|
|
46
|
-
|
|
42
|
+
return directive && directive.type === "spread" && (_canopycanopycanopy_b_ber_lib.State.build === "web" || _canopycanopycanopy_b_ber_lib.State.build === "reader");
|
|
47
43
|
}
|
|
48
44
|
function handleExitDirective(token) {
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
_State.default.remove('cursor', {
|
|
56
|
-
id
|
|
57
|
-
});
|
|
58
|
-
if (isGallery(directive)) {
|
|
59
|
-
// prettier-ignore
|
|
60
|
-
return `</div>
|
|
45
|
+
const [, type, id] = token;
|
|
46
|
+
_canopycanopycanopy_b_ber_logger.default.debug(`exit directive [${id}]`);
|
|
47
|
+
const comment = _canopycanopycanopy_b_ber_lib.Html.comment(`END: section:${type}#${(0, _canopycanopycanopy_b_ber_grammar_attributes.htmlId)(id)}`);
|
|
48
|
+
const directive = (0, lodash_find_js.default)(_canopycanopycanopy_b_ber_lib.State.cursor, { id });
|
|
49
|
+
_canopycanopycanopy_b_ber_lib.State.remove("cursor", { id });
|
|
50
|
+
if (isGallery(directive)) return `</div>
|
|
61
51
|
</figure>
|
|
62
52
|
</div>
|
|
63
53
|
</section>${comment}`;
|
|
64
|
-
|
|
65
|
-
if (isSpread(directive)) {
|
|
66
|
-
return `</div>
|
|
54
|
+
if (isSpread(directive)) return `</div>
|
|
67
55
|
</div>
|
|
68
56
|
|
|
69
|
-
${
|
|
70
|
-
<div></div>` :
|
|
57
|
+
${_canopycanopycanopy_b_ber_lib.State.build === "reader" ? `<!-- Empty node required for spread markers -->
|
|
58
|
+
<div></div>` : ""}
|
|
71
59
|
|
|
72
60
|
${comment}`;
|
|
73
|
-
|
|
74
|
-
return `</section>${comment}`;
|
|
61
|
+
return `</section>${comment}`;
|
|
75
62
|
}
|
|
76
63
|
function openElement(token, fileName, lineNumber) {
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
});
|
|
86
|
-
return `${comment}<section id="${(0, _bBerGrammarAttributes.htmlId)(id)}"${attrs}>`;
|
|
64
|
+
const [, type, id, attr] = token;
|
|
65
|
+
_canopycanopycanopy_b_ber_logger.default.debug(`open directive [${id}]`);
|
|
66
|
+
const comment = _canopycanopycanopy_b_ber_lib.Html.comment(`START: section:${type}#${(0, _canopycanopycanopy_b_ber_grammar_attributes.htmlId)(id)}; ${fileName}:${lineNumber}`);
|
|
67
|
+
const attrs = (0, _canopycanopycanopy_b_ber_grammar_attributes.attributes)(attr, type, {
|
|
68
|
+
fileName,
|
|
69
|
+
lineNumber
|
|
70
|
+
});
|
|
71
|
+
return `${comment}<section id="${(0, _canopycanopycanopy_b_ber_grammar_attributes.htmlId)(id)}"${attrs}>`;
|
|
87
72
|
}
|
|
88
73
|
function closeElement(marker) {
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
const [, id] = token;
|
|
97
|
-
if (!_State.default.contains('cursor', {
|
|
98
|
-
id
|
|
99
|
-
})) return '';
|
|
100
|
-
|
|
101
|
-
// its id still exists in state, so it's open. force close here
|
|
102
|
-
const comment = _bBerLib.Html.comment(`END: section:#${(0, _bBerGrammarAttributes.htmlId)(id)}`);
|
|
103
|
-
const result = `</section>${comment}`;
|
|
104
|
-
|
|
105
|
-
// remove the id
|
|
106
|
-
_State.default.remove('cursor', {
|
|
107
|
-
id
|
|
108
|
-
});
|
|
109
|
-
return result;
|
|
74
|
+
const token = marker.split(":");
|
|
75
|
+
if (token.length < 2) return "";
|
|
76
|
+
const [, id] = token;
|
|
77
|
+
if (!_canopycanopycanopy_b_ber_lib.State.contains("cursor", { id })) return "";
|
|
78
|
+
const result = `</section>${_canopycanopycanopy_b_ber_lib.Html.comment(`END: section:#${(0, _canopycanopycanopy_b_ber_grammar_attributes.htmlId)(id)}`)}`;
|
|
79
|
+
_canopycanopycanopy_b_ber_lib.State.remove("cursor", { id });
|
|
80
|
+
return result;
|
|
110
81
|
}
|
|
111
|
-
const render = ({
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
82
|
+
const render = ({ context = {} }) => (tokens, index) => {
|
|
83
|
+
const token = tokens[index];
|
|
84
|
+
const lineNumber = token.map ? token.map[0] : null;
|
|
85
|
+
const fileName = `_markdown/${context.fileName}.md`;
|
|
86
|
+
const marker = token.info.trim();
|
|
87
|
+
if (token.nesting !== 1) return closeElement(marker);
|
|
88
|
+
const tokenClose = marker.match(MARKER_CLOSE_RE);
|
|
89
|
+
const tokenOpen = marker.match(MARKER_OPEN_RE);
|
|
90
|
+
return tokenClose ? handleExitDirective(tokenClose) : openElement(tokenOpen, fileName, lineNumber);
|
|
91
|
+
};
|
|
92
|
+
var src_default = {
|
|
93
|
+
plugin: _canopycanopycanopy_b_ber_parser_section.default,
|
|
94
|
+
name: "section",
|
|
95
|
+
renderer: (args) => (0, _canopycanopycanopy_b_ber_grammar_renderer.default)({
|
|
96
|
+
...args,
|
|
97
|
+
markerOpen: MARKER_OPEN_RE,
|
|
98
|
+
markerClose: MARKER_CLOSE_RE,
|
|
99
|
+
render: render(args)
|
|
100
|
+
})
|
|
125
101
|
};
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
name: 'section',
|
|
129
|
-
renderer: args => (0, _bBerGrammarRenderer.default)(_objectSpread(_objectSpread({}, args), {}, {
|
|
130
|
-
markerOpen: MARKER_OPEN_RE,
|
|
131
|
-
markerClose: MARKER_CLOSE_RE,
|
|
132
|
-
render: render(args)
|
|
133
|
-
}))
|
|
134
|
-
};
|
|
102
|
+
//#endregion
|
|
103
|
+
module.exports = src_default;
|
package/package.json
CHANGED
|
@@ -1,14 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@canopycanopycanopy/b-ber-grammar-section",
|
|
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,23 +14,21 @@
|
|
|
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-grammar-attributes": "3.0.8-
|
|
29
|
-
"@canopycanopycanopy/b-ber-grammar-renderer": "3.0.8-
|
|
30
|
-
"@canopycanopycanopy/b-ber-lib": "3.0.8-
|
|
31
|
-
"@canopycanopycanopy/b-ber-logger": "3.0.8-
|
|
32
|
-
"@canopycanopycanopy/b-ber-parser-section": "3.0.8-
|
|
33
|
-
"@canopycanopycanopy/b-ber-shapes-directives": "3.0.8-
|
|
34
|
-
"lodash": "^4.17.21"
|
|
35
|
-
"lodash.find": "latest",
|
|
36
|
-
"tar": "^6.1.11"
|
|
25
|
+
"@canopycanopycanopy/b-ber-grammar-attributes": "3.0.8-next.96+7446845b",
|
|
26
|
+
"@canopycanopycanopy/b-ber-grammar-renderer": "3.0.8-next.96+7446845b",
|
|
27
|
+
"@canopycanopycanopy/b-ber-lib": "3.0.8-next.96+7446845b",
|
|
28
|
+
"@canopycanopycanopy/b-ber-logger": "3.0.8-next.96+7446845b",
|
|
29
|
+
"@canopycanopycanopy/b-ber-parser-section": "3.0.8-next.96+7446845b",
|
|
30
|
+
"@canopycanopycanopy/b-ber-shapes-directives": "3.0.8-next.96+7446845b",
|
|
31
|
+
"lodash": "^4.17.21"
|
|
37
32
|
},
|
|
38
33
|
"files": [
|
|
39
34
|
"dist"
|
|
@@ -52,5 +47,6 @@
|
|
|
52
47
|
"url": "https://maxwellsimmer.com"
|
|
53
48
|
}
|
|
54
49
|
],
|
|
55
|
-
"gitHead": "
|
|
50
|
+
"gitHead": "7446845bcda4337bfbc9f75b55a1e0ca805023eb",
|
|
51
|
+
"types": "dist/index.d.ts"
|
|
56
52
|
}
|