@canopycanopycanopy/b-ber-grammar-section 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 -49
- package/package.json +8 -8
package/dist/index.js
CHANGED
|
@@ -1,89 +1,60 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
var _Object$keys = require("@babel/runtime-corejs3/core-js-stable/object/keys");
|
|
4
|
-
|
|
5
4
|
var _Object$getOwnPropertySymbols = require("@babel/runtime-corejs3/core-js-stable/object/get-own-property-symbols");
|
|
6
|
-
|
|
7
5
|
var _filterInstanceProperty = require("@babel/runtime-corejs3/core-js-stable/instance/filter");
|
|
8
|
-
|
|
9
6
|
var _Object$getOwnPropertyDescriptor = require("@babel/runtime-corejs3/core-js-stable/object/get-own-property-descriptor");
|
|
10
|
-
|
|
11
7
|
var _forEachInstanceProperty = require("@babel/runtime-corejs3/core-js-stable/instance/for-each");
|
|
12
|
-
|
|
13
8
|
var _Object$getOwnPropertyDescriptors = require("@babel/runtime-corejs3/core-js-stable/object/get-own-property-descriptors");
|
|
14
|
-
|
|
15
9
|
var _Object$defineProperties = require("@babel/runtime-corejs3/core-js-stable/object/define-properties");
|
|
16
|
-
|
|
17
10
|
var _Object$defineProperty = require("@babel/runtime-corejs3/core-js-stable/object/define-property");
|
|
18
|
-
|
|
19
11
|
var _interopRequireDefault = require("@babel/runtime-corejs3/helpers/interopRequireDefault");
|
|
20
|
-
|
|
21
12
|
_Object$defineProperty(exports, "__esModule", {
|
|
22
13
|
value: true
|
|
23
14
|
});
|
|
24
|
-
|
|
25
15
|
exports.default = void 0;
|
|
26
|
-
|
|
27
16
|
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime-corejs3/helpers/defineProperty"));
|
|
28
|
-
|
|
29
17
|
var _from = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/array/from"));
|
|
30
|
-
|
|
31
18
|
var _map = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/instance/map"));
|
|
32
|
-
|
|
33
19
|
var _trim = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/instance/trim"));
|
|
34
|
-
|
|
35
20
|
var _lodash = _interopRequireDefault(require("lodash.find"));
|
|
36
|
-
|
|
37
21
|
var _State = _interopRequireDefault(require("@canopycanopycanopy/b-ber-lib/State"));
|
|
38
|
-
|
|
39
22
|
var _bBerLib = require("@canopycanopycanopy/b-ber-lib");
|
|
40
|
-
|
|
41
23
|
var _bBerShapesDirectives = require("@canopycanopycanopy/b-ber-shapes-directives");
|
|
42
|
-
|
|
43
24
|
var _bBerLogger = _interopRequireDefault(require("@canopycanopycanopy/b-ber-logger"));
|
|
44
|
-
|
|
45
25
|
var _bBerParserSection = _interopRequireDefault(require("@canopycanopycanopy/b-ber-parser-section"));
|
|
46
|
-
|
|
47
26
|
var _bBerGrammarRenderer = _interopRequireDefault(require("@canopycanopycanopy/b-ber-grammar-renderer"));
|
|
48
|
-
|
|
49
27
|
var _bBerGrammarAttributes = require("@canopycanopycanopy/b-ber-grammar-attributes");
|
|
50
|
-
|
|
51
28
|
function ownKeys(object, enumerableOnly) { var keys = _Object$keys(object); if (_Object$getOwnPropertySymbols) { var symbols = _Object$getOwnPropertySymbols(object); enumerableOnly && (symbols = _filterInstanceProperty(symbols).call(symbols, function (sym) { return _Object$getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
52
|
-
|
|
53
29
|
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var _context2, _context3; var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? _forEachInstanceProperty(_context2 = ownKeys(Object(source), !0)).call(_context2, function (key) { (0, _defineProperty2.default)(target, key, source[key]); }) : _Object$getOwnPropertyDescriptors ? _Object$defineProperties(target, _Object$getOwnPropertyDescriptors(source)) : _forEachInstanceProperty(_context3 = ownKeys(Object(source))).call(_context3, function (key) { _Object$defineProperty(target, key, _Object$getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
54
|
-
|
|
55
30
|
// This matches *all* container-type directives, and outputs the appropriate
|
|
56
31
|
// HTML based on user-defined attributes
|
|
57
|
-
const containers = (0, _from.default)(_bBerShapesDirectives.BLOCK_DIRECTIVES).join('|');
|
|
32
|
+
const containers = (0, _from.default)(_bBerShapesDirectives.BLOCK_DIRECTIVES).join('|');
|
|
58
33
|
|
|
34
|
+
// Treat `exit` like an opening marker
|
|
59
35
|
const MARKER_OPEN_RE = new RegExp(`^(${containers}|exit)(?::([^\\s]+)(\\s.*)?)?$`);
|
|
60
|
-
const MARKER_CLOSE_RE = /(exit)(?::([^\s]+))?/;
|
|
36
|
+
const MARKER_CLOSE_RE = /(exit)(?::([^\s]+))?/;
|
|
37
|
+
|
|
38
|
+
// `context` must be available in this `render` method and is passed
|
|
61
39
|
// into `createRenderer` below. Default for `context` is set for use
|
|
62
40
|
// during tests
|
|
63
41
|
|
|
64
42
|
function isGallery(directive) {
|
|
65
43
|
return directive && directive.type === 'gallery' && (_State.default.build === 'web' || _State.default.build === 'reader');
|
|
66
44
|
}
|
|
67
|
-
|
|
68
45
|
function isSpread(directive) {
|
|
69
46
|
return directive && directive.type === 'spread' && (_State.default.build === 'web' || _State.default.build === 'reader');
|
|
70
47
|
}
|
|
71
|
-
|
|
72
48
|
function handleExitDirective(token) {
|
|
73
49
|
const [, type, id] = token;
|
|
74
|
-
|
|
75
50
|
_bBerLogger.default.debug(`exit directive [${id}]`);
|
|
76
|
-
|
|
77
51
|
const comment = _bBerLib.Html.comment(`END: section:${type}#${(0, _bBerGrammarAttributes.htmlId)(id)}`);
|
|
78
|
-
|
|
79
52
|
const directive = (0, _lodash.default)(_State.default.cursor, {
|
|
80
53
|
id
|
|
81
54
|
});
|
|
82
|
-
|
|
83
55
|
_State.default.remove('cursor', {
|
|
84
56
|
id
|
|
85
57
|
});
|
|
86
|
-
|
|
87
58
|
if (isGallery(directive)) {
|
|
88
59
|
// prettier-ignore
|
|
89
60
|
return `</div>
|
|
@@ -91,7 +62,6 @@ function handleExitDirective(token) {
|
|
|
91
62
|
</div>
|
|
92
63
|
</section>${comment}`;
|
|
93
64
|
}
|
|
94
|
-
|
|
95
65
|
if (isSpread(directive)) {
|
|
96
66
|
return `</div>
|
|
97
67
|
</div>
|
|
@@ -101,65 +71,58 @@ function handleExitDirective(token) {
|
|
|
101
71
|
|
|
102
72
|
${comment}`;
|
|
103
73
|
}
|
|
104
|
-
|
|
105
74
|
return `</section>${comment}`;
|
|
106
75
|
}
|
|
107
|
-
|
|
108
76
|
function openElement(token, fileName, lineNumber) {
|
|
109
77
|
// Destructure the attributes from matches, omitting `matches[0]` since
|
|
110
78
|
// we're only interested in the captures
|
|
111
79
|
const [, type, id, attr] = token;
|
|
112
|
-
|
|
113
80
|
_bBerLogger.default.debug(`open directive [${id}]`);
|
|
114
|
-
|
|
115
81
|
const comment = _bBerLib.Html.comment(`START: section:${type}#${(0, _bBerGrammarAttributes.htmlId)(id)}; ${fileName}:${lineNumber}`);
|
|
116
|
-
|
|
117
82
|
const attrs = (0, _bBerGrammarAttributes.attributes)(attr, type, {
|
|
118
83
|
fileName,
|
|
119
84
|
lineNumber
|
|
120
85
|
});
|
|
121
86
|
return `${comment}<section id="${(0, _bBerGrammarAttributes.htmlId)(id)}"${attrs}>`;
|
|
122
87
|
}
|
|
123
|
-
|
|
124
88
|
function closeElement(marker) {
|
|
125
89
|
// tokens `nesting` prop is -1. we should be closing the html element
|
|
126
90
|
// here, but probably have done so above since we're treating `exit`
|
|
127
91
|
// directives as openers. check to see if the element has in fact been
|
|
128
92
|
// closed
|
|
93
|
+
|
|
129
94
|
const token = marker.split(':');
|
|
130
95
|
if (token.length < 2) return '';
|
|
131
96
|
const [, id] = token;
|
|
132
97
|
if (!_State.default.contains('cursor', {
|
|
133
98
|
id
|
|
134
|
-
})) return '';
|
|
99
|
+
})) return '';
|
|
135
100
|
|
|
101
|
+
// its id still exists in state, so it's open. force close here
|
|
136
102
|
const comment = _bBerLib.Html.comment(`END: section:#${(0, _bBerGrammarAttributes.htmlId)(id)}`);
|
|
103
|
+
const result = `</section>${comment}`;
|
|
137
104
|
|
|
138
|
-
|
|
139
|
-
|
|
105
|
+
// remove the id
|
|
140
106
|
_State.default.remove('cursor', {
|
|
141
107
|
id
|
|
142
108
|
});
|
|
143
|
-
|
|
144
109
|
return result;
|
|
145
110
|
}
|
|
146
|
-
|
|
147
111
|
const render = ({
|
|
148
112
|
context = {}
|
|
149
113
|
}) => (tokens, index) => {
|
|
150
114
|
var _context;
|
|
151
|
-
|
|
152
115
|
const token = tokens[index];
|
|
153
116
|
const lineNumber = (0, _map.default)(token) ? (0, _map.default)(token)[0] : null;
|
|
154
117
|
const fileName = `_markdown/${context.fileName}.md`;
|
|
155
118
|
const marker = (0, _trim.default)(_context = token.info).call(_context);
|
|
156
|
-
if (token.nesting !== 1) return closeElement(marker);
|
|
119
|
+
if (token.nesting !== 1) return closeElement(marker);
|
|
157
120
|
|
|
121
|
+
// token open, we ignore closing tokens and let `exit` handle those
|
|
158
122
|
const tokenClose = marker.match(MARKER_CLOSE_RE);
|
|
159
123
|
const tokenOpen = marker.match(MARKER_OPEN_RE);
|
|
160
124
|
return tokenClose ? handleExitDirective(tokenClose) : openElement(tokenOpen, fileName, lineNumber);
|
|
161
125
|
};
|
|
162
|
-
|
|
163
126
|
var _default = {
|
|
164
127
|
plugin: _bBerParserSection.default,
|
|
165
128
|
name: 'section',
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@canopycanopycanopy/b-ber-grammar-section",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.2",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -25,12 +25,12 @@
|
|
|
25
25
|
"rimraf": "^2.7.1"
|
|
26
26
|
},
|
|
27
27
|
"dependencies": {
|
|
28
|
-
"@canopycanopycanopy/b-ber-grammar-attributes": "2.0.
|
|
29
|
-
"@canopycanopycanopy/b-ber-grammar-renderer": "2.0.
|
|
30
|
-
"@canopycanopycanopy/b-ber-lib": "2.0.
|
|
31
|
-
"@canopycanopycanopy/b-ber-logger": "2.0.
|
|
32
|
-
"@canopycanopycanopy/b-ber-parser-section": "2.0.
|
|
33
|
-
"@canopycanopycanopy/b-ber-shapes-directives": "2.0.
|
|
28
|
+
"@canopycanopycanopy/b-ber-grammar-attributes": "2.0.2",
|
|
29
|
+
"@canopycanopycanopy/b-ber-grammar-renderer": "2.0.2",
|
|
30
|
+
"@canopycanopycanopy/b-ber-lib": "2.0.2",
|
|
31
|
+
"@canopycanopycanopy/b-ber-logger": "2.0.2",
|
|
32
|
+
"@canopycanopycanopy/b-ber-parser-section": "2.0.2",
|
|
33
|
+
"@canopycanopycanopy/b-ber-shapes-directives": "2.0.2",
|
|
34
34
|
"lodash": "^4.17.21",
|
|
35
35
|
"lodash.find": "latest",
|
|
36
36
|
"tar": "^6.1.11"
|
|
@@ -52,5 +52,5 @@
|
|
|
52
52
|
"url": "https://maxwellsimmer.com"
|
|
53
53
|
}
|
|
54
54
|
],
|
|
55
|
-
"gitHead": "
|
|
55
|
+
"gitHead": "9b13185f21f602f8a2bf3a4cf503b1fd644d6432"
|
|
56
56
|
}
|