@canopycanopycanopy/b-ber-grammar-epigraph 3.1.0 → 4.0.0
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 +81 -75
- package/package.json +14 -15
package/README.md
CHANGED
|
@@ -1,9 +1,20 @@
|
|
|
1
|
-
#
|
|
1
|
+
# b-ber-grammar-epigraph
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Handles the `epigraph` inline directive. Supports two forms: an image-based epigraph (`image "file.jpg"` with optional `caption`) that emits a full-width `<section epub:type="epigraph">` containing a figure and image element; and a text-only epigraph (`caption "..." citation "..."`) that emits one or more `<div class="pullquote full-width">` blocks with optional `<cite>` elements inside the epigraph section. Captions and citations support pipe-delimited (`|`) multi-value lists for producing multiple pull-quote blocks from a single directive. Uses `b-ber-parser-figure` as the MarkdownIt plugin.
|
|
4
4
|
|
|
5
|
-
##
|
|
5
|
+
## Usage
|
|
6
6
|
|
|
7
|
+
Registered as a MarkdownIt plugin by the rendering engine. The exported object provides `plugin`, `name`, and a `renderer` factory:
|
|
8
|
+
|
|
9
|
+
```js
|
|
10
|
+
import epigraph from '@canopycanopycanopy/b-ber-grammar-epigraph'
|
|
11
|
+
// { plugin, name: 'epigraph', 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,21 @@
|
|
|
1
|
+
//#region src/index.d.ts
|
|
2
|
+
declare const _default: {
|
|
3
|
+
plugin: (md: any, name: string, options?: any) => void;
|
|
4
|
+
name: string;
|
|
5
|
+
renderer: ({
|
|
6
|
+
instance,
|
|
7
|
+
context
|
|
8
|
+
}: {
|
|
9
|
+
instance: any;
|
|
10
|
+
context?: {
|
|
11
|
+
fileName: string;
|
|
12
|
+
} | undefined;
|
|
13
|
+
}) => {
|
|
14
|
+
marker: string;
|
|
15
|
+
minMarkers: number;
|
|
16
|
+
validate(params: any): any;
|
|
17
|
+
render(tokens: any, idx: any): string;
|
|
18
|
+
};
|
|
19
|
+
};
|
|
20
|
+
export = _default;
|
|
21
|
+
//# 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,78 +1,84 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
var
|
|
4
|
-
var
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
var
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
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_logger = require("@canopycanopycanopy/b-ber-logger");
|
|
24
|
+
_canopycanopycanopy_b_ber_logger = __toESM(_canopycanopycanopy_b_ber_logger);
|
|
25
|
+
let _canopycanopycanopy_b_ber_parser_figure = require("@canopycanopycanopy/b-ber-parser-figure");
|
|
26
|
+
_canopycanopycanopy_b_ber_parser_figure = __toESM(_canopycanopycanopy_b_ber_parser_figure);
|
|
27
|
+
//#region src/index.ts
|
|
26
28
|
const markerRe = /^epigraph/;
|
|
27
29
|
const attrsRe = /(?:(image|caption|citation)\s["]([^"]+)["])/g;
|
|
28
|
-
var
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
attrs[matches[1]] = matches[2];
|
|
59
|
-
}
|
|
60
|
-
if (!attrs.image && !attrs.caption) {
|
|
61
|
-
_bBerLogger.default.error(`[${context.fileName}.md] <epigraph> Malformed directive.`);
|
|
62
|
-
result = '';
|
|
63
|
-
} else if (!attrs.image && attrs.caption) {
|
|
64
|
-
var _context2, _context3;
|
|
65
|
-
const captions = (0, _map.default)(_context2 = attrs.caption.split('|')).call(_context2, _ => (0, _trim.default)(_).call(_));
|
|
66
|
-
const citations = (0, _map.default)(_context3 = attrs.citation.split('|')).call(_context3, _ => (0, _trim.default)(_).call(_));
|
|
67
|
-
result = ['<section epub:type="epigraph" class="epigraph chapter">', '<section epub:type="chapter" class="subchapter">', (0, _map.default)(captions).call(captions, (caption, idx2) => `<div class="pullquote full-width">
|
|
30
|
+
var src_default = {
|
|
31
|
+
plugin: _canopycanopycanopy_b_ber_parser_figure.default,
|
|
32
|
+
name: "epigraph",
|
|
33
|
+
renderer: ({ instance, context = { fileName: "" } }) => ({
|
|
34
|
+
marker: ":",
|
|
35
|
+
minMarkers: 3,
|
|
36
|
+
validate(params) {
|
|
37
|
+
return params.trim().match(markerRe);
|
|
38
|
+
},
|
|
39
|
+
render(tokens, idx) {
|
|
40
|
+
const { escapeHtml } = instance.escapeHtml;
|
|
41
|
+
const attrs = {
|
|
42
|
+
image: "",
|
|
43
|
+
caption: "",
|
|
44
|
+
citation: ""
|
|
45
|
+
};
|
|
46
|
+
let result = "";
|
|
47
|
+
if (tokens[idx].nesting === 1) {
|
|
48
|
+
let matches;
|
|
49
|
+
while ((matches = attrsRe.exec(tokens[idx].info.trim())) !== null) attrs[matches[1]] = matches[2];
|
|
50
|
+
if (!attrs.image && !attrs.caption) {
|
|
51
|
+
_canopycanopycanopy_b_ber_logger.default.error(`[${context.fileName}.md] <epigraph> Malformed directive.`);
|
|
52
|
+
result = "";
|
|
53
|
+
} else if (!attrs.image && attrs.caption) {
|
|
54
|
+
const captions = attrs.caption.split("|").map((_) => _.trim());
|
|
55
|
+
const citations = attrs.citation.split("|").map((_) => _.trim());
|
|
56
|
+
result = [
|
|
57
|
+
"<section epub:type=\"epigraph\" class=\"epigraph chapter\">",
|
|
58
|
+
"<section epub:type=\"chapter\" class=\"subchapter\">",
|
|
59
|
+
captions.map((caption, idx2) => `<div class="pullquote full-width">
|
|
68
60
|
<p>${escapeHtml(caption)}</p>
|
|
69
|
-
${citations[idx2] ? `<cite>—${escapeHtml(citations[idx2])}</cite>` :
|
|
70
|
-
</div>`).join(
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
61
|
+
${citations[idx2] ? `<cite>—${escapeHtml(citations[idx2])}</cite>` : ""}
|
|
62
|
+
</div>`).join(""),
|
|
63
|
+
"</section>",
|
|
64
|
+
"</section>"
|
|
65
|
+
].join("");
|
|
66
|
+
} else result = [
|
|
67
|
+
"<section epub:type=\"epigraph\" class=\"epigraph chapter\">",
|
|
68
|
+
"<div class=\"figure-lg\" style=\"height: auto;\">",
|
|
69
|
+
"<figure style=\"height: auto;\">",
|
|
70
|
+
"<div class=\"figure__items\" style=\"width: 100%; margin: 0 auto;\">",
|
|
71
|
+
`<img class="landscape" alt="${attrs.image}" src="../images/${escapeHtml(attrs.image)}" style="width: 100%; max-width: 100%; height: auto;"/>`,
|
|
72
|
+
attrs.caption ? `<div class="figcaption" style="width: 100%; max-width: 100%; height: auto;"><p class="small">${escapeHtml(attrs.caption)}</p></div>` : "",
|
|
73
|
+
"</div>",
|
|
74
|
+
"</figure>",
|
|
75
|
+
"</div>",
|
|
76
|
+
"</section>"
|
|
77
|
+
].join("");
|
|
78
|
+
}
|
|
79
|
+
return result;
|
|
80
|
+
}
|
|
81
|
+
})
|
|
82
|
+
};
|
|
83
|
+
//#endregion
|
|
84
|
+
module.exports = src_default;
|
package/package.json
CHANGED
|
@@ -1,14 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@canopycanopycanopy/b-ber-grammar-epigraph",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "4.0.0",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"scripts": {
|
|
7
|
-
"
|
|
8
|
-
"
|
|
9
|
-
"
|
|
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
|
+
"watch": "tsdown --watch",
|
|
9
|
+
"typecheck": "tsc --noEmit",
|
|
12
10
|
"test": "jest"
|
|
13
11
|
},
|
|
14
12
|
"author": "Triple Canopy <b-ber@canopycanopycanopy.com> (https://triplecanopy.github.io/)",
|
|
@@ -17,16 +15,16 @@
|
|
|
17
15
|
"access": "public"
|
|
18
16
|
},
|
|
19
17
|
"devDependencies": {
|
|
20
|
-
"@
|
|
21
|
-
"@
|
|
22
|
-
"
|
|
23
|
-
"
|
|
24
|
-
"
|
|
25
|
-
"
|
|
18
|
+
"@swc/core": "^1.15.40",
|
|
19
|
+
"@swc/jest": "^0.2.39",
|
|
20
|
+
"jest": "^29.7.0",
|
|
21
|
+
"rimraf": "^2.7.1",
|
|
22
|
+
"tsdown": "^0.22.1",
|
|
23
|
+
"typescript": "^6.0.3"
|
|
26
24
|
},
|
|
27
25
|
"dependencies": {
|
|
28
|
-
"@canopycanopycanopy/b-ber-logger": "
|
|
29
|
-
"@canopycanopycanopy/b-ber-parser-figure": "
|
|
26
|
+
"@canopycanopycanopy/b-ber-logger": "4.0.0",
|
|
27
|
+
"@canopycanopycanopy/b-ber-parser-figure": "4.0.0",
|
|
30
28
|
"lodash": "^4.17.21",
|
|
31
29
|
"tar": "^6.1.11"
|
|
32
30
|
},
|
|
@@ -47,5 +45,6 @@
|
|
|
47
45
|
"url": "https://maxwellsimmer.com"
|
|
48
46
|
}
|
|
49
47
|
],
|
|
50
|
-
"gitHead": "
|
|
48
|
+
"gitHead": "435b9c7e6b97d3fbdeb21f2308283597040ebfc8",
|
|
49
|
+
"types": "dist/index.d.ts"
|
|
51
50
|
}
|