@adobe/helix-markdown-support 3.1.7 → 3.1.8

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/CHANGELOG.md CHANGED
@@ -1,3 +1,10 @@
1
+ ## [3.1.8](https://github.com/adobe/helix-markdown-support/compare/v3.1.7...v3.1.8) (2022-07-28)
2
+
3
+
4
+ ### Bug Fixes
5
+
6
+ * matter plugin to run in micromark development mode ([#80](https://github.com/adobe/helix-markdown-support/issues/80)) ([36e69fa](https://github.com/adobe/helix-markdown-support/commit/36e69fa8328850950969597e074b7b610d40f0c9))
7
+
1
8
  ## [3.1.7](https://github.com/adobe/helix-markdown-support/compare/v3.1.6...v3.1.7) (2022-07-09)
2
9
 
3
10
 
package/package.json CHANGED
@@ -1,10 +1,10 @@
1
1
  {
2
2
  "name": "@adobe/helix-markdown-support",
3
- "version": "3.1.7",
3
+ "version": "3.1.8",
4
4
  "description": "Helix Markdown Support",
5
5
  "type": "module",
6
6
  "scripts": {
7
- "test": " c8 mocha",
7
+ "test": "c8 mocha",
8
8
  "test-ci": "c8 mocha && codecov",
9
9
  "lint": "eslint .",
10
10
  "semantic-release": "semantic-release",
@@ -25,6 +25,8 @@
25
25
  "hast-util-to-html": "8.0.3",
26
26
  "js-yaml": "4.1.0",
27
27
  "mdast-util-to-hast": "12.1.2",
28
+ "micromark-util-character": "1.1.0",
29
+ "micromark-util-symbol": "1.0.1",
28
30
  "unist-util-find": "1.0.2",
29
31
  "unist-util-visit": "4.1.0"
30
32
  },
@@ -32,7 +34,8 @@
32
34
  "spec": "test/**/*.test.js",
33
35
  "recursive": "true",
34
36
  "reporter": "mocha-multi-reporters",
35
- "reporter-options": "configFile=.mocha-multi.json"
37
+ "reporter-options": "configFile=.mocha-multi.json",
38
+ "node-option": "conditions=development"
36
39
  },
37
40
  "peerDependencies": {
38
41
  "unified": "10.x"
@@ -41,13 +44,13 @@
41
44
  "@adobe/eslint-config-helix": "1.3.2",
42
45
  "@semantic-release/changelog": "6.0.1",
43
46
  "@semantic-release/git": "10.0.1",
44
- "c8": "7.11.3",
47
+ "c8": "7.12.0",
45
48
  "codecov": "3.8.3",
46
- "eslint": "8.19.0",
49
+ "eslint": "8.20.0",
47
50
  "eslint-plugin-header": "3.1.1",
48
51
  "eslint-plugin-import": "2.26.0",
49
52
  "husky": "8.0.1",
50
- "junit-report-builder": "3.0.0",
53
+ "junit-report-builder": "3.0.1",
51
54
  "lint-staged": "13.0.3",
52
55
  "mdast-builder": "1.1.1",
53
56
  "mocha": "10.0.0",
@@ -57,7 +60,7 @@
57
60
  "remark-stringify": "10.0.2",
58
61
  "semantic-release": "19.0.3",
59
62
  "unified": "10.1.2",
60
- "unist-util-inspect": "7.0.0"
63
+ "unist-util-inspect": "7.0.1"
61
64
  },
62
65
  "lint-staged": {
63
66
  "*.js": "eslint"
@@ -11,11 +11,12 @@
11
11
  */
12
12
  /* eslint-disable no-use-before-define */
13
13
  import jsYaml from 'js-yaml';
14
+ import { codes } from 'micromark-util-symbol/codes.js';
15
+ import { types } from 'micromark-util-symbol/types.js';
16
+ import { markdownLineEnding, markdownSpace } from 'micromark-util-character';
14
17
 
15
18
  const type = (v) => ((v !== undefined && v !== null) ? v.constructor : v);
16
19
 
17
- const CODE_DASH = '-'.charCodeAt(0);
18
-
19
20
  function validYaml(str, errorHandler) {
20
21
  // console.log('validate yaml', str);
21
22
  try {
@@ -49,9 +50,9 @@ function validYaml(str, errorHandler) {
49
50
  }
50
51
 
51
52
  function parse(options) {
52
- const valueType = 'yamlValue';
53
- const fenceType = 'yamlFence';
54
- const sequenceType = 'yamlSequence';
53
+ const yamlValue = 'yamlValue';
54
+ const yamlFence = 'yamlFence';
55
+ const yamlSequence = 'yamlSequence';
55
56
  const { errorHandler } = options;
56
57
 
57
58
  const fenceConstruct = {
@@ -102,20 +103,20 @@ function parse(options) {
102
103
  function lineStart(code) {
103
104
  // set the whitespace flag to true
104
105
  wasWS = true;
105
- if (code === -5 || code === -4 || code === -3 || code === null) {
106
+ if (code === codes.eof || markdownLineEnding(code)) {
106
107
  return lineEnd(code);
107
108
  }
108
- effects.enter(valueType);
109
+ effects.enter(yamlValue);
109
110
  return lineData(code);
110
111
  }
111
112
 
112
113
  function lineData(code) {
113
- if (code === -5 || code === -4 || code === -3 || code === null) {
114
- effects.exit(valueType);
114
+ if (code === codes.eof || markdownLineEnding(code)) {
115
+ effects.exit(yamlValue);
115
116
  return lineEnd(code);
116
117
  }
117
118
 
118
- if (!(code === -2 || code === -1 || code === 32)) {
119
+ if (!markdownSpace(code)) {
119
120
  // if not whitespace, clear flag
120
121
  wasWS = false;
121
122
  }
@@ -125,40 +126,7 @@ function parse(options) {
125
126
  }
126
127
 
127
128
  function closedFence(code) {
128
- // if we are at the end, don't check for empty line after
129
- if (code === null) {
130
- return afterClosedFence(code);
131
- }
132
-
133
- // remember new line
134
- effects.enter('lineEnding');
135
- effects.consume(code);
136
- effects.exit('lineEnding');
137
-
138
- // this is a bit a hack to avoid create soo many states
139
- wasWS = false;
140
-
141
- return afterClosedFence;
142
- }
143
-
144
- function afterClosedFence(code) {
145
- // check for whitespace
146
- if (code === -2 || code === -1 || code === 32) {
147
- if (!wasWS) {
148
- effects.enter('whitespace');
149
- wasWS = true;
150
- }
151
- effects.consume(code);
152
- return afterClosedFence;
153
- } else if (wasWS) {
154
- effects.exit('whitespace');
155
- wasWS = false;
156
- }
157
-
158
- if (code !== -5 && code !== -4 && code !== -3 && code !== null) {
159
- return nok(code);
160
- }
161
-
129
+ // check if valid yaml
162
130
  const token = effects.exit('yaml');
163
131
  let yamlString = self.sliceSerialize(token).trim();
164
132
  // remove fences
@@ -167,18 +135,20 @@ function parse(options) {
167
135
  return nok(code);
168
136
  }
169
137
 
170
- if (code !== null) {
171
- // since there is a blank line after the `---`, also mark it.
172
- effects.enter('lineEndingBlank');
173
- effects.exit('lineEndingBlank');
138
+ // if we are at the end, don't check for empty line after
139
+ if (code === codes.eof) {
140
+ return ok(code);
174
141
  }
175
142
 
176
- return ok(code);
143
+ return effects.check({
144
+ tokenize: tokenizeEmptyLine,
145
+ partial: true,
146
+ }, ok, nok)(code);
177
147
  }
178
148
 
179
149
  function lineEnd(code) {
180
150
  // Require a closing fence.
181
- if (code === null) {
151
+ if (code === codes.eof) {
182
152
  return nok(code);
183
153
  }
184
154
 
@@ -196,9 +166,9 @@ function parse(options) {
196
166
  }
197
167
 
198
168
  // Can only be an eol.
199
- effects.enter('lineEnding');
169
+ effects.enter(types.lineEnding);
200
170
  effects.consume(code);
201
- effects.exit('lineEnding');
171
+ effects.exit(types.lineEnding);
202
172
 
203
173
  // attempt to detect the closing fence `---`. if not, start next line
204
174
  return effects.attempt(fenceConstruct, closedFence, lineStart);
@@ -211,9 +181,9 @@ function parse(options) {
211
181
  return start;
212
182
 
213
183
  function start(code) {
214
- if (code === CODE_DASH) {
215
- effects.enter(fenceType);
216
- effects.enter(sequenceType);
184
+ if (code === codes.dash) {
185
+ effects.enter(yamlFence);
186
+ effects.enter(yamlSequence);
217
187
  return insideSequence(code);
218
188
  }
219
189
 
@@ -222,17 +192,17 @@ function parse(options) {
222
192
 
223
193
  function insideSequence(code) {
224
194
  if (numDashes === 3) {
225
- effects.exit(sequenceType);
195
+ effects.exit(yamlSequence);
226
196
 
227
- if (code === -2 || code === -1 || code === 32) {
228
- effects.enter('whitespace');
197
+ if (markdownSpace(code)) {
198
+ effects.enter(types.whitespace);
229
199
  return insideWhitespace(code);
230
200
  }
231
201
 
232
202
  return fenceEnd(code);
233
203
  }
234
204
 
235
- if (code === CODE_DASH) {
205
+ if (code === codes.dash) {
236
206
  effects.consume(code);
237
207
  numDashes += 1;
238
208
  return insideSequence;
@@ -243,30 +213,66 @@ function parse(options) {
243
213
 
244
214
  // white space after fence
245
215
  function insideWhitespace(code) {
246
- if (code === -2 || code === -1 || code === 32) {
216
+ if (markdownSpace(code)) {
247
217
  effects.consume(code);
248
218
  return insideWhitespace;
249
219
  }
250
220
 
251
- effects.exit('whitespace');
221
+ effects.exit(types.whitespace);
252
222
  return fenceEnd(code);
253
223
  }
254
224
 
255
225
  // after fence (plus potential ws) we expect a LF
256
226
  function fenceEnd(code) {
257
- if (code === -5 || code === -4 || code === -3 || code === null) {
258
- effects.exit(fenceType);
227
+ if (code === codes.eof || markdownLineEnding(code)) {
228
+ effects.exit(yamlFence);
259
229
  return ok(code);
260
230
  }
261
231
  return nok(code);
262
232
  }
263
233
  }
234
+
235
+ function tokenizeEmptyLine(effects, ok, nok) {
236
+ let wasWS = false;
237
+
238
+ return start;
239
+
240
+ /**
241
+ * after the closed fence, we either need EOF or an empty line.
242
+ */
243
+ function start(code) {
244
+ // always eol
245
+ effects.enter(types.lineEnding);
246
+ effects.consume(code);
247
+ effects.exit(types.lineEnding);
248
+ return emptyLines;
249
+ }
250
+
251
+ function emptyLines(code) {
252
+ if (code === codes.eof || markdownLineEnding(code)) {
253
+ return ok(code);
254
+ }
255
+ // check for whitespace
256
+ if (markdownSpace(code)) {
257
+ if (!wasWS) {
258
+ effects.enter(types.whitespace);
259
+ wasWS = true;
260
+ }
261
+ effects.consume(code);
262
+ return emptyLines;
263
+ }
264
+ if (wasWS) {
265
+ effects.exit(types.whitespace);
266
+ }
267
+ return nok(code);
268
+ }
269
+ }
264
270
  }
265
271
 
266
272
  export default function create(options = {}) {
267
273
  return {
268
274
  flow: {
269
- [CODE_DASH]: [parse(options)],
275
+ [codes.dash]: [parse(options)],
270
276
  },
271
277
  };
272
278
  }