@canopycanopycanopy/b-ber-parser-gallery 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.
- package/dist/index.js +12 -33
- package/package.json +7 -7
package/dist/index.js
CHANGED
|
@@ -1,29 +1,18 @@
|
|
|
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 _filter = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/instance/filter"));
|
|
14
|
-
|
|
15
10
|
var _forEach = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/instance/for-each"));
|
|
16
|
-
|
|
17
11
|
var _slice = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/instance/slice"));
|
|
18
|
-
|
|
19
12
|
var _path = _interopRequireDefault(require("path"));
|
|
20
|
-
|
|
21
13
|
var _State = _interopRequireDefault(require("@canopycanopycanopy/b-ber-lib/State"));
|
|
22
|
-
|
|
23
14
|
var _mimeTypes = _interopRequireDefault(require("mime-types"));
|
|
24
|
-
|
|
25
15
|
var _bBerGrammarAttributes = require("@canopycanopycanopy/b-ber-grammar-attributes");
|
|
26
|
-
|
|
27
16
|
/* eslint-disable no-param-reassign,no-continue */
|
|
28
17
|
|
|
29
18
|
/*!
|
|
@@ -31,6 +20,7 @@ An adapted version of markdown-it-container 2.0.0
|
|
|
31
20
|
https://github.com//markdown-it/markdown-it-container
|
|
32
21
|
MIT license
|
|
33
22
|
*/
|
|
23
|
+
|
|
34
24
|
const addCaption = (md, t, attrs) => {
|
|
35
25
|
if (!attrs.caption) return;
|
|
36
26
|
t.children.push({
|
|
@@ -53,7 +43,6 @@ const addCaption = (md, t, attrs) => {
|
|
|
53
43
|
nesting: -1
|
|
54
44
|
});
|
|
55
45
|
};
|
|
56
|
-
|
|
57
46
|
const createImageElement = (tok, attrs) => {
|
|
58
47
|
tok.content = '';
|
|
59
48
|
tok.children.push({
|
|
@@ -63,10 +52,8 @@ const createImageElement = (tok, attrs) => {
|
|
|
63
52
|
nesting: 0
|
|
64
53
|
});
|
|
65
54
|
};
|
|
66
|
-
|
|
67
55
|
const createMediaElement = (tok, attrs) => {
|
|
68
56
|
var _context;
|
|
69
|
-
|
|
70
57
|
const media = [..._State.default[attrs.type]];
|
|
71
58
|
const supportedMediaAttrs = {
|
|
72
59
|
audio: ['controls', 'loop'],
|
|
@@ -74,8 +61,9 @@ const createMediaElement = (tok, attrs) => {
|
|
|
74
61
|
};
|
|
75
62
|
const sources = (0, _filter.default)(media).call(media, a => (0, _bBerGrammarAttributes.toAlias)(a) === attrs.source);
|
|
76
63
|
const mediaAttrs = [[`data-${attrs.type}`, (0, _bBerGrammarAttributes.htmlId)(attrs.source)]];
|
|
77
|
-
if (attrs.poster) mediaAttrs.push(['poster', `../images/${attrs.poster}`]);
|
|
64
|
+
if (attrs.poster) mediaAttrs.push(['poster', `../images/${attrs.poster}`]);
|
|
78
65
|
|
|
66
|
+
// add boolean attrs
|
|
79
67
|
(0, _forEach.default)(_context = supportedMediaAttrs[attrs.type]).call(_context, a => {
|
|
80
68
|
if (attrs[a]) mediaAttrs.push([a, a]);
|
|
81
69
|
});
|
|
@@ -115,7 +103,6 @@ const createMediaElement = (tok, attrs) => {
|
|
|
115
103
|
nesting: -1
|
|
116
104
|
});
|
|
117
105
|
};
|
|
118
|
-
|
|
119
106
|
const containerPlugin = (md, name, options = {}) => {
|
|
120
107
|
const minMarkers = options.minMarkers || 3;
|
|
121
108
|
const markerStr = options.marker || ':';
|
|
@@ -125,10 +112,8 @@ const containerPlugin = (md, name, options = {}) => {
|
|
|
125
112
|
validateOpen,
|
|
126
113
|
render
|
|
127
114
|
} = options;
|
|
128
|
-
|
|
129
115
|
function container(state, startLine, endLine, silent) {
|
|
130
116
|
var _context2, _context3, _context4, _context5;
|
|
131
|
-
|
|
132
117
|
const lineNumber = startLine + 1;
|
|
133
118
|
let pos;
|
|
134
119
|
let nextLine;
|
|
@@ -136,14 +121,14 @@ const containerPlugin = (md, name, options = {}) => {
|
|
|
136
121
|
let autoClosed = false;
|
|
137
122
|
let start = state.bMarks[startLine] + state.tShift[startLine];
|
|
138
123
|
let max = state.eMarks[startLine];
|
|
139
|
-
if (markerChar !== state.src.charCodeAt(start)) return false;
|
|
124
|
+
if (markerChar !== state.src.charCodeAt(start)) return false;
|
|
140
125
|
|
|
126
|
+
// Check out the rest of the marker string, i.e., count the number of markers
|
|
141
127
|
for (pos = start + 1; pos <= max; pos++) {
|
|
142
128
|
if (markerStr[(pos - start) % markerLen] !== state.src[pos]) {
|
|
143
129
|
break;
|
|
144
130
|
}
|
|
145
131
|
}
|
|
146
|
-
|
|
147
132
|
const markerCount = Math.floor((pos - start) / markerLen);
|
|
148
133
|
if (markerCount < minMarkers) return false;
|
|
149
134
|
pos -= (pos - start) % markerLen;
|
|
@@ -152,8 +137,9 @@ const containerPlugin = (md, name, options = {}) => {
|
|
|
152
137
|
if (!validateOpen(params, lineNumber)) return false;
|
|
153
138
|
if (silent) return true; // for testing validation
|
|
154
139
|
|
|
155
|
-
nextLine = startLine;
|
|
140
|
+
nextLine = startLine;
|
|
156
141
|
|
|
142
|
+
// look for closing block
|
|
157
143
|
for (;;) {
|
|
158
144
|
nextLine += 1;
|
|
159
145
|
if (nextLine >= endLine) break; // unclosed block is autoclosed by end of document
|
|
@@ -161,17 +147,16 @@ const containerPlugin = (md, name, options = {}) => {
|
|
|
161
147
|
start = state.bMarks[nextLine] + state.tShift[nextLine];
|
|
162
148
|
max = state.eMarks[nextLine];
|
|
163
149
|
if (state.sCount[nextLine] - state.blkIndent >= 4) continue; // closing fence must be indented less than 4 spaces
|
|
164
|
-
|
|
165
150
|
if (Math.floor((pos - start) / markerLen) < markerCount) continue;
|
|
166
151
|
if (pos < max) continue;
|
|
167
152
|
autoClosed = true;
|
|
168
153
|
break;
|
|
169
154
|
}
|
|
170
|
-
|
|
171
155
|
const oldParent = state.parentType;
|
|
172
156
|
const oldLineMax = state.lineMax;
|
|
173
|
-
state.parentType = 'container';
|
|
157
|
+
state.parentType = 'container';
|
|
174
158
|
|
|
159
|
+
// this will prevent lazy continuations from ever going past our end marker
|
|
175
160
|
state.lineMax = nextLine;
|
|
176
161
|
token = state.push(`container_${name}_open`, 'div', 1);
|
|
177
162
|
token.markup = markup;
|
|
@@ -184,17 +169,16 @@ const containerPlugin = (md, name, options = {}) => {
|
|
|
184
169
|
token.block = true;
|
|
185
170
|
state.parentType = oldParent;
|
|
186
171
|
state.lineMax = oldLineMax;
|
|
187
|
-
state.line = nextLine + (autoClosed ? 1 : 0);
|
|
188
|
-
// set a flag so that we don't render other directives' children which may use the same syntax
|
|
172
|
+
state.line = nextLine + (autoClosed ? 1 : 0);
|
|
189
173
|
|
|
174
|
+
// parse child tokens
|
|
175
|
+
// set a flag so that we don't render other directives' children which may use the same syntax
|
|
190
176
|
let childOfGallery = false;
|
|
191
177
|
(0, _forEach.default)(_context5 = state.tokens).call(_context5, (tok, i) => {
|
|
192
178
|
if (tok.type === 'container_gallery_open') childOfGallery = true;
|
|
193
179
|
if (tok.type === 'container_gallery_close') childOfGallery = false;
|
|
194
|
-
|
|
195
180
|
if (tok.type === 'inline' && childOfGallery) {
|
|
196
181
|
const matchedContent = tok.content.match(/^(::\s?(.+)\s?::)/);
|
|
197
|
-
|
|
198
182
|
if (matchedContent) {
|
|
199
183
|
const attrs = (0, _bBerGrammarAttributes.parseAttrs)(matchedContent[1]);
|
|
200
184
|
const prev = state.tokens[i - 1];
|
|
@@ -203,19 +187,16 @@ const containerPlugin = (md, name, options = {}) => {
|
|
|
203
187
|
prev.attrSet('class', 'gallery__item');
|
|
204
188
|
prev.attrSet('data-gallery-item', attrs.item);
|
|
205
189
|
next.tag = 'div';
|
|
206
|
-
|
|
207
190
|
switch (attrs.type) {
|
|
208
191
|
case 'image':
|
|
209
192
|
createImageElement(tok, attrs);
|
|
210
193
|
addCaption(md, tok, attrs);
|
|
211
194
|
break;
|
|
212
|
-
|
|
213
195
|
case 'video':
|
|
214
196
|
case 'audio':
|
|
215
197
|
createMediaElement(tok, attrs);
|
|
216
198
|
addCaption(md, tok, attrs);
|
|
217
199
|
break;
|
|
218
|
-
|
|
219
200
|
default:
|
|
220
201
|
break;
|
|
221
202
|
}
|
|
@@ -224,13 +205,11 @@ const containerPlugin = (md, name, options = {}) => {
|
|
|
224
205
|
});
|
|
225
206
|
return true;
|
|
226
207
|
}
|
|
227
|
-
|
|
228
208
|
md.block.ruler.before('fence', `container_${name}`, container, {
|
|
229
209
|
alt: ['paragraph', 'reference', 'blockquote']
|
|
230
210
|
});
|
|
231
211
|
md.renderer.rules[`container_${name}_open`] = render;
|
|
232
212
|
md.renderer.rules[`container_${name}_close`] = render;
|
|
233
213
|
};
|
|
234
|
-
|
|
235
214
|
var _default = containerPlugin;
|
|
236
215
|
exports.default = _default;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@canopycanopycanopy/b-ber-parser-gallery",
|
|
3
|
-
"version": "2.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.
|
|
29
|
-
"@canopycanopycanopy/b-ber-lib": "2.0.
|
|
30
|
-
"@canopycanopycanopy/b-ber-logger": "2.0.
|
|
31
|
-
"@canopycanopycanopy/b-ber-shapes-directives": "2.0.
|
|
32
|
-
"@canopycanopycanopy/b-ber-templates": "2.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-shapes-directives": "2.0.2",
|
|
32
|
+
"@canopycanopycanopy/b-ber-templates": "2.0.2",
|
|
33
33
|
"lodash": "^4.17.21",
|
|
34
34
|
"mime-types": "^2.1.24",
|
|
35
35
|
"tar": "^6.1.11"
|
|
@@ -51,5 +51,5 @@
|
|
|
51
51
|
"url": "https://maxwellsimmer.com"
|
|
52
52
|
}
|
|
53
53
|
],
|
|
54
|
-
"gitHead": "
|
|
54
|
+
"gitHead": "9b13185f21f602f8a2bf3a4cf503b1fd644d6432"
|
|
55
55
|
}
|