@canopycanopycanopy/b-ber-parser-figure 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 +34 -48
  2. package/package.json +6 -6
package/dist/index.js CHANGED
@@ -1,82 +1,68 @@
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 _slice = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/instance/slice"));
14
-
15
10
  var _indexOf = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/instance/index-of"));
16
-
17
11
  var _lodash = _interopRequireDefault(require("lodash.isundefined"));
18
-
19
12
  /* eslint-disable no-param-reassign */
13
+
20
14
  const figurePlugin = (md, name, options = {}) => {
21
- const minMarkers =
22
- /*options.minMarkers || */
23
- 3;
24
- const markerStr =
25
- /*options.marker || */
26
- ':';
15
+ const minMarkers = /*options.minMarkers || */3;
16
+ const markerStr = /*options.marker || */':';
27
17
  const markerChar = markerStr.charCodeAt(0);
28
18
  const markerLen = markerStr.length;
29
19
  const {
30
20
  validate,
31
21
  render
32
22
  } = options;
33
-
34
23
  function container(state, startLine, endLine, silent) {
35
24
  var _context, _context2;
36
-
37
25
  const start = state.bMarks[startLine] + state.tShift[startLine];
38
26
  const max = state.eMarks[startLine];
39
27
  let pos;
40
28
  let nextLine;
41
- let token; // Check out the first character quickly,
42
- // this should filter out most of non-containers
29
+ let token;
43
30
 
44
- if (markerChar !== state.src.charCodeAt(start)) return false; // Check out the rest of the marker string
31
+ // Check out the first character quickly,
32
+ // this should filter out most of non-containers
33
+ if (markerChar !== state.src.charCodeAt(start)) return false;
45
34
 
35
+ // Check out the rest of the marker string
46
36
  for (pos = start + 1; pos <= max; pos++) {
47
37
  if (markerStr[(pos - start) % markerLen] !== state.src[pos]) {
48
38
  break;
49
39
  }
50
40
  }
51
-
52
41
  const markerCount = Math.floor((pos - start) / markerLen);
53
42
  if (markerCount < minMarkers) return false;
54
43
  pos -= (pos - start) % markerLen;
55
44
  const markup = (0, _slice.default)(_context = state.src).call(_context, start, pos);
56
45
  const params = (0, _slice.default)(_context2 = state.src).call(_context2, pos, max);
57
- if (!validate(params, state.line + 1)) return false; // Since start is found, we can report success here in validation mode
46
+ if (!validate(params, state.line + 1)) return false;
47
+
48
+ // Since start is found, we can report success here in validation mode
49
+ if (silent) return true;
58
50
 
59
- if (silent) return true; // Search for the end of the block
51
+ // Search for the end of the block
52
+ nextLine = startLine;
60
53
 
61
- nextLine = startLine; // check to see if the image is followed by a caption
54
+ // check to see if the image is followed by a caption
62
55
  // - increment to next line
63
56
  // - check chars at pos to see if they match caption start
64
57
  // if not, continue
65
58
 
66
59
  const _capMarkerLen = minMarkers - 1;
67
-
68
60
  let _capStartPos;
69
-
70
61
  let _capEndPos;
71
-
72
62
  let _capEndLine;
73
-
74
63
  let _fastForward;
75
-
76
64
  let _capBody;
77
-
78
65
  let _cursor;
79
-
80
66
  for (;;) {
81
67
  // images can either be self-closing (i.e., they close when another
82
68
  // directive begins, or the parser hits EOF), and can also contain
@@ -84,46 +70,46 @@ const figurePlugin = (md, name, options = {}) => {
84
70
  // directive.
85
71
  nextLine += 1;
86
72
  if (nextLine >= endLine) break; // EOF
73
+
87
74
  // we only check the following line for markers, so whitespace is
88
75
  // significant for image captions. this can be relaxed, but it's more
89
76
  // performant this way.
90
77
  //
91
78
  // there is no caption (open or close); exit and output only the markup
92
79
  // for figure
93
-
94
80
  if (state.src[state.bMarks[nextLine]].charCodeAt(0) !== markerChar) {
95
81
  break;
96
- } // capture the current character
97
-
82
+ }
98
83
 
99
- _cursor = state.bMarks[nextLine]; // this is sort of inelegant, but it's an easy way to fake a lookahead
84
+ // capture the current character
85
+ _cursor = state.bMarks[nextLine];
100
86
 
87
+ // this is sort of inelegant, but it's an easy way to fake a lookahead
101
88
  const _currChar = state.src[_cursor].charCodeAt(0);
89
+ const _nextChar = state.src[_cursor + 1].charCodeAt(0);
102
90
 
103
- const _nextChar = state.src[_cursor + 1].charCodeAt(0); // two markers on the next line mean that there's a caption
104
-
105
-
91
+ // two markers on the next line mean that there's a caption
106
92
  if (_currChar === markerChar && _nextChar === markerChar) {
107
93
  if ((0, _lodash.default)(_capStartPos)) {
108
94
  _capStartPos = _cursor + _capMarkerLen; // state the start index
109
95
  } else if (!(0, _lodash.default)(_capStartPos)) {
110
96
  // a caption is being captured, so we know we're still in the
111
97
  // opening image marker
98
+
112
99
  // eslint-disable-next-line
113
100
  _capEndPos = _cursor + 2 - _capMarkerLen; // state the end index
114
-
115
101
  _capEndLine = _cursor;
116
102
  break;
117
103
  }
118
104
  }
119
- } // then,
105
+ }
106
+
107
+ // then,
120
108
  // - slice the string from src at beginning and end
121
109
  // - add it to the image token so that it can be parsed in `render` method
122
110
 
123
-
124
111
  if (_capStartPos && _capEndPos) {
125
112
  var _context3, _context4;
126
-
127
113
  // we have both a beginning and end marker for the caption, so we can
128
114
  // advance the cursor for further parsing
129
115
  _capBody = (0, _slice.default)(_context3 = state.src).call(_context3, _capStartPos, _capEndPos);
@@ -132,30 +118,30 @@ const figurePlugin = (md, name, options = {}) => {
132
118
  // there's no caption, but we've advanced the cursor, so we just rewind
133
119
  // it to where it initially matched our image directive
134
120
  nextLine = startLine + 1;
135
- } // this will prevent lazy continuations from ever going past our end marker
136
- // state.lineMax = nextLine
137
-
121
+ }
138
122
 
123
+ // this will prevent lazy continuations from ever going past our end marker
124
+ // state.lineMax = nextLine
139
125
  token = state.push(`container_${name}_open`, 'div', 1);
140
126
  token.markup = markup;
141
127
  token.block = true;
142
128
  token.info = params;
143
129
  token.children = _capBody;
144
- token.map = [startLine, nextLine]; // add ending token since we're using a `container` plugin as an inline
130
+ token.map = [startLine, nextLine];
145
131
 
146
- token = state.push(`container_${name}_close`, 'div', -1); // then,
147
- // - increment the pointer to the caption end if applicable
132
+ // add ending token since we're using a `container` plugin as an inline
133
+ token = state.push(`container_${name}_close`, 'div', -1);
148
134
 
135
+ // then,
136
+ // - increment the pointer to the caption end if applicable
149
137
  state.line = _fastForward || nextLine;
150
138
  return true;
151
139
  }
152
-
153
140
  md.block.ruler.before('fence', `container_${name}`, container, {
154
141
  alt: ['paragraph', 'reference', 'blockquote']
155
142
  });
156
143
  md.renderer.rules[`container_${name}_open`] = render;
157
144
  md.renderer.rules[`container_${name}_close`] = render; // not used, but keeping things consistent
158
145
  };
159
-
160
146
  var _default = figurePlugin;
161
147
  exports.default = _default;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@canopycanopycanopy/b-ber-parser-figure",
3
- "version": "2.0.0",
3
+ "version": "2.0.2",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "scripts": {
@@ -25,10 +25,10 @@
25
25
  "rimraf": "^2.7.1"
26
26
  },
27
27
  "dependencies": {
28
- "@canopycanopycanopy/b-ber-lib": "2.0.0",
29
- "@canopycanopycanopy/b-ber-logger": "2.0.0",
30
- "@canopycanopycanopy/b-ber-shapes-directives": "2.0.0",
31
- "@canopycanopycanopy/b-ber-templates": "2.0.0",
28
+ "@canopycanopycanopy/b-ber-lib": "2.0.2",
29
+ "@canopycanopycanopy/b-ber-logger": "2.0.2",
30
+ "@canopycanopycanopy/b-ber-shapes-directives": "2.0.2",
31
+ "@canopycanopycanopy/b-ber-templates": "2.0.2",
32
32
  "lodash": "^4.17.21",
33
33
  "lodash.isundefined": "^3.0.1",
34
34
  "tar": "^6.1.11"
@@ -50,5 +50,5 @@
50
50
  "url": "https://maxwellsimmer.com"
51
51
  }
52
52
  ],
53
- "gitHead": "dbeae192709705f5bc211195ff343cbd999f9caf"
53
+ "gitHead": "9b13185f21f602f8a2bf3a4cf503b1fd644d6432"
54
54
  }