@canopycanopycanopy/b-ber-grammar-pullquote 2.0.0 → 2.0.2

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.
Files changed (2) hide show
  1. package/dist/index.js +21 -35
  2. package/package.json +7 -7
package/dist/index.js CHANGED
@@ -1,38 +1,25 @@
1
1
  "use strict";
2
2
 
3
3
  var _Object$defineProperty = require("@babel/runtime-corejs3/core-js-stable/object/define-property");
4
-
5
4
  var _interopRequireDefault = require("@babel/runtime-corejs3/helpers/interopRequireDefault");
6
-
7
5
  _Object$defineProperty(exports, "__esModule", {
8
6
  value: true
9
7
  });
10
-
11
8
  exports.default = void 0;
12
-
13
9
  var _indexOf = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/instance/index-of"));
14
-
15
10
  var _trim = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/instance/trim"));
16
-
17
11
  var _map = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/instance/map"));
18
-
19
12
  var _State = _interopRequireDefault(require("@canopycanopycanopy/b-ber-lib/State"));
20
-
21
13
  var _bBerLogger = _interopRequireDefault(require("@canopycanopycanopy/b-ber-logger"));
22
-
23
14
  var _lodash = _interopRequireDefault(require("lodash.has"));
24
-
25
15
  var _lodash2 = _interopRequireDefault(require("lodash.isundefined"));
26
-
27
16
  var _bBerShapesDirectives = require("@canopycanopycanopy/b-ber-shapes-directives");
28
-
29
17
  var _bBerParserSection = _interopRequireDefault(require("@canopycanopycanopy/b-ber-parser-section"));
30
-
31
18
  var _bBerGrammarAttributes = require("@canopycanopycanopy/b-ber-grammar-attributes");
32
-
33
19
  // we can't use our nice factory for this because it doesn't support
34
20
  // customized closing elements (always outputs `</section>`), so we have to
35
21
  // write it long-hand. see comments below
22
+
36
23
  const MARKER_OPEN_RE = /^(pullquote|blockquote|exit)(?::([^\s]+)(\s.*)?)?$/;
37
24
  const MARKER_CLOSE_RE = /(exit)(?::([\s]+))?/;
38
25
  let citation = '';
@@ -40,9 +27,10 @@ const pullquoteIndices = []; // track these separately
40
27
 
41
28
  function handleOpen(token, context, fileName, lineNumber) {
42
29
  // the pullquote opens
43
- const [, type, id, attrs] = token; // we could just state the id in a variable outside of `render`, but
44
- // good to keep consistent with the normal handling
30
+ const [, type, id, attrs] = token;
45
31
 
32
+ // we could just state the id in a variable outside of `render`, but
33
+ // good to keep consistent with the normal handling
46
34
  const index = (0, _indexOf.default)(_State.default).call(_State.default, 'cursor', {
47
35
  id
48
36
  });
@@ -50,13 +38,15 @@ function handleOpen(token, context, fileName, lineNumber) {
50
38
  pullquoteIndices.push({
51
39
  id,
52
40
  type
53
- }); // parse attrs as normal
41
+ });
54
42
 
43
+ // parse attrs as normal
55
44
  const attrsObject = (0, _bBerGrammarAttributes.attributesObject)(attrs, type, {
56
45
  fileName,
57
46
  lineNumber
58
- }); // get citation which we'll use below
47
+ });
59
48
 
49
+ // get citation which we'll use below
60
50
  if ((0, _lodash.default)(attrsObject, 'citation')) {
61
51
  ;
62
52
  ({
@@ -64,78 +54,74 @@ function handleOpen(token, context, fileName, lineNumber) {
64
54
  } = attrsObject);
65
55
  delete attrsObject.citation;
66
56
  }
67
-
68
57
  const attrsString = (0, _bBerGrammarAttributes.attributesString)(attrsObject);
69
58
  const elementName = type === 'pullquote' ? 'section' : 'blockquote';
70
59
  const comment = `<!-- START: section:${type}#${id} -->`;
71
60
  return `${comment}<${elementName}${attrsString}>`;
72
61
  }
73
-
74
62
  function cite(text) {
75
63
  return `<footer><cite>&#8212;&#160;${text}</cite></footer>`;
76
64
  }
77
-
78
65
  function handleClose(token, instance) {
79
66
  // it's an exit to a pullquote. grab the id from the list of
80
67
  // indices
68
+
81
69
  const {
82
70
  id,
83
71
  type
84
72
  } = pullquoteIndices[pullquoteIndices.length - 1];
85
- const elementName = type === 'pullquote' ? 'section' : 'blockquote'; // check that the id matches our token
73
+ const elementName = type === 'pullquote' ? 'section' : 'blockquote';
86
74
 
75
+ // check that the id matches our token
87
76
  if (!id || !token.match(new RegExp(`exit:${id}`))) return '';
88
- let result = ''; // it's a match for the exit directive's `id`, output the citation
77
+ let result = '';
78
+
79
+ // it's a match for the exit directive's `id`, output the citation
89
80
  // with the HTML comment and reset the citation to prepare for the
90
81
  // next iteration
91
-
92
82
  const comment = `<!-- END: section:${type}#${id} -->`;
93
83
  result = `
94
84
  ${citation ? cite(instance.renderInline(citation)) : ''}
95
85
  </${elementName}>${comment}
96
86
  `;
97
- citation = ''; // update indices
87
+ citation = '';
98
88
 
89
+ // update indices
99
90
  pullquoteIndices.pop();
100
91
  return result;
101
92
  }
102
-
103
93
  const validateOpen = ({
104
94
  context
105
95
  }) => (params, line) => {
106
96
  const match = (0, _trim.default)(params).call(params).match(MARKER_OPEN_RE);
107
97
  if (!match || match.length < 3) return false;
108
98
  const [,, id] = match;
109
-
110
99
  if ((0, _lodash2.default)(id)) {
111
100
  _bBerLogger.default.error(`Missing [id] for [${exports.default.name}:start] at ${context.fileName}.md:${line}`);
112
-
113
101
  return false;
114
102
  }
115
-
116
103
  return true;
117
104
  };
118
-
119
105
  const render = ({
120
106
  instance,
121
107
  context
122
108
  }) => (tokens, idx) => {
123
109
  var _context;
124
-
125
110
  const fileName = `_markdown/${context.fileName}.md`;
126
111
  const lineNumber = (0, _map.default)(tokens[idx]) ? (0, _map.default)(tokens[idx])[0] : null;
127
- const token = (0, _trim.default)(_context = tokens[idx].info).call(_context); // we handle opening and closing render methods on element open, since
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
128
115
  // we need to append data (citation blocks) from the directive's opening
129
116
  // attributes to the end of the element
117
+ if (tokens[idx].nesting !== 1) return '';
130
118
 
131
- if (tokens[idx].nesting !== 1) return ''; // either a `pullquote`, `blockquote` or an `exit` directive, we
119
+ // either a `pullquote`, `blockquote` or an `exit` directive, we
132
120
  // keep matches for both in `open` and `close` vars below
133
-
134
121
  const tokenOpen = token.match(MARKER_OPEN_RE);
135
122
  const tokenClose = token.match(MARKER_CLOSE_RE);
136
123
  return tokenClose ? handleClose(token, instance) : tokenOpen ? handleOpen(tokenOpen, context, fileName, lineNumber) : '';
137
124
  };
138
-
139
125
  var _default = {
140
126
  plugin: _bBerParserSection.default,
141
127
  name: 'pullQuote',
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@canopycanopycanopy/b-ber-grammar-pullquote",
3
- "version": "2.0.0",
3
+ "version": "2.0.2",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "scripts": {
@@ -25,11 +25,11 @@
25
25
  "rimraf": "^2.7.1"
26
26
  },
27
27
  "dependencies": {
28
- "@canopycanopycanopy/b-ber-grammar-attributes": "2.0.0",
29
- "@canopycanopycanopy/b-ber-lib": "2.0.0",
30
- "@canopycanopycanopy/b-ber-logger": "2.0.0",
31
- "@canopycanopycanopy/b-ber-parser-section": "2.0.0",
32
- "@canopycanopycanopy/b-ber-shapes-directives": "2.0.0",
28
+ "@canopycanopycanopy/b-ber-grammar-attributes": "2.0.2",
29
+ "@canopycanopycanopy/b-ber-lib": "2.0.2",
30
+ "@canopycanopycanopy/b-ber-logger": "2.0.2",
31
+ "@canopycanopycanopy/b-ber-parser-section": "2.0.2",
32
+ "@canopycanopycanopy/b-ber-shapes-directives": "2.0.2",
33
33
  "lodash": "^4.17.21",
34
34
  "lodash.has": "latest",
35
35
  "lodash.isundefined": "^3.0.1",
@@ -52,5 +52,5 @@
52
52
  "url": "https://maxwellsimmer.com"
53
53
  }
54
54
  ],
55
- "gitHead": "dbeae192709705f5bc211195ff343cbd999f9caf"
55
+ "gitHead": "9b13185f21f602f8a2bf3a4cf503b1fd644d6432"
56
56
  }