@canopycanopycanopy/b-ber-grammar-pullquote 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 +21 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +97 -132
- package/package.json +17 -22
package/README.md
CHANGED
|
@@ -1,9 +1,20 @@
|
|
|
1
|
-
#
|
|
1
|
+
# b-ber-grammar-pullquote
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Handles the `pullquote`, `blockquote`, and their shared `exit` directive. A `pullquote` opening marker emits a `<section>` element; a `blockquote` opening marker emits a `<blockquote>` element. Both support a `citation` attribute: if present, the citation text is appended as a `<footer><cite>` block when the matching `exit` directive is encountered. The package tracks open directives in a local `pullquoteIndices` stack so that the correct element name and citation are available at close time. Uses `b-ber-parser-section` as the MarkdownIt plugin and the block directive marker/min-length from `b-ber-shapes-directives`.
|
|
4
4
|
|
|
5
|
-
##
|
|
5
|
+
## Usage
|
|
6
6
|
|
|
7
|
+
Registered as a MarkdownIt plugin by the rendering engine:
|
|
8
|
+
|
|
9
|
+
```js
|
|
10
|
+
import pullquote from '@canopycanopycanopy/b-ber-grammar-pullquote'
|
|
11
|
+
// { plugin, name: 'pullQuote', 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: any;
|
|
11
|
+
}) => {
|
|
12
|
+
marker: string;
|
|
13
|
+
minMarkers: number;
|
|
14
|
+
markerOpen: RegExp;
|
|
15
|
+
markerClose: RegExp;
|
|
16
|
+
validateOpen: (params: any, line: any) => boolean;
|
|
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,144 +1,109 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
var
|
|
4
|
-
var
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
var
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
var
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
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_lib = require("@canopycanopycanopy/b-ber-lib");
|
|
25
|
+
let _canopycanopycanopy_b_ber_logger = require("@canopycanopycanopy/b-ber-logger");
|
|
26
|
+
_canopycanopycanopy_b_ber_logger = __toESM(_canopycanopycanopy_b_ber_logger);
|
|
27
|
+
let _canopycanopycanopy_b_ber_parser_section = require("@canopycanopycanopy/b-ber-parser-section");
|
|
28
|
+
_canopycanopycanopy_b_ber_parser_section = __toESM(_canopycanopycanopy_b_ber_parser_section);
|
|
29
|
+
let _canopycanopycanopy_b_ber_shapes_directives = require("@canopycanopycanopy/b-ber-shapes-directives");
|
|
30
|
+
let lodash_has_js = require("lodash/has.js");
|
|
31
|
+
lodash_has_js = __toESM(lodash_has_js);
|
|
32
|
+
let lodash_isUndefined_js = require("lodash/isUndefined.js");
|
|
33
|
+
lodash_isUndefined_js = __toESM(lodash_isUndefined_js);
|
|
34
|
+
//#region src/index.ts
|
|
23
35
|
const MARKER_OPEN_RE = /^(pullquote|blockquote|exit)(?::([^\s]+)(\s.*)?)?$/;
|
|
24
36
|
const MARKER_CLOSE_RE = /(exit)(?::([\s]+))?/;
|
|
25
|
-
let citation =
|
|
26
|
-
const pullquoteIndices = [];
|
|
27
|
-
|
|
37
|
+
let citation = "";
|
|
38
|
+
const pullquoteIndices = [];
|
|
28
39
|
function handleOpen(token, context, fileName, lineNumber) {
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
lineNumber
|
|
47
|
-
});
|
|
48
|
-
|
|
49
|
-
// get citation which we'll use below
|
|
50
|
-
if ((0, _lodash.default)(attrsObject, 'citation')) {
|
|
51
|
-
;
|
|
52
|
-
({
|
|
53
|
-
citation
|
|
54
|
-
} = attrsObject);
|
|
55
|
-
delete attrsObject.citation;
|
|
56
|
-
}
|
|
57
|
-
const attrsString = (0, _bBerGrammarAttributes.attributesString)(attrsObject);
|
|
58
|
-
const elementName = type === 'pullquote' ? 'section' : 'blockquote';
|
|
59
|
-
const comment = `<!-- START: section:${type}#${id} -->`;
|
|
60
|
-
return `${comment}<${elementName}${attrsString}>`;
|
|
40
|
+
const [, type, id, attrs] = token;
|
|
41
|
+
if (_canopycanopycanopy_b_ber_lib.State.indexOf("cursor", { id }) > -1) _canopycanopycanopy_b_ber_logger.default.error(`Duplicate [id] [${id}]. [id] must be unique at [${context.fileName}.md:${lineNumber}]`);
|
|
42
|
+
pullquoteIndices.push({
|
|
43
|
+
id,
|
|
44
|
+
type
|
|
45
|
+
});
|
|
46
|
+
const attrsObject = (0, _canopycanopycanopy_b_ber_grammar_attributes.attributesObject)(attrs, type, {
|
|
47
|
+
fileName,
|
|
48
|
+
lineNumber
|
|
49
|
+
});
|
|
50
|
+
if ((0, lodash_has_js.default)(attrsObject, "citation")) {
|
|
51
|
+
({citation} = attrsObject);
|
|
52
|
+
delete attrsObject.citation;
|
|
53
|
+
}
|
|
54
|
+
const attrsString = (0, _canopycanopycanopy_b_ber_grammar_attributes.attributesString)(attrsObject);
|
|
55
|
+
const elementName = type === "pullquote" ? "section" : "blockquote";
|
|
56
|
+
return `${`<!-- START: section:${type}#${id} -->`}<${elementName}${attrsString}>`;
|
|
61
57
|
}
|
|
62
58
|
function cite(text) {
|
|
63
|
-
|
|
59
|
+
return `<footer><cite>— ${text}</cite></footer>`;
|
|
64
60
|
}
|
|
65
61
|
function handleClose(token, instance) {
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
const elementName = type === 'pullquote' ? 'section' : 'blockquote';
|
|
74
|
-
|
|
75
|
-
// check that the id matches our token
|
|
76
|
-
if (!id || !token.match(new RegExp(`exit:${id}`))) return '';
|
|
77
|
-
let result = '';
|
|
78
|
-
|
|
79
|
-
// it's a match for the exit directive's `id`, output the citation
|
|
80
|
-
// with the HTML comment and reset the citation to prepare for the
|
|
81
|
-
// next iteration
|
|
82
|
-
const comment = `<!-- END: section:${type}#${id} -->`;
|
|
83
|
-
result = `
|
|
84
|
-
${citation ? cite(instance.renderInline(citation)) : ''}
|
|
62
|
+
const { id, type } = pullquoteIndices[pullquoteIndices.length - 1];
|
|
63
|
+
const elementName = type === "pullquote" ? "section" : "blockquote";
|
|
64
|
+
if (!id || !token.match(new RegExp(`exit:${id}`))) return "";
|
|
65
|
+
let result = "";
|
|
66
|
+
const comment = `<!-- END: section:${type}#${id} -->`;
|
|
67
|
+
result = `
|
|
68
|
+
${citation ? cite(instance.renderInline(citation)) : ""}
|
|
85
69
|
</${elementName}>${comment}
|
|
86
70
|
`;
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
pullquoteIndices.pop();
|
|
91
|
-
return result;
|
|
71
|
+
citation = "";
|
|
72
|
+
pullquoteIndices.pop();
|
|
73
|
+
return result;
|
|
92
74
|
}
|
|
93
|
-
const validateOpen = ({
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
75
|
+
const validateOpen = ({ context }) => (params, line) => {
|
|
76
|
+
const match = params.trim().match(MARKER_OPEN_RE);
|
|
77
|
+
if (!match || match.length < 3) return false;
|
|
78
|
+
const [, type, id] = match;
|
|
79
|
+
if ((0, lodash_isUndefined_js.default)(id)) {
|
|
80
|
+
_canopycanopycanopy_b_ber_logger.default.error(`Missing [id] for [${type}:start] at ${context.fileName}.md:${line}`);
|
|
81
|
+
return false;
|
|
82
|
+
}
|
|
83
|
+
return true;
|
|
84
|
+
};
|
|
85
|
+
const render = ({ instance, context }) => (tokens, idx) => {
|
|
86
|
+
const fileName = `_markdown/${context.fileName}.md`;
|
|
87
|
+
const lineNumber = tokens[idx].map ? tokens[idx].map[0] : null;
|
|
88
|
+
const token = tokens[idx].info.trim();
|
|
89
|
+
if (tokens[idx].nesting !== 1) return "";
|
|
90
|
+
const tokenOpen = token.match(MARKER_OPEN_RE);
|
|
91
|
+
return token.match(MARKER_CLOSE_RE) ? handleClose(token, instance) : tokenOpen ? handleOpen(tokenOpen, context, fileName, lineNumber) : "";
|
|
104
92
|
};
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
// either a `pullquote`, `blockquote` or an `exit` directive, we
|
|
120
|
-
// keep matches for both in `open` and `close` vars below
|
|
121
|
-
const tokenOpen = token.match(MARKER_OPEN_RE);
|
|
122
|
-
const tokenClose = token.match(MARKER_CLOSE_RE);
|
|
123
|
-
return tokenClose ? handleClose(token, instance) : tokenOpen ? handleOpen(tokenOpen, context, fileName, lineNumber) : '';
|
|
93
|
+
var src_default = {
|
|
94
|
+
plugin: _canopycanopycanopy_b_ber_parser_section.default,
|
|
95
|
+
name: "pullQuote",
|
|
96
|
+
renderer: ({ instance, context }) => ({
|
|
97
|
+
marker: _canopycanopycanopy_b_ber_shapes_directives.BLOCK_DIRECTIVE_MARKER,
|
|
98
|
+
minMarkers: _canopycanopycanopy_b_ber_shapes_directives.BLOCK_DIRECTIVE_MARKER_MIN_LENGTH,
|
|
99
|
+
markerOpen: MARKER_OPEN_RE,
|
|
100
|
+
markerClose: MARKER_CLOSE_RE,
|
|
101
|
+
validateOpen: validateOpen({ context }),
|
|
102
|
+
render: render({
|
|
103
|
+
instance,
|
|
104
|
+
context
|
|
105
|
+
})
|
|
106
|
+
})
|
|
124
107
|
};
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
name: 'pullQuote',
|
|
128
|
-
renderer: ({
|
|
129
|
-
instance,
|
|
130
|
-
context
|
|
131
|
-
}) => ({
|
|
132
|
-
marker: _bBerShapesDirectives.BLOCK_DIRECTIVE_MARKER,
|
|
133
|
-
minMarkers: _bBerShapesDirectives.BLOCK_DIRECTIVE_MARKER_MIN_LENGTH,
|
|
134
|
-
markerOpen: MARKER_OPEN_RE,
|
|
135
|
-
markerClose: MARKER_CLOSE_RE,
|
|
136
|
-
validateOpen: validateOpen({
|
|
137
|
-
context
|
|
138
|
-
}),
|
|
139
|
-
render: render({
|
|
140
|
-
instance,
|
|
141
|
-
context
|
|
142
|
-
})
|
|
143
|
-
})
|
|
144
|
-
};
|
|
108
|
+
//#endregion
|
|
109
|
+
module.exports = src_default;
|
package/package.json
CHANGED
|
@@ -1,14 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@canopycanopycanopy/b-ber-grammar-pullquote",
|
|
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,20 @@
|
|
|
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-lib": "3.0.8-
|
|
30
|
-
"@canopycanopycanopy/b-ber-logger": "3.0.8-
|
|
31
|
-
"@canopycanopycanopy/b-ber-parser-section": "3.0.8-
|
|
32
|
-
"@canopycanopycanopy/b-ber-shapes-directives": "3.0.8-
|
|
33
|
-
"lodash": "^4.17.21"
|
|
34
|
-
"lodash.has": "latest",
|
|
35
|
-
"lodash.isundefined": "^3.0.1",
|
|
36
|
-
"tar": "^6.1.11"
|
|
25
|
+
"@canopycanopycanopy/b-ber-grammar-attributes": "3.0.8-next.96+7446845b",
|
|
26
|
+
"@canopycanopycanopy/b-ber-lib": "3.0.8-next.96+7446845b",
|
|
27
|
+
"@canopycanopycanopy/b-ber-logger": "3.0.8-next.96+7446845b",
|
|
28
|
+
"@canopycanopycanopy/b-ber-parser-section": "3.0.8-next.96+7446845b",
|
|
29
|
+
"@canopycanopycanopy/b-ber-shapes-directives": "3.0.8-next.96+7446845b",
|
|
30
|
+
"lodash": "^4.17.21"
|
|
37
31
|
},
|
|
38
32
|
"files": [
|
|
39
33
|
"dist"
|
|
@@ -52,5 +46,6 @@
|
|
|
52
46
|
"url": "https://maxwellsimmer.com"
|
|
53
47
|
}
|
|
54
48
|
],
|
|
55
|
-
"gitHead": "
|
|
49
|
+
"gitHead": "7446845bcda4337bfbc9f75b55a1e0ca805023eb",
|
|
50
|
+
"types": "dist/index.d.ts"
|
|
56
51
|
}
|