@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 CHANGED
@@ -1,9 +1,20 @@
1
- # `@canopycanopycanopy/b-ber-grammar-pullquote`
1
+ # b-ber-grammar-pullquote
2
2
 
3
- The `b-ber-grammar-pullquote` package renders b-ber's custom `pullquote` Markdown extension (directive) into HTML. More information about b-ber directives can be found in the [All directives](https://github.com/triplecanopy/b-ber/wiki/all-directives) page in the b-ber [Wiki](https://github.com/triplecanopy/b-ber/wiki).
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
- ## Install
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
- $ npm i -g @canopycanopycanopy/b-ber-grammar-pullquote
13
+
14
+ ## Dev
15
+
9
16
  ```
17
+ npm test
18
+ ```
19
+
20
+ Tests are in `__tests__/index.test.js`.
@@ -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
- "use strict";
2
-
3
- var _Object$defineProperty = require("@babel/runtime-corejs3/core-js-stable/object/define-property");
4
- var _interopRequireDefault = require("@babel/runtime-corejs3/helpers/interopRequireDefault");
5
- _Object$defineProperty(exports, "__esModule", {
6
- value: true
7
- });
8
- exports.default = void 0;
9
- var _indexOf = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/instance/index-of"));
10
- var _trim = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/instance/trim"));
11
- var _map = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/instance/map"));
12
- var _State = _interopRequireDefault(require("@canopycanopycanopy/b-ber-lib/State"));
13
- var _bBerLogger = _interopRequireDefault(require("@canopycanopycanopy/b-ber-logger"));
14
- var _lodash = _interopRequireDefault(require("lodash.has"));
15
- var _lodash2 = _interopRequireDefault(require("lodash.isundefined"));
16
- var _bBerShapesDirectives = require("@canopycanopycanopy/b-ber-shapes-directives");
17
- var _bBerParserSection = _interopRequireDefault(require("@canopycanopycanopy/b-ber-parser-section"));
18
- var _bBerGrammarAttributes = require("@canopycanopycanopy/b-ber-grammar-attributes");
19
- // we can't use our nice factory for this because it doesn't support
20
- // customized closing elements (always outputs `</section>`), so we have to
21
- // write it long-hand. see comments below
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 = []; // track these separately
27
-
37
+ let citation = "";
38
+ const pullquoteIndices = [];
28
39
  function handleOpen(token, context, fileName, lineNumber) {
29
- // the pullquote opens
30
- const [, type, id, attrs] = token;
31
-
32
- // we could just state the id in a variable outside of `render`, but
33
- // good to keep consistent with the normal handling
34
- const index = (0, _indexOf.default)(_State.default).call(_State.default, 'cursor', {
35
- id
36
- });
37
- if (index > -1) _bBerLogger.default.error(`Duplicate [id] [${id}]. [id] must be unique at [${context.fileName}.md:${lineNumber}]`);
38
- pullquoteIndices.push({
39
- id,
40
- type
41
- });
42
-
43
- // parse attrs as normal
44
- const attrsObject = (0, _bBerGrammarAttributes.attributesObject)(attrs, type, {
45
- fileName,
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
- return `<footer><cite>&#8212;&#160;${text}</cite></footer>`;
59
+ return `<footer><cite>&#8212;&#160;${text}</cite></footer>`;
64
60
  }
65
61
  function handleClose(token, instance) {
66
- // it's an exit to a pullquote. grab the id from the list of
67
- // indices
68
-
69
- const {
70
- id,
71
- type
72
- } = pullquoteIndices[pullquoteIndices.length - 1];
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
- citation = '';
88
-
89
- // update indices
90
- pullquoteIndices.pop();
91
- return result;
71
+ citation = "";
72
+ pullquoteIndices.pop();
73
+ return result;
92
74
  }
93
- const validateOpen = ({
94
- context
95
- }) => (params, line) => {
96
- const match = (0, _trim.default)(params).call(params).match(MARKER_OPEN_RE);
97
- if (!match || match.length < 3) return false;
98
- const [,, id] = match;
99
- if ((0, _lodash2.default)(id)) {
100
- _bBerLogger.default.error(`Missing [id] for [${exports.default.name}:start] at ${context.fileName}.md:${line}`);
101
- return false;
102
- }
103
- return true;
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
- const render = ({
106
- instance,
107
- context
108
- }) => (tokens, idx) => {
109
- var _context;
110
- const fileName = `_markdown/${context.fileName}.md`;
111
- const lineNumber = (0, _map.default)(tokens[idx]) ? (0, _map.default)(tokens[idx])[0] : null;
112
- const token = (0, _trim.default)(_context = tokens[idx].info).call(_context);
113
-
114
- // we handle opening and closing render methods on element open, since
115
- // we need to append data (citation blocks) from the directive's opening
116
- // attributes to the end of the element
117
- if (tokens[idx].nesting !== 1) return '';
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
- var _default = exports.default = {
126
- plugin: _bBerParserSection.default,
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-nav-memo.4+d47a9aae",
3
+ "version": "3.0.8-next.96+7446845b",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "scripts": {
7
- "prepare:dist": "BABEL_ENV=production babel --config-file ../../babel.config.js -d dist/ src/ --ignore **/__tests__/**",
8
- "clean": "rimraf dist",
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
- "@babel/cli": "^7.10.5",
21
- "@babel/core": "^7.10.5",
22
- "@babel/preset-env": "^7.10.4",
23
- "browserslist": "^4.17.4",
24
- "jest": "^26.6.3",
25
- "rimraf": "^2.7.1"
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-nav-memo.4+d47a9aae",
29
- "@canopycanopycanopy/b-ber-lib": "3.0.8-nav-memo.4+d47a9aae",
30
- "@canopycanopycanopy/b-ber-logger": "3.0.8-nav-memo.4+d47a9aae",
31
- "@canopycanopycanopy/b-ber-parser-section": "3.0.8-nav-memo.4+d47a9aae",
32
- "@canopycanopycanopy/b-ber-shapes-directives": "3.0.8-nav-memo.4+d47a9aae",
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": "d47a9aae74dec3e3225e363b2434c7abe0fcf21b"
49
+ "gitHead": "7446845bcda4337bfbc9f75b55a1e0ca805023eb",
50
+ "types": "dist/index.d.ts"
56
51
  }