@khanacademy/simple-markdown 0.8.6 → 0.9.1
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/.eslintrc.js +1 -0
- package/CHANGELOG.md +12 -0
- package/dist/es/index.js +274 -511
- package/dist/es/index.js.map +1 -1
- package/dist/index.d.ts +187 -2
- package/dist/index.js +194 -244
- package/dist/index.js.flow +282 -2
- package/dist/index.js.map +1 -1
- package/package.json +3 -3
- package/src/__tests__/{simple-markdown_test.js → simple-markdown.test.ts} +39 -53
- package/src/{index.js → index.ts} +249 -187
- package/tsconfig.json +6 -68
- package/tsconfig.tsbuildinfo +1 -0
package/dist/es/index.js
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
/* eslint-disable prefer-spread, no-regex-spaces, no-unused-vars, guard-for-in, no-console, no-var */
|
|
2
|
-
|
|
1
|
+
/* eslint-disable prefer-spread, no-regex-spaces, @typescript-eslint/no-unused-vars, guard-for-in, no-console, no-var */
|
|
3
2
|
/**
|
|
4
3
|
* Simple-Markdown
|
|
5
4
|
* ===============
|
|
@@ -19,36 +18,37 @@
|
|
|
19
18
|
* Many of the regexes and original logic has been adapted from
|
|
20
19
|
* the wonderful [marked.js](https://github.com/chjj/marked)
|
|
21
20
|
*/
|
|
22
|
-
|
|
21
|
+
|
|
22
|
+
// Type Definitions:
|
|
23
|
+
|
|
23
24
|
// We want to clarify our defaultRules types a little bit more so clients can
|
|
24
25
|
// reuse defaultRules built-ins. So we make some stronger guarantess when
|
|
25
26
|
// we can:
|
|
27
|
+
|
|
26
28
|
// End Flow Definitions
|
|
29
|
+
|
|
27
30
|
var CR_NEWLINE_R = /\r\n?/g;
|
|
28
31
|
var TAB_R = /\t/g;
|
|
29
32
|
var FORMFEED_R = /\f/g;
|
|
33
|
+
|
|
30
34
|
/**
|
|
31
35
|
* Turn various whitespace into easy-to-process whitespace
|
|
32
36
|
*/
|
|
33
|
-
|
|
34
37
|
var preprocess = function preprocess(source) {
|
|
35
38
|
return source.replace(CR_NEWLINE_R, "\n").replace(FORMFEED_R, "").replace(TAB_R, " ");
|
|
36
39
|
};
|
|
37
|
-
|
|
38
40
|
var populateInitialState = function populateInitialState(givenState, defaultState) {
|
|
39
41
|
var state = givenState || {};
|
|
40
|
-
|
|
41
42
|
if (defaultState != null) {
|
|
42
43
|
for (var prop in defaultState) {
|
|
43
|
-
// $FlowFixMe
|
|
44
44
|
if (Object.prototype.hasOwnProperty.call(defaultState, prop)) {
|
|
45
45
|
state[prop] = defaultState[prop];
|
|
46
46
|
}
|
|
47
47
|
}
|
|
48
48
|
}
|
|
49
|
-
|
|
50
49
|
return state;
|
|
51
50
|
};
|
|
51
|
+
|
|
52
52
|
/**
|
|
53
53
|
* Creates a parser for a given set of rules, with the precedence
|
|
54
54
|
* specified as a list of rules.
|
|
@@ -68,41 +68,36 @@ var populateInitialState = function populateInitialState(givenState, defaultStat
|
|
|
68
68
|
* some nesting is. For an example use-case, see passage-ref
|
|
69
69
|
* parsing in src/widgets/passage/passage-markdown.jsx
|
|
70
70
|
*/
|
|
71
|
-
|
|
72
|
-
|
|
73
71
|
var parserFor = function parserFor(rules, defaultState) {
|
|
74
72
|
// Sorts rules in order of increasing order, then
|
|
75
73
|
// ascending rule name in case of ties.
|
|
76
74
|
var ruleList = Object.keys(rules).filter(function (type) {
|
|
77
75
|
var rule = rules[type];
|
|
78
|
-
|
|
79
76
|
if (rule == null || rule.match == null) {
|
|
80
77
|
return false;
|
|
81
78
|
}
|
|
82
|
-
|
|
83
79
|
var order = rule.order;
|
|
84
|
-
|
|
85
80
|
if ((typeof order !== "number" || !isFinite(order)) && typeof console !== "undefined") {
|
|
86
81
|
console.warn("simple-markdown: Invalid order for rule `" + type + "`: " + String(order));
|
|
87
82
|
}
|
|
88
|
-
|
|
89
83
|
return true;
|
|
90
84
|
});
|
|
91
85
|
ruleList.sort(function (typeA, typeB) {
|
|
92
86
|
var ruleA = rules[typeA];
|
|
93
87
|
var ruleB = rules[typeB];
|
|
94
88
|
var orderA = ruleA.order;
|
|
95
|
-
var orderB = ruleB.order;
|
|
89
|
+
var orderB = ruleB.order;
|
|
96
90
|
|
|
91
|
+
// First sort based on increasing order
|
|
97
92
|
if (orderA !== orderB) {
|
|
98
93
|
return orderA - orderB;
|
|
99
94
|
}
|
|
100
|
-
|
|
101
95
|
var secondaryOrderA = ruleA.quality ? 0 : 1;
|
|
102
96
|
var secondaryOrderB = ruleB.quality ? 0 : 1;
|
|
103
|
-
|
|
104
97
|
if (secondaryOrderA !== secondaryOrderB) {
|
|
105
|
-
return secondaryOrderA - secondaryOrderB;
|
|
98
|
+
return secondaryOrderA - secondaryOrderB;
|
|
99
|
+
|
|
100
|
+
// Then based on increasing unicode lexicographic ordering
|
|
106
101
|
} else if (typeA < typeB) {
|
|
107
102
|
return -1;
|
|
108
103
|
} else if (typeA > typeB) {
|
|
@@ -114,139 +109,128 @@ var parserFor = function parserFor(rules, defaultState) {
|
|
|
114
109
|
}
|
|
115
110
|
});
|
|
116
111
|
var latestState;
|
|
117
|
-
|
|
118
112
|
var nestedParse = function nestedParse(source, state) {
|
|
119
113
|
var result = [];
|
|
120
114
|
state = state || latestState;
|
|
121
115
|
latestState = state;
|
|
122
|
-
|
|
123
116
|
while (source) {
|
|
124
117
|
// store the best match, it's rule, and quality:
|
|
125
118
|
var ruleType = null;
|
|
126
119
|
var rule = null;
|
|
127
120
|
var capture = null;
|
|
128
|
-
var quality = NaN;
|
|
121
|
+
var quality = NaN;
|
|
129
122
|
|
|
123
|
+
// loop control variables:
|
|
130
124
|
var i = 0;
|
|
131
|
-
var currRuleType = ruleList[0];
|
|
132
|
-
|
|
125
|
+
var currRuleType = ruleList[0];
|
|
133
126
|
var currRule = rules[currRuleType];
|
|
134
|
-
|
|
135
127
|
do {
|
|
136
128
|
var currOrder = currRule.order;
|
|
137
129
|
var prevCaptureStr = state.prevCapture == null ? "" : state.prevCapture[0];
|
|
138
130
|
var currCapture = currRule.match(source, state, prevCaptureStr);
|
|
139
|
-
|
|
140
131
|
if (currCapture) {
|
|
141
|
-
var currQuality = currRule.quality ? currRule.quality(currCapture, state, prevCaptureStr) : 0;
|
|
132
|
+
var currQuality = currRule.quality ? currRule.quality(currCapture, state, prevCaptureStr) : 0;
|
|
133
|
+
// This should always be true the first time because
|
|
142
134
|
// the initial quality is NaN (that's why there's the
|
|
143
135
|
// condition negation).
|
|
144
|
-
|
|
145
136
|
if (!(currQuality <= quality)) {
|
|
137
|
+
// @ts-expect-error [FEI-5003] - TS2322 - Type 'string' is not assignable to type 'null'.
|
|
146
138
|
ruleType = currRuleType;
|
|
139
|
+
// @ts-expect-error [FEI-5003] - TS2322 - Type 'ParserRule' is not assignable to type 'null'.
|
|
147
140
|
rule = currRule;
|
|
141
|
+
// @ts-expect-error [FEI-5003] - TS2322 - Type 'Capture' is not assignable to type 'null'.
|
|
148
142
|
capture = currCapture;
|
|
149
143
|
quality = currQuality;
|
|
150
144
|
}
|
|
151
|
-
}
|
|
152
|
-
// Note that this makes `currRule` be the next item
|
|
153
|
-
|
|
145
|
+
}
|
|
154
146
|
|
|
147
|
+
// Move on to the next item.
|
|
148
|
+
// Note that this makes `currRule` be the next item
|
|
155
149
|
i++;
|
|
156
|
-
currRuleType = ruleList[i];
|
|
157
|
-
|
|
150
|
+
currRuleType = ruleList[i];
|
|
158
151
|
currRule = rules[currRuleType];
|
|
159
|
-
} while (
|
|
160
|
-
|
|
161
|
-
|
|
152
|
+
} while (
|
|
153
|
+
// keep looping while we're still within the ruleList
|
|
154
|
+
currRule && (
|
|
155
|
+
// if we don't have a match yet, continue
|
|
156
|
+
!capture ||
|
|
157
|
+
// or if we have a match, but the next rule is
|
|
162
158
|
// at the same order, and has a quality measurement
|
|
163
159
|
// functions, then this rule must have a quality
|
|
164
160
|
// measurement function (since they are sorted before
|
|
165
161
|
// those without), and we need to check if there is
|
|
166
162
|
// a better quality match
|
|
167
|
-
currRule.order === currOrder && currRule.quality));
|
|
168
|
-
|
|
163
|
+
currRule.order === currOrder && currRule.quality));
|
|
169
164
|
|
|
165
|
+
// TODO(aria): Write tests for these
|
|
170
166
|
if (rule == null || capture == null) {
|
|
171
167
|
throw new Error("Could not find a matching rule for the below " + "content. The rule with highest `order` should " + "always match content provided to it. Check " + "the definition of `match` for '" + ruleList[ruleList.length - 1] + "'. It seems to not match the following source:\n" + source);
|
|
172
168
|
}
|
|
173
|
-
|
|
169
|
+
// @ts-expect-error [FEI-5003] - TS2339 - Property 'index' does not exist on type 'never'.
|
|
174
170
|
if (capture.index) {
|
|
175
171
|
// If present and non-zero, i.e. a non-^ regexp result:
|
|
176
172
|
throw new Error("`match` must return a capture starting at index 0 " + "(the current parse index). Did you forget a ^ at the " + "start of the RegExp?");
|
|
177
173
|
}
|
|
178
174
|
|
|
179
|
-
|
|
175
|
+
// @ts-expect-error [FEI-5003] - TS2339 - Property 'parse' does not exist on type 'never'.
|
|
176
|
+
var parsed = rule.parse(capture, nestedParse, state);
|
|
177
|
+
// We maintain the same object here so that rules can
|
|
180
178
|
// store references to the objects they return and
|
|
181
179
|
// modify them later. (oops sorry! but this adds a lot
|
|
182
180
|
// of power--see reflinks.)
|
|
183
|
-
|
|
184
181
|
if (Array.isArray(parsed)) {
|
|
185
|
-
// $FlowFixMe
|
|
186
182
|
Array.prototype.push.apply(result, parsed);
|
|
187
183
|
} else {
|
|
188
184
|
if (parsed == null || typeof parsed !== "object") {
|
|
189
|
-
throw new Error(
|
|
190
|
-
}
|
|
185
|
+
throw new Error(`parse() function returned invalid parse result: '${parsed}'`);
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
// We also let rules override the default type of
|
|
191
189
|
// their parsed node if they would like to, so that
|
|
192
190
|
// there can be a single output function for all links,
|
|
193
191
|
// even if there are several rules to parse them.
|
|
194
|
-
|
|
195
|
-
|
|
196
192
|
if (parsed.type == null) {
|
|
197
|
-
// $FlowFixMe
|
|
198
193
|
parsed.type = ruleType;
|
|
199
194
|
}
|
|
200
|
-
|
|
201
195
|
result.push(parsed);
|
|
202
196
|
}
|
|
203
|
-
|
|
204
197
|
state.prevCapture = capture;
|
|
205
198
|
source = source.substring(state.prevCapture[0].length);
|
|
206
|
-
}
|
|
207
|
-
|
|
208
|
-
|
|
199
|
+
}
|
|
209
200
|
return result;
|
|
210
201
|
};
|
|
211
|
-
|
|
212
202
|
var outerParse = function outerParse(source, state) {
|
|
213
203
|
latestState = populateInitialState(state, defaultState);
|
|
214
|
-
|
|
215
204
|
if (!latestState.inline && !latestState.disableAutoBlockNewlines) {
|
|
216
205
|
source = source + "\n\n";
|
|
217
|
-
}
|
|
206
|
+
}
|
|
207
|
+
// We store the previous capture so that match functions can
|
|
218
208
|
// use some limited amount of lookbehind. Lists use this to
|
|
219
209
|
// ensure they don't match arbitrary '- ' or '* ' in inline
|
|
220
210
|
// text (see the list rule for more information). This stores
|
|
221
211
|
// the full regex capture object, if there is one.
|
|
222
|
-
|
|
223
|
-
|
|
224
212
|
latestState.prevCapture = null;
|
|
225
213
|
return nestedParse(preprocess(source), latestState);
|
|
226
|
-
};
|
|
227
|
-
|
|
228
|
-
|
|
214
|
+
};
|
|
229
215
|
return outerParse;
|
|
230
|
-
};
|
|
231
|
-
|
|
216
|
+
};
|
|
232
217
|
|
|
218
|
+
// Creates a match function for an inline scoped element from a regex
|
|
233
219
|
var inlineRegex = function inlineRegex(regex) {
|
|
234
220
|
var match = function match(source, state, prevCapture) {
|
|
235
221
|
if (state.inline) {
|
|
236
|
-
// $FlowFixMe
|
|
237
222
|
return regex.exec(source);
|
|
238
223
|
} else {
|
|
239
224
|
return null;
|
|
240
225
|
}
|
|
241
226
|
};
|
|
242
|
-
|
|
227
|
+
// @ts-expect-error [FEI-5003] - TS2339 - Property 'regex' does not exist on type '(source: string, state: State, prevCapture: string) => Capture | null | undefined'.
|
|
243
228
|
match.regex = regex;
|
|
244
229
|
return match;
|
|
245
|
-
};
|
|
246
|
-
|
|
230
|
+
};
|
|
247
231
|
|
|
232
|
+
// Creates a match function for a block scoped element from a regex
|
|
248
233
|
var blockRegex = function blockRegex(regex) {
|
|
249
|
-
// $FlowFixMe
|
|
250
234
|
var match = function match(source, state) {
|
|
251
235
|
if (state.inline) {
|
|
252
236
|
return null;
|
|
@@ -254,24 +238,19 @@ var blockRegex = function blockRegex(regex) {
|
|
|
254
238
|
return regex.exec(source);
|
|
255
239
|
}
|
|
256
240
|
};
|
|
257
|
-
|
|
258
241
|
match.regex = regex;
|
|
259
242
|
return match;
|
|
260
|
-
};
|
|
261
|
-
|
|
243
|
+
};
|
|
262
244
|
|
|
245
|
+
// Creates a match function from a regex, ignoring block/inline scope
|
|
263
246
|
var anyScopeRegex = function anyScopeRegex(regex) {
|
|
264
|
-
// $FlowFixMe
|
|
265
247
|
var match = function match(source, state) {
|
|
266
248
|
return regex.exec(source);
|
|
267
249
|
};
|
|
268
|
-
|
|
269
250
|
match.regex = regex;
|
|
270
251
|
return match;
|
|
271
252
|
};
|
|
272
|
-
|
|
273
253
|
var TYPE_SYMBOL = typeof Symbol === "function" && Symbol.for && Symbol.for("react.element") || 0xeac7;
|
|
274
|
-
|
|
275
254
|
var reactElement = function reactElement(type, key, props) {
|
|
276
255
|
var element = {
|
|
277
256
|
$$typeof: TYPE_SYMBOL,
|
|
@@ -283,6 +262,7 @@ var reactElement = function reactElement(type, key, props) {
|
|
|
283
262
|
};
|
|
284
263
|
return element;
|
|
285
264
|
};
|
|
265
|
+
|
|
286
266
|
/** Returns a closed HTML tag.
|
|
287
267
|
* @param {string} tagName - Name of HTML tag (eg. "em" or "a")
|
|
288
268
|
* @param {string} content - Inner content of tag
|
|
@@ -291,45 +271,38 @@ var reactElement = function reactElement(type, key, props) {
|
|
|
291
271
|
* @param {boolean} [isClosed] - boolean that controls whether tag is closed or not (eg. img tags).
|
|
292
272
|
* defaults to true
|
|
293
273
|
*/
|
|
294
|
-
|
|
295
|
-
|
|
296
274
|
var htmlTag = function htmlTag(tagName, content, attributes, isClosed) {
|
|
297
275
|
attributes = attributes || {};
|
|
298
276
|
isClosed = typeof isClosed !== "undefined" ? isClosed : true;
|
|
299
277
|
var attributeString = "";
|
|
300
|
-
|
|
301
278
|
for (var attr in attributes) {
|
|
302
|
-
var attribute = attributes[attr];
|
|
303
|
-
|
|
304
|
-
if (
|
|
279
|
+
var attribute = attributes[attr];
|
|
280
|
+
// Removes falsey attributes
|
|
281
|
+
if (
|
|
282
|
+
// $FlowFixMe
|
|
305
283
|
Object.prototype.hasOwnProperty.call(attributes, attr) && attribute) {
|
|
306
284
|
attributeString += " " + sanitizeText(attr) + '="' + sanitizeText(attribute) + '"';
|
|
307
285
|
}
|
|
308
286
|
}
|
|
309
|
-
|
|
310
287
|
var unclosedTag = "<" + tagName + attributeString + ">";
|
|
311
|
-
|
|
312
288
|
if (isClosed) {
|
|
313
289
|
return unclosedTag + content + "</" + tagName + ">";
|
|
314
290
|
} else {
|
|
315
291
|
return unclosedTag;
|
|
316
292
|
}
|
|
317
293
|
};
|
|
318
|
-
|
|
319
294
|
var EMPTY_PROPS = {};
|
|
295
|
+
|
|
320
296
|
/**
|
|
321
297
|
* @param {string | null | undefined} url - url to sanitize
|
|
322
298
|
* @returns {string | null} - url if safe, or null if a safe url could not be made
|
|
323
299
|
*/
|
|
324
|
-
|
|
325
300
|
var sanitizeUrl = function sanitizeUrl(url) {
|
|
326
301
|
if (url == null) {
|
|
327
302
|
return null;
|
|
328
303
|
}
|
|
329
|
-
|
|
330
304
|
try {
|
|
331
305
|
var prot = new URL(url, "https://localhost").protocol;
|
|
332
|
-
|
|
333
306
|
if (prot.indexOf("javascript:") === 0 || prot.indexOf("vbscript:") === 0 || prot.indexOf("data:") === 0) {
|
|
334
307
|
return null;
|
|
335
308
|
}
|
|
@@ -338,10 +311,8 @@ var sanitizeUrl = function sanitizeUrl(url) {
|
|
|
338
311
|
// see for instance: `new URL("");`
|
|
339
312
|
return null;
|
|
340
313
|
}
|
|
341
|
-
|
|
342
314
|
return url;
|
|
343
315
|
};
|
|
344
|
-
|
|
345
316
|
var SANITIZE_TEXT_R = /[<>&"']/g;
|
|
346
317
|
var SANITIZE_TEXT_CODES = {
|
|
347
318
|
"<": "<",
|
|
@@ -352,25 +323,21 @@ var SANITIZE_TEXT_CODES = {
|
|
|
352
323
|
"/": "/",
|
|
353
324
|
"`": "`"
|
|
354
325
|
};
|
|
355
|
-
|
|
356
326
|
var sanitizeText = function sanitizeText(text) {
|
|
357
327
|
return String(text).replace(SANITIZE_TEXT_R, function (chr) {
|
|
358
328
|
return SANITIZE_TEXT_CODES[chr];
|
|
359
329
|
});
|
|
360
330
|
};
|
|
361
|
-
|
|
362
331
|
var UNESCAPE_URL_R = /\\([^0-9A-Za-z\s])/g;
|
|
363
|
-
|
|
364
332
|
var unescapeUrl = function unescapeUrl(rawUrlString) {
|
|
365
333
|
return rawUrlString.replace(UNESCAPE_URL_R, "$1");
|
|
366
334
|
};
|
|
335
|
+
|
|
367
336
|
/**
|
|
368
337
|
* Parse some content with the parser `parse`, with state.inline
|
|
369
338
|
* set to true. Useful for block elements; not generally necessary
|
|
370
339
|
* to be used by inline elements (where state.inline is already true.
|
|
371
340
|
*/
|
|
372
|
-
|
|
373
|
-
|
|
374
341
|
var parseInline = function parseInline(parse, content, state) {
|
|
375
342
|
var isCurrentlyInline = state.inline || false;
|
|
376
343
|
state.inline = true;
|
|
@@ -378,7 +345,6 @@ var parseInline = function parseInline(parse, content, state) {
|
|
|
378
345
|
state.inline = isCurrentlyInline;
|
|
379
346
|
return result;
|
|
380
347
|
};
|
|
381
|
-
|
|
382
348
|
var parseBlock = function parseBlock(parse, content, state) {
|
|
383
349
|
var isCurrentlyInline = state.inline || false;
|
|
384
350
|
state.inline = false;
|
|
@@ -386,50 +352,50 @@ var parseBlock = function parseBlock(parse, content, state) {
|
|
|
386
352
|
state.inline = isCurrentlyInline;
|
|
387
353
|
return result;
|
|
388
354
|
};
|
|
389
|
-
|
|
390
355
|
var parseCaptureInline = function parseCaptureInline(capture, parse, state) {
|
|
391
356
|
return {
|
|
392
357
|
content: parseInline(parse, capture[1], state)
|
|
393
358
|
};
|
|
394
359
|
};
|
|
395
|
-
|
|
396
360
|
var ignoreCapture = function ignoreCapture() {
|
|
397
361
|
return {};
|
|
398
|
-
};
|
|
399
|
-
|
|
362
|
+
};
|
|
400
363
|
|
|
401
|
-
|
|
364
|
+
// recognize a `*` `-`, `+`, `1.`, `2.`... list bullet
|
|
365
|
+
var LIST_BULLET = "(?:[*+-]|\\d+\\.)";
|
|
366
|
+
// recognize the start of a list item:
|
|
402
367
|
// leading space plus a bullet plus a space (` * `)
|
|
403
|
-
|
|
404
368
|
var LIST_ITEM_PREFIX = "( *)(" + LIST_BULLET + ") +";
|
|
405
|
-
var LIST_ITEM_PREFIX_R = new RegExp("^" + LIST_ITEM_PREFIX);
|
|
369
|
+
var LIST_ITEM_PREFIX_R = new RegExp("^" + LIST_ITEM_PREFIX);
|
|
370
|
+
// recognize an individual list item:
|
|
406
371
|
// * hi
|
|
407
372
|
// this is part of the same item
|
|
408
373
|
//
|
|
409
374
|
// as is this, which is a new paragraph in the same item
|
|
410
375
|
//
|
|
411
376
|
// * but this is not part of the same item
|
|
412
|
-
|
|
413
377
|
var LIST_ITEM_R = new RegExp(LIST_ITEM_PREFIX + "[^\\n]*(?:\\n" + "(?!\\1" + LIST_BULLET + " )[^\\n]*)*(\n|$)", "gm");
|
|
414
378
|
var BLOCK_END_R = /\n{2,}$/;
|
|
415
|
-
var INLINE_CODE_ESCAPE_BACKTICKS_R = /^ (?= *`)|(` *) $/g;
|
|
379
|
+
var INLINE_CODE_ESCAPE_BACKTICKS_R = /^ (?= *`)|(` *) $/g;
|
|
380
|
+
// recognize the end of a paragraph block inside a list item:
|
|
416
381
|
// two or more newlines at end end of the item
|
|
417
|
-
|
|
418
382
|
var LIST_BLOCK_END_R = BLOCK_END_R;
|
|
419
|
-
var LIST_ITEM_END_R = / *\n+$/;
|
|
383
|
+
var LIST_ITEM_END_R = / *\n+$/;
|
|
384
|
+
// check whether a list item has paragraphs: if it does,
|
|
420
385
|
// we leave the newlines at the end
|
|
421
|
-
|
|
422
|
-
|
|
386
|
+
var LIST_R = new RegExp("^( *)(" + LIST_BULLET + ") " + "[\\s\\S]+?(?:\n{2,}(?! )" + "(?!\\1" + LIST_BULLET + " )\\n*" +
|
|
387
|
+
// the \\s*$ here is so that we can parse the inside of nested
|
|
423
388
|
// lists, where our content might end before we receive two `\n`s
|
|
424
389
|
"|\\s*\n*$)");
|
|
425
390
|
var LIST_LOOKBEHIND_R = /(?:^|\n)( *)$/;
|
|
426
|
-
|
|
427
391
|
var TABLES = function () {
|
|
428
392
|
var TABLE_ROW_SEPARATOR_TRIM = /^ *\| *| *\| *$/g;
|
|
429
393
|
var TABLE_CELL_END_TRIM = / *$/;
|
|
430
394
|
var TABLE_RIGHT_ALIGN = /^ *-+: *$/;
|
|
431
395
|
var TABLE_CENTER_ALIGN = /^ *:-+: *$/;
|
|
432
|
-
var TABLE_LEFT_ALIGN = /^ *:-+ *$/;
|
|
396
|
+
var TABLE_LEFT_ALIGN = /^ *:-+ *$/;
|
|
397
|
+
|
|
398
|
+
// TODO: This needs a real type
|
|
433
399
|
|
|
434
400
|
var parseTableAlignCapture = function parseTableAlignCapture(alignCapture) {
|
|
435
401
|
if (TABLE_RIGHT_ALIGN.test(alignCapture)) {
|
|
@@ -442,16 +408,13 @@ var TABLES = function () {
|
|
|
442
408
|
return null;
|
|
443
409
|
}
|
|
444
410
|
};
|
|
445
|
-
|
|
446
411
|
var parseTableAlign = function parseTableAlign(source, parse, state, trimEndSeparators) {
|
|
447
412
|
if (trimEndSeparators) {
|
|
448
413
|
source = source.replace(TABLE_ROW_SEPARATOR_TRIM, "");
|
|
449
414
|
}
|
|
450
|
-
|
|
451
415
|
var alignText = source.trim().split("|");
|
|
452
416
|
return alignText.map(parseTableAlignCapture);
|
|
453
417
|
};
|
|
454
|
-
|
|
455
418
|
var parseTableRow = function parseTableRow(source, parse, state, trimEndSeparators) {
|
|
456
419
|
var prevInTable = state.inTable;
|
|
457
420
|
state.inTable = true;
|
|
@@ -469,12 +432,13 @@ var TABLES = function () {
|
|
|
469
432
|
if (node.type === "text" && (tableRow[i + 1] == null || tableRow[i + 1].type === "tableSeparator")) {
|
|
470
433
|
node.content = node.content.replace(TABLE_CELL_END_TRIM, "");
|
|
471
434
|
}
|
|
472
|
-
|
|
435
|
+
// @ts-expect-error [FEI-5003] - TS2345 - Argument of type 'SingleASTNode' is not assignable to parameter of type 'never'.
|
|
473
436
|
cells[cells.length - 1].push(node);
|
|
474
437
|
}
|
|
475
438
|
});
|
|
476
439
|
return cells;
|
|
477
440
|
};
|
|
441
|
+
|
|
478
442
|
/**
|
|
479
443
|
* @param {string} source
|
|
480
444
|
* @param {SimpleMarkdown.Parser} parse
|
|
@@ -482,21 +446,17 @@ var TABLES = function () {
|
|
|
482
446
|
* @param {boolean} trimEndSeparators
|
|
483
447
|
* @returns {SimpleMarkdown.ASTNode[][]}
|
|
484
448
|
*/
|
|
485
|
-
|
|
486
|
-
|
|
487
449
|
var parseTableCells = function parseTableCells(source, parse, state, trimEndSeparators) {
|
|
488
450
|
var rowsText = source.trim().split("\n");
|
|
489
451
|
return rowsText.map(function (rowText) {
|
|
490
|
-
// $FlowFixMe
|
|
491
452
|
return parseTableRow(rowText, parse, state, trimEndSeparators);
|
|
492
453
|
});
|
|
493
454
|
};
|
|
455
|
+
|
|
494
456
|
/**
|
|
495
457
|
* @param {boolean} trimEndSeparators
|
|
496
458
|
* @returns {SimpleMarkdown.SingleNodeParseFunction}
|
|
497
459
|
*/
|
|
498
|
-
|
|
499
|
-
|
|
500
460
|
var parseTable = function parseTable(trimEndSeparators) {
|
|
501
461
|
return function (capture, parse, state) {
|
|
502
462
|
state.inline = true;
|
|
@@ -512,7 +472,6 @@ var TABLES = function () {
|
|
|
512
472
|
};
|
|
513
473
|
};
|
|
514
474
|
};
|
|
515
|
-
|
|
516
475
|
return {
|
|
517
476
|
parseTable: parseTable(true),
|
|
518
477
|
parseNpTable: parseTable(false),
|
|
@@ -520,121 +479,101 @@ var TABLES = function () {
|
|
|
520
479
|
NPTABLE_REGEX: /^ *(\S.*\|.*)\n *([-:]+ *\|[-| :]*)\n((?:.*\|.*(?:\n|$))*)\n*/
|
|
521
480
|
};
|
|
522
481
|
}();
|
|
523
|
-
|
|
524
482
|
var LINK_INSIDE = "(?:\\[[^\\]]*\\]|[^\\[\\]]|\\](?=[^\\[]*\\]))*";
|
|
525
483
|
var LINK_HREF_AND_TITLE = "\\s*<?((?:\\([^)]*\\)|[^\\s\\\\]|\\\\.)*?)>?(?:\\s+['\"]([\\s\\S]*?)['\"])?\\s*";
|
|
526
484
|
var AUTOLINK_MAILTO_CHECK_R = /mailto:/i;
|
|
527
|
-
|
|
528
485
|
var parseRef = function parseRef(capture, state, refNode) {
|
|
529
|
-
var ref = (capture[2] || capture[1]).replace(/\s+/g, " ").toLowerCase();
|
|
486
|
+
var ref = (capture[2] || capture[1]).replace(/\s+/g, " ").toLowerCase();
|
|
487
|
+
|
|
488
|
+
// We store information about previously seen defs on
|
|
530
489
|
// state._defs (_ to deconflict with client-defined
|
|
531
490
|
// state). If the def for this reflink/refimage has
|
|
532
491
|
// already been seen, we can use its target/source
|
|
533
492
|
// and title here:
|
|
534
|
-
|
|
535
493
|
if (state._defs && state._defs[ref]) {
|
|
536
|
-
var def = state._defs[ref];
|
|
494
|
+
var def = state._defs[ref];
|
|
495
|
+
// `refNode` can be a link or an image. Both use
|
|
537
496
|
// target and title properties.
|
|
538
|
-
|
|
539
497
|
refNode.target = def.target;
|
|
540
498
|
refNode.title = def.title;
|
|
541
|
-
}
|
|
499
|
+
}
|
|
500
|
+
|
|
501
|
+
// In case we haven't seen our def yet (or if someone
|
|
542
502
|
// overwrites that def later on), we add this node
|
|
543
503
|
// to the list of ref nodes for that def. Then, when
|
|
544
504
|
// we find the def, we can modify this link/image AST
|
|
545
505
|
// node :).
|
|
546
506
|
// I'm sorry.
|
|
547
|
-
|
|
548
|
-
|
|
549
507
|
state._refs = state._refs || {};
|
|
550
508
|
state._refs[ref] = state._refs[ref] || [];
|
|
551
|
-
|
|
552
509
|
state._refs[ref].push(refNode);
|
|
553
|
-
|
|
554
510
|
return refNode;
|
|
555
511
|
};
|
|
556
|
-
|
|
557
512
|
var currOrder = 0;
|
|
558
513
|
var defaultRules = {
|
|
559
514
|
Array: {
|
|
560
|
-
react: function
|
|
515
|
+
react: function (arr, output, state) {
|
|
561
516
|
var oldKey = state.key;
|
|
562
|
-
var result = [];
|
|
563
|
-
// nodes together into a single string output.
|
|
517
|
+
var result = [];
|
|
564
518
|
|
|
519
|
+
// map output over the ast, except group any text
|
|
520
|
+
// nodes together into a single string output.
|
|
565
521
|
for (var i = 0, key = 0; i < arr.length; i++, key++) {
|
|
566
522
|
// `key` is our numerical `state.key`, which we increment for
|
|
567
523
|
// every output node, but don't change for joined text nodes.
|
|
568
524
|
// (i, however, must change for joined text nodes)
|
|
569
525
|
state.key = "" + i;
|
|
570
526
|
var node = arr[i];
|
|
571
|
-
|
|
572
527
|
if (node.type === "text") {
|
|
573
528
|
node = {
|
|
574
529
|
type: "text",
|
|
575
530
|
content: node.content
|
|
576
531
|
};
|
|
577
|
-
|
|
578
532
|
for (; i + 1 < arr.length && arr[i + 1].type === "text"; i++) {
|
|
579
533
|
node.content += arr[i + 1].content;
|
|
580
534
|
}
|
|
581
535
|
}
|
|
582
|
-
|
|
583
536
|
result.push(output(node, state));
|
|
584
537
|
}
|
|
585
|
-
|
|
586
538
|
state.key = oldKey;
|
|
587
539
|
return result;
|
|
588
540
|
},
|
|
589
|
-
html: function
|
|
590
|
-
var result = "";
|
|
591
|
-
// nodes together into a single string output.
|
|
541
|
+
html: function (arr, output, state) {
|
|
542
|
+
var result = "";
|
|
592
543
|
|
|
544
|
+
// map output over the ast, except group any text
|
|
545
|
+
// nodes together into a single string output.
|
|
593
546
|
for (var i = 0; i < arr.length; i++) {
|
|
594
547
|
var node = arr[i];
|
|
595
|
-
|
|
596
548
|
if (node.type === "text") {
|
|
597
549
|
node = {
|
|
598
550
|
type: "text",
|
|
599
551
|
content: node.content
|
|
600
552
|
};
|
|
601
|
-
|
|
602
553
|
for (; i + 1 < arr.length && arr[i + 1].type === "text"; i++) {
|
|
603
554
|
node.content += arr[i + 1].content;
|
|
604
555
|
}
|
|
605
556
|
}
|
|
606
|
-
|
|
607
557
|
result += output(node, state);
|
|
608
558
|
}
|
|
609
|
-
|
|
610
559
|
return result;
|
|
611
560
|
}
|
|
612
561
|
},
|
|
613
562
|
heading: {
|
|
614
563
|
order: currOrder++,
|
|
615
564
|
match: blockRegex(/^ *(#{1,6})([^\n]+?)#* *(?:\n *)+\n/),
|
|
616
|
-
parse: function (
|
|
617
|
-
function parse(_x, _x2, _x3) {
|
|
618
|
-
return _parse.apply(this, arguments);
|
|
619
|
-
}
|
|
620
|
-
|
|
621
|
-
parse.toString = function () {
|
|
622
|
-
return _parse.toString();
|
|
623
|
-
};
|
|
624
|
-
|
|
625
|
-
return parse;
|
|
626
|
-
}(function (capture, parse, state) {
|
|
565
|
+
parse: function (capture, parse, state) {
|
|
627
566
|
return {
|
|
628
567
|
level: capture[1].length,
|
|
629
568
|
content: parseInline(parse, capture[2].trim(), state)
|
|
630
569
|
};
|
|
631
|
-
}
|
|
632
|
-
react: function
|
|
570
|
+
},
|
|
571
|
+
react: function (node, output, state) {
|
|
633
572
|
return reactElement("h" + node.level, state.key, {
|
|
634
573
|
children: output(node.content, state)
|
|
635
574
|
});
|
|
636
575
|
},
|
|
637
|
-
html: function
|
|
576
|
+
html: function (node, output, state) {
|
|
638
577
|
return htmlTag("h" + node.level, output(node.content, state));
|
|
639
578
|
}
|
|
640
579
|
},
|
|
@@ -648,23 +587,13 @@ var defaultRules = {
|
|
|
648
587
|
lheading: {
|
|
649
588
|
order: currOrder++,
|
|
650
589
|
match: blockRegex(/^([^\n]+)\n *(=|-){3,} *(?:\n *)+\n/),
|
|
651
|
-
parse: function (
|
|
652
|
-
function parse(_x4, _x5, _x6) {
|
|
653
|
-
return _parse2.apply(this, arguments);
|
|
654
|
-
}
|
|
655
|
-
|
|
656
|
-
parse.toString = function () {
|
|
657
|
-
return _parse2.toString();
|
|
658
|
-
};
|
|
659
|
-
|
|
660
|
-
return parse;
|
|
661
|
-
}(function (capture, parse, state) {
|
|
590
|
+
parse: function (capture, parse, state) {
|
|
662
591
|
return {
|
|
663
592
|
type: "heading",
|
|
664
593
|
level: capture[2] === "=" ? 1 : 2,
|
|
665
594
|
content: parseInline(parse, capture[1], state)
|
|
666
595
|
};
|
|
667
|
-
}
|
|
596
|
+
},
|
|
668
597
|
react: null,
|
|
669
598
|
html: null
|
|
670
599
|
},
|
|
@@ -672,34 +601,24 @@ var defaultRules = {
|
|
|
672
601
|
order: currOrder++,
|
|
673
602
|
match: blockRegex(/^( *[-*_]){3,} *(?:\n *)+\n/),
|
|
674
603
|
parse: ignoreCapture,
|
|
675
|
-
react: function
|
|
604
|
+
react: function (node, output, state) {
|
|
676
605
|
return reactElement("hr", state.key, EMPTY_PROPS);
|
|
677
606
|
},
|
|
678
|
-
html: function
|
|
607
|
+
html: function (node, output, state) {
|
|
679
608
|
return "<hr>";
|
|
680
609
|
}
|
|
681
610
|
},
|
|
682
611
|
codeBlock: {
|
|
683
612
|
order: currOrder++,
|
|
684
613
|
match: blockRegex(/^(?: [^\n]+\n*)+(?:\n *)+\n/),
|
|
685
|
-
parse: function (
|
|
686
|
-
function parse(_x7, _x8, _x9) {
|
|
687
|
-
return _parse3.apply(this, arguments);
|
|
688
|
-
}
|
|
689
|
-
|
|
690
|
-
parse.toString = function () {
|
|
691
|
-
return _parse3.toString();
|
|
692
|
-
};
|
|
693
|
-
|
|
694
|
-
return parse;
|
|
695
|
-
}(function (capture, parse, state) {
|
|
614
|
+
parse: function (capture, parse, state) {
|
|
696
615
|
var content = capture[0].replace(/^ /gm, "").replace(/\n+$/, "");
|
|
697
616
|
return {
|
|
698
617
|
lang: undefined,
|
|
699
618
|
content: content
|
|
700
619
|
};
|
|
701
|
-
}
|
|
702
|
-
react: function
|
|
620
|
+
},
|
|
621
|
+
react: function (node, output, state) {
|
|
703
622
|
var className = node.lang ? "markdown-code-" + node.lang : undefined;
|
|
704
623
|
return reactElement("pre", state.key, {
|
|
705
624
|
children: reactElement("code", null, {
|
|
@@ -708,7 +627,7 @@ var defaultRules = {
|
|
|
708
627
|
})
|
|
709
628
|
});
|
|
710
629
|
},
|
|
711
|
-
html: function
|
|
630
|
+
html: function (node, output, state) {
|
|
712
631
|
var className = node.lang ? "markdown-code-" + node.lang : undefined;
|
|
713
632
|
var codeBlock = htmlTag("code", sanitizeText(node.content), {
|
|
714
633
|
class: className
|
|
@@ -719,58 +638,38 @@ var defaultRules = {
|
|
|
719
638
|
fence: {
|
|
720
639
|
order: currOrder++,
|
|
721
640
|
match: blockRegex(/^ *(`{3,}|~{3,}) *(?:(\S+) *)?\n([\s\S]+?)\n?\1 *(?:\n *)+\n/),
|
|
722
|
-
parse: function (
|
|
723
|
-
function parse(_x10, _x11, _x12) {
|
|
724
|
-
return _parse4.apply(this, arguments);
|
|
725
|
-
}
|
|
726
|
-
|
|
727
|
-
parse.toString = function () {
|
|
728
|
-
return _parse4.toString();
|
|
729
|
-
};
|
|
730
|
-
|
|
731
|
-
return parse;
|
|
732
|
-
}(function (capture, parse, state) {
|
|
641
|
+
parse: function (capture, parse, state) {
|
|
733
642
|
return {
|
|
734
643
|
type: "codeBlock",
|
|
735
644
|
lang: capture[2] || undefined,
|
|
736
645
|
content: capture[3]
|
|
737
646
|
};
|
|
738
|
-
}
|
|
647
|
+
},
|
|
739
648
|
react: null,
|
|
740
649
|
html: null
|
|
741
650
|
},
|
|
742
651
|
blockQuote: {
|
|
743
652
|
order: currOrder++,
|
|
744
653
|
match: blockRegex(/^( *>[^\n]+(\n[^\n]+)*\n*)+\n{2,}/),
|
|
745
|
-
parse: function (
|
|
746
|
-
function parse(_x13, _x14, _x15) {
|
|
747
|
-
return _parse5.apply(this, arguments);
|
|
748
|
-
}
|
|
749
|
-
|
|
750
|
-
parse.toString = function () {
|
|
751
|
-
return _parse5.toString();
|
|
752
|
-
};
|
|
753
|
-
|
|
754
|
-
return parse;
|
|
755
|
-
}(function (capture, parse, state) {
|
|
654
|
+
parse: function (capture, parse, state) {
|
|
756
655
|
var content = capture[0].replace(/^ *> ?/gm, "");
|
|
757
656
|
return {
|
|
758
657
|
content: parse(content, state)
|
|
759
658
|
};
|
|
760
|
-
}
|
|
761
|
-
react: function
|
|
659
|
+
},
|
|
660
|
+
react: function (node, output, state) {
|
|
762
661
|
return reactElement("blockquote", state.key, {
|
|
763
662
|
children: output(node.content, state)
|
|
764
663
|
});
|
|
765
664
|
},
|
|
766
|
-
html: function
|
|
665
|
+
html: function (node, output, state) {
|
|
767
666
|
return htmlTag("blockquote", output(node.content, state));
|
|
768
667
|
}
|
|
769
668
|
},
|
|
770
669
|
list: {
|
|
771
670
|
order: currOrder++,
|
|
772
671
|
// $FlowFixMe
|
|
773
|
-
match: function
|
|
672
|
+
match: function (source, state) {
|
|
774
673
|
// We only want to break into a list if we are at the start of a
|
|
775
674
|
// line. This is to avoid parsing "hi * there" with "* there"
|
|
776
675
|
// becoming a part of a list.
|
|
@@ -782,7 +681,6 @@ var defaultRules = {
|
|
|
782
681
|
var prevCaptureStr = state.prevCapture == null ? "" : state.prevCapture[0];
|
|
783
682
|
var isStartOfLineCapture = LIST_LOOKBEHIND_R.exec(prevCaptureStr);
|
|
784
683
|
var isListBlock = state._list || !state.inline;
|
|
785
|
-
|
|
786
684
|
if (isStartOfLineCapture && isListBlock) {
|
|
787
685
|
source = isStartOfLineCapture[1] + source;
|
|
788
686
|
return LIST_R.exec(source);
|
|
@@ -790,35 +688,34 @@ var defaultRules = {
|
|
|
790
688
|
return null;
|
|
791
689
|
}
|
|
792
690
|
},
|
|
793
|
-
parse: function (
|
|
794
|
-
function parse(_x16, _x17, _x18) {
|
|
795
|
-
return _parse6.apply(this, arguments);
|
|
796
|
-
}
|
|
797
|
-
|
|
798
|
-
parse.toString = function () {
|
|
799
|
-
return _parse6.toString();
|
|
800
|
-
};
|
|
801
|
-
|
|
802
|
-
return parse;
|
|
803
|
-
}(function (capture, parse, state) {
|
|
691
|
+
parse: function (capture, parse, state) {
|
|
804
692
|
var bullet = capture[2];
|
|
805
693
|
var ordered = bullet.length > 1;
|
|
806
694
|
var start = ordered ? +bullet : undefined;
|
|
807
|
-
|
|
695
|
+
// @ts-expect-error [FEI-5003] - TS2322 - Type 'RegExpMatchArray | null' is not assignable to type 'string[]'.
|
|
696
|
+
var items = capture[0].replace(LIST_BLOCK_END_R, "\n").match(LIST_ITEM_R);
|
|
697
|
+
|
|
698
|
+
// We know this will match here, because of how the regexes are
|
|
808
699
|
// defined
|
|
809
700
|
|
|
810
701
|
var lastItemWasAParagraph = false;
|
|
811
702
|
var itemContent = items.map(function (item, i) {
|
|
812
703
|
// We need to see how far indented this item is:
|
|
813
704
|
var prefixCapture = LIST_ITEM_PREFIX_R.exec(item);
|
|
814
|
-
var space = prefixCapture ? prefixCapture[0].length : 0;
|
|
705
|
+
var space = prefixCapture ? prefixCapture[0].length : 0;
|
|
706
|
+
// And then we construct a regex to "unindent" the subsequent
|
|
815
707
|
// lines of the items by that amount:
|
|
708
|
+
var spaceRegex = new RegExp("^ {1," + space + "}", "gm");
|
|
816
709
|
|
|
817
|
-
|
|
710
|
+
// Before processing the item, we need a couple things
|
|
711
|
+
var content = item
|
|
712
|
+
// remove indents on trailing lines:
|
|
713
|
+
.replace(spaceRegex, "")
|
|
714
|
+
// remove the bullet:
|
|
715
|
+
.replace(LIST_ITEM_PREFIX_R, "");
|
|
716
|
+
|
|
717
|
+
// I'm not sur4 why this is necessary again?
|
|
818
718
|
|
|
819
|
-
var content = item // remove indents on trailing lines:
|
|
820
|
-
.replace(spaceRegex, "") // remove the bullet:
|
|
821
|
-
.replace(LIST_ITEM_PREFIX_R, ""); // I'm not sur4 why this is necessary again?
|
|
822
719
|
// Handling "loose" lists, like:
|
|
823
720
|
//
|
|
824
721
|
// * this is wrapped in a paragraph
|
|
@@ -826,27 +723,28 @@ var defaultRules = {
|
|
|
826
723
|
// * as is this
|
|
827
724
|
//
|
|
828
725
|
// * as is this
|
|
829
|
-
|
|
830
726
|
var isLastItem = i === items.length - 1;
|
|
831
|
-
var containsBlocks = content.indexOf("\n\n") !== -1;
|
|
727
|
+
var containsBlocks = content.indexOf("\n\n") !== -1;
|
|
728
|
+
|
|
729
|
+
// Any element in a list is a block if it contains multiple
|
|
832
730
|
// newlines. The last element in the list can also be a block
|
|
833
731
|
// if the previous item in the list was a block (this is
|
|
834
732
|
// because non-last items in the list can end with \n\n, but
|
|
835
733
|
// the last item can't, so we just "inherit" this property
|
|
836
734
|
// from our previous element).
|
|
837
|
-
|
|
838
735
|
var thisItemIsAParagraph = containsBlocks || isLastItem && lastItemWasAParagraph;
|
|
839
|
-
lastItemWasAParagraph = thisItemIsAParagraph;
|
|
736
|
+
lastItemWasAParagraph = thisItemIsAParagraph;
|
|
737
|
+
|
|
738
|
+
// backup our state for restoration afterwards. We're going to
|
|
840
739
|
// want to set state._list to true, and state.inline depending
|
|
841
740
|
// on our list's looseness.
|
|
842
|
-
|
|
843
741
|
var oldStateInline = state.inline;
|
|
844
742
|
var oldStateList = state._list;
|
|
845
|
-
state._list = true;
|
|
846
|
-
// a loose list.
|
|
743
|
+
state._list = true;
|
|
847
744
|
|
|
745
|
+
// Parse inline if we're in a tight list, or block if we're in
|
|
746
|
+
// a loose list.
|
|
848
747
|
var adjustedContent;
|
|
849
|
-
|
|
850
748
|
if (thisItemIsAParagraph) {
|
|
851
749
|
state.inline = false;
|
|
852
750
|
adjustedContent = content.replace(LIST_ITEM_END_R, "\n\n");
|
|
@@ -854,9 +752,9 @@ var defaultRules = {
|
|
|
854
752
|
state.inline = true;
|
|
855
753
|
adjustedContent = content.replace(LIST_ITEM_END_R, "");
|
|
856
754
|
}
|
|
755
|
+
var result = parse(adjustedContent, state);
|
|
857
756
|
|
|
858
|
-
|
|
859
|
-
|
|
757
|
+
// Restore our state before returning
|
|
860
758
|
state.inline = oldStateInline;
|
|
861
759
|
state._list = oldStateList;
|
|
862
760
|
return result;
|
|
@@ -866,8 +764,8 @@ var defaultRules = {
|
|
|
866
764
|
start: start,
|
|
867
765
|
items: itemContent
|
|
868
766
|
};
|
|
869
|
-
}
|
|
870
|
-
react: function
|
|
767
|
+
},
|
|
768
|
+
react: function (node, output, state) {
|
|
871
769
|
var ListWrapper = node.ordered ? "ol" : "ul";
|
|
872
770
|
return reactElement(ListWrapper, state.key, {
|
|
873
771
|
start: node.start,
|
|
@@ -878,7 +776,7 @@ var defaultRules = {
|
|
|
878
776
|
})
|
|
879
777
|
});
|
|
880
778
|
},
|
|
881
|
-
html: function
|
|
779
|
+
html: function (node, output, state) {
|
|
882
780
|
var listItems = node.items.map(function (item) {
|
|
883
781
|
return htmlTag("li", output(item, state));
|
|
884
782
|
}).join("");
|
|
@@ -895,57 +793,49 @@ var defaultRules = {
|
|
|
895
793
|
// block element, which is inconsistent with most of the rest of
|
|
896
794
|
// simple-markdown.
|
|
897
795
|
match: blockRegex(/^ *\[([^\]]+)\]: *<?([^\s>]*)>?(?: +["(]([^\n]+)[")])? *\n(?: *\n)*/),
|
|
898
|
-
parse: function (
|
|
899
|
-
function parse(_x19, _x20, _x21) {
|
|
900
|
-
return _parse7.apply(this, arguments);
|
|
901
|
-
}
|
|
902
|
-
|
|
903
|
-
parse.toString = function () {
|
|
904
|
-
return _parse7.toString();
|
|
905
|
-
};
|
|
906
|
-
|
|
907
|
-
return parse;
|
|
908
|
-
}(function (capture, parse, state) {
|
|
796
|
+
parse: function (capture, parse, state) {
|
|
909
797
|
var def = capture[1].replace(/\s+/g, " ").toLowerCase();
|
|
910
798
|
var target = capture[2];
|
|
911
|
-
var title = capture[3];
|
|
799
|
+
var title = capture[3];
|
|
800
|
+
|
|
801
|
+
// Look for previous links/images using this def
|
|
912
802
|
// If any links/images using this def have already been declared,
|
|
913
803
|
// they will have added themselves to the state._refs[def] list
|
|
914
804
|
// (_ to deconflict with client-defined state). We look through
|
|
915
805
|
// that list of reflinks for this def, and modify those AST nodes
|
|
916
806
|
// with our newly found information now.
|
|
917
807
|
// Sorry :(.
|
|
918
|
-
|
|
919
808
|
if (state._refs && state._refs[def]) {
|
|
920
809
|
// `refNode` can be a link or an image
|
|
921
810
|
state._refs[def].forEach(function (refNode) {
|
|
922
811
|
refNode.target = target;
|
|
923
812
|
refNode.title = title;
|
|
924
813
|
});
|
|
925
|
-
}
|
|
814
|
+
}
|
|
815
|
+
|
|
816
|
+
// Add this def to our map of defs for any future links/images
|
|
926
817
|
// In case we haven't found any or all of the refs referring to
|
|
927
818
|
// this def yet, we add our def to the table of known defs, so
|
|
928
819
|
// that future reflinks can modify themselves appropriately with
|
|
929
820
|
// this information.
|
|
930
|
-
|
|
931
|
-
|
|
932
821
|
state._defs = state._defs || {};
|
|
933
822
|
state._defs[def] = {
|
|
934
823
|
target: target,
|
|
935
824
|
title: title
|
|
936
|
-
};
|
|
937
|
-
// for debugging only.
|
|
825
|
+
};
|
|
938
826
|
|
|
827
|
+
// return the relevant parsed information
|
|
828
|
+
// for debugging only.
|
|
939
829
|
return {
|
|
940
830
|
def: def,
|
|
941
831
|
target: target,
|
|
942
832
|
title: title
|
|
943
833
|
};
|
|
944
|
-
}
|
|
945
|
-
react: function
|
|
834
|
+
},
|
|
835
|
+
react: function () {
|
|
946
836
|
return null;
|
|
947
837
|
},
|
|
948
|
-
html: function
|
|
838
|
+
html: function () {
|
|
949
839
|
return "";
|
|
950
840
|
}
|
|
951
841
|
},
|
|
@@ -953,13 +843,12 @@ var defaultRules = {
|
|
|
953
843
|
order: currOrder++,
|
|
954
844
|
match: blockRegex(TABLES.TABLE_REGEX),
|
|
955
845
|
parse: TABLES.parseTable,
|
|
956
|
-
react: function
|
|
846
|
+
react: function (node, output, state) {
|
|
957
847
|
var getStyle = function getStyle(colIndex) {
|
|
958
848
|
return node.align[colIndex] == null ? {} : {
|
|
959
849
|
textAlign: node.align[colIndex]
|
|
960
850
|
};
|
|
961
851
|
};
|
|
962
|
-
|
|
963
852
|
var headers = node.header.map(function (content, i) {
|
|
964
853
|
return reactElement("th", "" + i, {
|
|
965
854
|
style: getStyle(i),
|
|
@@ -987,11 +876,10 @@ var defaultRules = {
|
|
|
987
876
|
})]
|
|
988
877
|
});
|
|
989
878
|
},
|
|
990
|
-
html: function
|
|
879
|
+
html: function (node, output, state) {
|
|
991
880
|
var getStyle = function getStyle(colIndex) {
|
|
992
881
|
return node.align[colIndex] == null ? "" : "text-align:" + node.align[colIndex] + ";";
|
|
993
882
|
};
|
|
994
|
-
|
|
995
883
|
var headers = node.header.map(function (content, i) {
|
|
996
884
|
return htmlTag("th", output(content, state), {
|
|
997
885
|
style: getStyle(i),
|
|
@@ -1015,10 +903,10 @@ var defaultRules = {
|
|
|
1015
903
|
order: currOrder++,
|
|
1016
904
|
match: blockRegex(/^(?:\n *)*\n/),
|
|
1017
905
|
parse: ignoreCapture,
|
|
1018
|
-
react: function
|
|
906
|
+
react: function (node, output, state) {
|
|
1019
907
|
return "\n";
|
|
1020
908
|
},
|
|
1021
|
-
html: function
|
|
909
|
+
html: function (node, output, state) {
|
|
1022
910
|
return "\n";
|
|
1023
911
|
}
|
|
1024
912
|
},
|
|
@@ -1026,13 +914,13 @@ var defaultRules = {
|
|
|
1026
914
|
order: currOrder++,
|
|
1027
915
|
match: blockRegex(/^((?:[^\n]|\n(?! *\n))+)(?:\n *)+\n/),
|
|
1028
916
|
parse: parseCaptureInline,
|
|
1029
|
-
react: function
|
|
917
|
+
react: function (node, output, state) {
|
|
1030
918
|
return reactElement("div", state.key, {
|
|
1031
919
|
className: "paragraph",
|
|
1032
920
|
children: output(node.content, state)
|
|
1033
921
|
});
|
|
1034
922
|
},
|
|
1035
|
-
html: function
|
|
923
|
+
html: function (node, output, state) {
|
|
1036
924
|
var attributes = {
|
|
1037
925
|
class: "paragraph"
|
|
1038
926
|
};
|
|
@@ -1046,62 +934,41 @@ var defaultRules = {
|
|
|
1046
934
|
// escaping anything else provides a very flexible escape mechanism,
|
|
1047
935
|
// regardless of how this grammar is extended.
|
|
1048
936
|
match: inlineRegex(/^\\([^0-9A-Za-z\s])/),
|
|
1049
|
-
parse: function (
|
|
1050
|
-
function parse(_x22, _x23, _x24) {
|
|
1051
|
-
return _parse8.apply(this, arguments);
|
|
1052
|
-
}
|
|
1053
|
-
|
|
1054
|
-
parse.toString = function () {
|
|
1055
|
-
return _parse8.toString();
|
|
1056
|
-
};
|
|
1057
|
-
|
|
1058
|
-
return parse;
|
|
1059
|
-
}(function (capture, parse, state) {
|
|
937
|
+
parse: function (capture, parse, state) {
|
|
1060
938
|
return {
|
|
1061
939
|
type: "text",
|
|
1062
940
|
content: capture[1]
|
|
1063
941
|
};
|
|
1064
|
-
}
|
|
942
|
+
},
|
|
1065
943
|
react: null,
|
|
1066
944
|
html: null
|
|
1067
945
|
},
|
|
1068
946
|
tableSeparator: {
|
|
1069
947
|
order: currOrder++,
|
|
1070
948
|
// $FlowFixMe
|
|
1071
|
-
match: function
|
|
949
|
+
match: function (source, state) {
|
|
1072
950
|
if (!state.inTable) {
|
|
1073
951
|
return null;
|
|
1074
952
|
}
|
|
1075
|
-
|
|
1076
953
|
return /^ *\| */.exec(source);
|
|
1077
954
|
},
|
|
1078
|
-
parse: function
|
|
955
|
+
parse: function () {
|
|
1079
956
|
return {
|
|
1080
957
|
type: "tableSeparator"
|
|
1081
958
|
};
|
|
1082
959
|
},
|
|
1083
960
|
// These shouldn't be reached, but in case they are, be reasonable:
|
|
1084
|
-
react: function
|
|
961
|
+
react: function () {
|
|
1085
962
|
return " | ";
|
|
1086
963
|
},
|
|
1087
|
-
html: function
|
|
964
|
+
html: function () {
|
|
1088
965
|
return " | ";
|
|
1089
966
|
}
|
|
1090
967
|
},
|
|
1091
968
|
autolink: {
|
|
1092
969
|
order: currOrder++,
|
|
1093
970
|
match: inlineRegex(/^<([^: >]+:\/[^ >]+)>/),
|
|
1094
|
-
parse: function (
|
|
1095
|
-
function parse(_x25, _x26, _x27) {
|
|
1096
|
-
return _parse9.apply(this, arguments);
|
|
1097
|
-
}
|
|
1098
|
-
|
|
1099
|
-
parse.toString = function () {
|
|
1100
|
-
return _parse9.toString();
|
|
1101
|
-
};
|
|
1102
|
-
|
|
1103
|
-
return parse;
|
|
1104
|
-
}(function (capture, parse, state) {
|
|
971
|
+
parse: function (capture, parse, state) {
|
|
1105
972
|
return {
|
|
1106
973
|
type: "link",
|
|
1107
974
|
content: [{
|
|
@@ -1110,31 +977,21 @@ var defaultRules = {
|
|
|
1110
977
|
}],
|
|
1111
978
|
target: capture[1]
|
|
1112
979
|
};
|
|
1113
|
-
}
|
|
980
|
+
},
|
|
1114
981
|
react: null,
|
|
1115
982
|
html: null
|
|
1116
983
|
},
|
|
1117
984
|
mailto: {
|
|
1118
985
|
order: currOrder++,
|
|
1119
986
|
match: inlineRegex(/^<([^ >]+@[^ >]+)>/),
|
|
1120
|
-
parse: function (
|
|
1121
|
-
function parse(_x28, _x29, _x30) {
|
|
1122
|
-
return _parse10.apply(this, arguments);
|
|
1123
|
-
}
|
|
1124
|
-
|
|
1125
|
-
parse.toString = function () {
|
|
1126
|
-
return _parse10.toString();
|
|
1127
|
-
};
|
|
1128
|
-
|
|
1129
|
-
return parse;
|
|
1130
|
-
}(function (capture, parse, state) {
|
|
987
|
+
parse: function (capture, parse, state) {
|
|
1131
988
|
var address = capture[1];
|
|
1132
|
-
var target = capture[1];
|
|
989
|
+
var target = capture[1];
|
|
1133
990
|
|
|
991
|
+
// Check for a `mailto:` already existing in the link:
|
|
1134
992
|
if (!AUTOLINK_MAILTO_CHECK_R.test(target)) {
|
|
1135
993
|
target = "mailto:" + target;
|
|
1136
994
|
}
|
|
1137
|
-
|
|
1138
995
|
return {
|
|
1139
996
|
type: "link",
|
|
1140
997
|
content: [{
|
|
@@ -1143,24 +1000,14 @@ var defaultRules = {
|
|
|
1143
1000
|
}],
|
|
1144
1001
|
target: target
|
|
1145
1002
|
};
|
|
1146
|
-
}
|
|
1003
|
+
},
|
|
1147
1004
|
react: null,
|
|
1148
1005
|
html: null
|
|
1149
1006
|
},
|
|
1150
1007
|
url: {
|
|
1151
1008
|
order: currOrder++,
|
|
1152
1009
|
match: inlineRegex(/^(https?:\/\/[^\s<]+[^<.,:;"')\]\s])/),
|
|
1153
|
-
parse: function (
|
|
1154
|
-
function parse(_x31, _x32, _x33) {
|
|
1155
|
-
return _parse11.apply(this, arguments);
|
|
1156
|
-
}
|
|
1157
|
-
|
|
1158
|
-
parse.toString = function () {
|
|
1159
|
-
return _parse11.toString();
|
|
1160
|
-
};
|
|
1161
|
-
|
|
1162
|
-
return parse;
|
|
1163
|
-
}(function (capture, parse, state) {
|
|
1010
|
+
parse: function (capture, parse, state) {
|
|
1164
1011
|
return {
|
|
1165
1012
|
type: "link",
|
|
1166
1013
|
content: [{
|
|
@@ -1170,39 +1017,29 @@ var defaultRules = {
|
|
|
1170
1017
|
target: capture[1],
|
|
1171
1018
|
title: undefined
|
|
1172
1019
|
};
|
|
1173
|
-
}
|
|
1020
|
+
},
|
|
1174
1021
|
react: null,
|
|
1175
1022
|
html: null
|
|
1176
1023
|
},
|
|
1177
1024
|
link: {
|
|
1178
1025
|
order: currOrder++,
|
|
1179
1026
|
match: inlineRegex(new RegExp("^\\[(" + LINK_INSIDE + ")\\]\\(" + LINK_HREF_AND_TITLE + "\\)")),
|
|
1180
|
-
parse: function (
|
|
1181
|
-
function parse(_x34, _x35, _x36) {
|
|
1182
|
-
return _parse12.apply(this, arguments);
|
|
1183
|
-
}
|
|
1184
|
-
|
|
1185
|
-
parse.toString = function () {
|
|
1186
|
-
return _parse12.toString();
|
|
1187
|
-
};
|
|
1188
|
-
|
|
1189
|
-
return parse;
|
|
1190
|
-
}(function (capture, parse, state) {
|
|
1027
|
+
parse: function (capture, parse, state) {
|
|
1191
1028
|
var link = {
|
|
1192
1029
|
content: parse(capture[1], state),
|
|
1193
1030
|
target: unescapeUrl(capture[2]),
|
|
1194
1031
|
title: capture[3]
|
|
1195
1032
|
};
|
|
1196
1033
|
return link;
|
|
1197
|
-
}
|
|
1198
|
-
react: function
|
|
1034
|
+
},
|
|
1035
|
+
react: function (node, output, state) {
|
|
1199
1036
|
return reactElement("a", state.key, {
|
|
1200
1037
|
href: sanitizeUrl(node.target),
|
|
1201
1038
|
title: node.title,
|
|
1202
1039
|
children: output(node.content, state)
|
|
1203
1040
|
});
|
|
1204
1041
|
},
|
|
1205
|
-
html: function
|
|
1042
|
+
html: function (node, output, state) {
|
|
1206
1043
|
var attributes = {
|
|
1207
1044
|
href: sanitizeUrl(node.target),
|
|
1208
1045
|
title: node.title
|
|
@@ -1213,32 +1050,22 @@ var defaultRules = {
|
|
|
1213
1050
|
image: {
|
|
1214
1051
|
order: currOrder++,
|
|
1215
1052
|
match: inlineRegex(new RegExp("^!\\[(" + LINK_INSIDE + ")\\]\\(" + LINK_HREF_AND_TITLE + "\\)")),
|
|
1216
|
-
parse: function (
|
|
1217
|
-
function parse(_x37, _x38, _x39) {
|
|
1218
|
-
return _parse13.apply(this, arguments);
|
|
1219
|
-
}
|
|
1220
|
-
|
|
1221
|
-
parse.toString = function () {
|
|
1222
|
-
return _parse13.toString();
|
|
1223
|
-
};
|
|
1224
|
-
|
|
1225
|
-
return parse;
|
|
1226
|
-
}(function (capture, parse, state) {
|
|
1053
|
+
parse: function (capture, parse, state) {
|
|
1227
1054
|
var image = {
|
|
1228
1055
|
alt: capture[1],
|
|
1229
1056
|
target: unescapeUrl(capture[2]),
|
|
1230
1057
|
title: capture[3]
|
|
1231
1058
|
};
|
|
1232
1059
|
return image;
|
|
1233
|
-
}
|
|
1234
|
-
react: function
|
|
1060
|
+
},
|
|
1061
|
+
react: function (node, output, state) {
|
|
1235
1062
|
return reactElement("img", state.key, {
|
|
1236
1063
|
src: sanitizeUrl(node.target),
|
|
1237
1064
|
alt: node.alt,
|
|
1238
1065
|
title: node.title
|
|
1239
1066
|
});
|
|
1240
1067
|
},
|
|
1241
|
-
html: function
|
|
1068
|
+
html: function (node, output, state) {
|
|
1242
1069
|
var attributes = {
|
|
1243
1070
|
src: sanitizeUrl(node.target),
|
|
1244
1071
|
alt: node.alt,
|
|
@@ -1249,132 +1076,109 @@ var defaultRules = {
|
|
|
1249
1076
|
},
|
|
1250
1077
|
reflink: {
|
|
1251
1078
|
order: currOrder++,
|
|
1252
|
-
match: inlineRegex(new RegExp(
|
|
1253
|
-
|
|
1079
|
+
match: inlineRegex(new RegExp(
|
|
1080
|
+
// The first [part] of the link
|
|
1081
|
+
"^\\[(" + LINK_INSIDE + ")\\]" +
|
|
1082
|
+
// The [ref] target of the link
|
|
1254
1083
|
"\\s*\\[([^\\]]*)\\]")),
|
|
1255
|
-
parse: function (
|
|
1256
|
-
function parse(_x40, _x41, _x42) {
|
|
1257
|
-
return _parse14.apply(this, arguments);
|
|
1258
|
-
}
|
|
1259
|
-
|
|
1260
|
-
parse.toString = function () {
|
|
1261
|
-
return _parse14.toString();
|
|
1262
|
-
};
|
|
1263
|
-
|
|
1264
|
-
return parse;
|
|
1265
|
-
}(function (capture, parse, state) {
|
|
1084
|
+
parse: function (capture, parse, state) {
|
|
1266
1085
|
return parseRef(capture, state, {
|
|
1267
1086
|
type: "link",
|
|
1268
1087
|
content: parse(capture[1], state)
|
|
1269
1088
|
});
|
|
1270
|
-
}
|
|
1089
|
+
},
|
|
1271
1090
|
react: null,
|
|
1272
1091
|
html: null
|
|
1273
1092
|
},
|
|
1274
1093
|
refimage: {
|
|
1275
1094
|
order: currOrder++,
|
|
1276
|
-
match: inlineRegex(new RegExp(
|
|
1277
|
-
|
|
1095
|
+
match: inlineRegex(new RegExp(
|
|
1096
|
+
// The first [part] of the link
|
|
1097
|
+
"^!\\[(" + LINK_INSIDE + ")\\]" +
|
|
1098
|
+
// The [ref] target of the link
|
|
1278
1099
|
"\\s*\\[([^\\]]*)\\]")),
|
|
1279
|
-
parse: function (
|
|
1280
|
-
function parse(_x43, _x44, _x45) {
|
|
1281
|
-
return _parse15.apply(this, arguments);
|
|
1282
|
-
}
|
|
1283
|
-
|
|
1284
|
-
parse.toString = function () {
|
|
1285
|
-
return _parse15.toString();
|
|
1286
|
-
};
|
|
1287
|
-
|
|
1288
|
-
return parse;
|
|
1289
|
-
}(function (capture, parse, state) {
|
|
1100
|
+
parse: function (capture, parse, state) {
|
|
1290
1101
|
return parseRef(capture, state, {
|
|
1291
1102
|
type: "image",
|
|
1292
1103
|
alt: capture[1]
|
|
1293
1104
|
});
|
|
1294
|
-
}
|
|
1105
|
+
},
|
|
1295
1106
|
react: null,
|
|
1296
1107
|
html: null
|
|
1297
1108
|
},
|
|
1298
1109
|
em: {
|
|
1299
|
-
order: currOrder
|
|
1300
|
-
|
|
1301
|
-
|
|
1302
|
-
|
|
1303
|
-
|
|
1304
|
-
"|" +
|
|
1305
|
-
|
|
1306
|
-
"(
|
|
1110
|
+
order: currOrder /* same as strong/u */,
|
|
1111
|
+
match: inlineRegex(new RegExp(
|
|
1112
|
+
// only match _s surrounding words.
|
|
1113
|
+
"^\\b_" + "((?:__|\\\\[\\s\\S]|[^\\\\_])+?)_" + "\\b" +
|
|
1114
|
+
// Or match *s:
|
|
1115
|
+
"|" +
|
|
1116
|
+
// Only match *s that are followed by a non-space:
|
|
1117
|
+
"^\\*(?=\\S)(" +
|
|
1118
|
+
// Match at least one of:
|
|
1119
|
+
"(?:" +
|
|
1120
|
+
// - `**`: so that bolds inside italics don't close the
|
|
1307
1121
|
// italics
|
|
1308
|
-
"\\*\\*|" +
|
|
1309
|
-
|
|
1122
|
+
"\\*\\*|" +
|
|
1123
|
+
// - escape sequence: so escaped *s don't close us
|
|
1124
|
+
"\\\\[\\s\\S]|" +
|
|
1125
|
+
// - whitespace: followed by a non-* (we don't
|
|
1310
1126
|
// want ' *' to close an italics--it might
|
|
1311
1127
|
// start a list)
|
|
1312
|
-
"\\s+(?:\\\\[\\s\\S]|[^\\s\\*\\\\]|\\*\\*)|" +
|
|
1313
|
-
|
|
1128
|
+
"\\s+(?:\\\\[\\s\\S]|[^\\s\\*\\\\]|\\*\\*)|" +
|
|
1129
|
+
// - non-whitespace, non-*, non-backslash characters
|
|
1130
|
+
"[^\\s\\*\\\\]" + ")+?" +
|
|
1131
|
+
// followed by a non-space, non-* then *
|
|
1314
1132
|
")\\*(?!\\*)")),
|
|
1315
|
-
quality: function
|
|
1133
|
+
quality: function (capture) {
|
|
1316
1134
|
// precedence by length, `em` wins ties:
|
|
1317
1135
|
return capture[0].length + 0.2;
|
|
1318
1136
|
},
|
|
1319
|
-
parse: function (
|
|
1320
|
-
function parse(_x46, _x47, _x48) {
|
|
1321
|
-
return _parse16.apply(this, arguments);
|
|
1322
|
-
}
|
|
1323
|
-
|
|
1324
|
-
parse.toString = function () {
|
|
1325
|
-
return _parse16.toString();
|
|
1326
|
-
};
|
|
1327
|
-
|
|
1328
|
-
return parse;
|
|
1329
|
-
}(function (capture, parse, state) {
|
|
1137
|
+
parse: function (capture, parse, state) {
|
|
1330
1138
|
return {
|
|
1331
1139
|
content: parse(capture[2] || capture[1], state)
|
|
1332
1140
|
};
|
|
1333
|
-
}
|
|
1334
|
-
react: function
|
|
1141
|
+
},
|
|
1142
|
+
react: function (node, output, state) {
|
|
1335
1143
|
return reactElement("em", state.key, {
|
|
1336
1144
|
children: output(node.content, state)
|
|
1337
1145
|
});
|
|
1338
1146
|
},
|
|
1339
|
-
html: function
|
|
1147
|
+
html: function (node, output, state) {
|
|
1340
1148
|
return htmlTag("em", output(node.content, state));
|
|
1341
1149
|
}
|
|
1342
1150
|
},
|
|
1343
1151
|
strong: {
|
|
1344
|
-
order: currOrder
|
|
1345
|
-
/* same as em */
|
|
1346
|
-
,
|
|
1152
|
+
order: currOrder /* same as em */,
|
|
1347
1153
|
match: inlineRegex(/^\*\*((?:\\[\s\S]|[^\\])+?)\*\*(?!\*)/),
|
|
1348
|
-
quality: function
|
|
1154
|
+
quality: function (capture) {
|
|
1349
1155
|
// precedence by length, wins ties vs `u`:
|
|
1350
1156
|
return capture[0].length + 0.1;
|
|
1351
1157
|
},
|
|
1352
1158
|
parse: parseCaptureInline,
|
|
1353
|
-
react: function
|
|
1159
|
+
react: function (node, output, state) {
|
|
1354
1160
|
return reactElement("strong", state.key, {
|
|
1355
1161
|
children: output(node.content, state)
|
|
1356
1162
|
});
|
|
1357
1163
|
},
|
|
1358
|
-
html: function
|
|
1164
|
+
html: function (node, output, state) {
|
|
1359
1165
|
return htmlTag("strong", output(node.content, state));
|
|
1360
1166
|
}
|
|
1361
1167
|
},
|
|
1362
1168
|
u: {
|
|
1363
|
-
order: currOrder++
|
|
1364
|
-
/* same as em&strong; increment for next rule */
|
|
1365
|
-
,
|
|
1169
|
+
order: currOrder++ /* same as em&strong; increment for next rule */,
|
|
1366
1170
|
match: inlineRegex(/^__((?:\\[\s\S]|[^\\])+?)__(?!_)/),
|
|
1367
|
-
quality: function
|
|
1171
|
+
quality: function (capture) {
|
|
1368
1172
|
// precedence by length, loses all ties
|
|
1369
1173
|
return capture[0].length;
|
|
1370
1174
|
},
|
|
1371
1175
|
parse: parseCaptureInline,
|
|
1372
|
-
react: function
|
|
1176
|
+
react: function (node, output, state) {
|
|
1373
1177
|
return reactElement("u", state.key, {
|
|
1374
1178
|
children: output(node.content, state)
|
|
1375
1179
|
});
|
|
1376
1180
|
},
|
|
1377
|
-
html: function
|
|
1181
|
+
html: function (node, output, state) {
|
|
1378
1182
|
return htmlTag("u", output(node.content, state));
|
|
1379
1183
|
}
|
|
1380
1184
|
},
|
|
@@ -1382,39 +1186,29 @@ var defaultRules = {
|
|
|
1382
1186
|
order: currOrder++,
|
|
1383
1187
|
match: inlineRegex(/^~~(?=\S)((?:\\[\s\S]|~(?!~)|[^\s~\\]|\s(?!~~))+?)~~/),
|
|
1384
1188
|
parse: parseCaptureInline,
|
|
1385
|
-
react: function
|
|
1189
|
+
react: function (node, output, state) {
|
|
1386
1190
|
return reactElement("del", state.key, {
|
|
1387
1191
|
children: output(node.content, state)
|
|
1388
1192
|
});
|
|
1389
1193
|
},
|
|
1390
|
-
html: function
|
|
1194
|
+
html: function (node, output, state) {
|
|
1391
1195
|
return htmlTag("del", output(node.content, state));
|
|
1392
1196
|
}
|
|
1393
1197
|
},
|
|
1394
1198
|
inlineCode: {
|
|
1395
1199
|
order: currOrder++,
|
|
1396
1200
|
match: inlineRegex(/^(`+)([\s\S]*?[^`])\1(?!`)/),
|
|
1397
|
-
parse: function (
|
|
1398
|
-
function parse(_x49, _x50, _x51) {
|
|
1399
|
-
return _parse17.apply(this, arguments);
|
|
1400
|
-
}
|
|
1401
|
-
|
|
1402
|
-
parse.toString = function () {
|
|
1403
|
-
return _parse17.toString();
|
|
1404
|
-
};
|
|
1405
|
-
|
|
1406
|
-
return parse;
|
|
1407
|
-
}(function (capture, parse, state) {
|
|
1201
|
+
parse: function (capture, parse, state) {
|
|
1408
1202
|
return {
|
|
1409
1203
|
content: capture[2].replace(INLINE_CODE_ESCAPE_BACKTICKS_R, "$1")
|
|
1410
1204
|
};
|
|
1411
|
-
}
|
|
1412
|
-
react: function
|
|
1205
|
+
},
|
|
1206
|
+
react: function (node, output, state) {
|
|
1413
1207
|
return reactElement("code", state.key, {
|
|
1414
1208
|
children: node.content
|
|
1415
1209
|
});
|
|
1416
1210
|
},
|
|
1417
|
-
html: function
|
|
1211
|
+
html: function (node, output, state) {
|
|
1418
1212
|
return htmlTag("code", sanitizeText(node.content));
|
|
1419
1213
|
}
|
|
1420
1214
|
},
|
|
@@ -1422,10 +1216,10 @@ var defaultRules = {
|
|
|
1422
1216
|
order: currOrder++,
|
|
1423
1217
|
match: anyScopeRegex(/^ {2,}\n/),
|
|
1424
1218
|
parse: ignoreCapture,
|
|
1425
|
-
react: function
|
|
1219
|
+
react: function (node, output, state) {
|
|
1426
1220
|
return reactElement("br", state.key, EMPTY_PROPS);
|
|
1427
1221
|
},
|
|
1428
|
-
html: function
|
|
1222
|
+
html: function (node, output, state) {
|
|
1429
1223
|
return "<br>";
|
|
1430
1224
|
}
|
|
1431
1225
|
},
|
|
@@ -1436,88 +1230,74 @@ var defaultRules = {
|
|
|
1436
1230
|
// We break on any symbol characters so that this grammar
|
|
1437
1231
|
// is easy to extend without needing to modify this regex
|
|
1438
1232
|
match: anyScopeRegex(/^[\s\S]+?(?=[^0-9A-Za-z\s\u00c0-\uffff]|\n\n| {2,}\n|\w+:\S|$)/),
|
|
1439
|
-
parse: function (
|
|
1440
|
-
function parse(_x52, _x53, _x54) {
|
|
1441
|
-
return _parse18.apply(this, arguments);
|
|
1442
|
-
}
|
|
1443
|
-
|
|
1444
|
-
parse.toString = function () {
|
|
1445
|
-
return _parse18.toString();
|
|
1446
|
-
};
|
|
1447
|
-
|
|
1448
|
-
return parse;
|
|
1449
|
-
}(function (capture, parse, state) {
|
|
1233
|
+
parse: function (capture, parse, state) {
|
|
1450
1234
|
return {
|
|
1451
1235
|
content: capture[0]
|
|
1452
1236
|
};
|
|
1453
|
-
}
|
|
1454
|
-
react: function
|
|
1237
|
+
},
|
|
1238
|
+
react: function (node, output, state) {
|
|
1455
1239
|
return node.content;
|
|
1456
1240
|
},
|
|
1457
|
-
html: function
|
|
1241
|
+
html: function (node, output, state) {
|
|
1458
1242
|
return sanitizeText(node.content);
|
|
1459
1243
|
}
|
|
1460
1244
|
}
|
|
1461
1245
|
};
|
|
1462
|
-
/** (deprecated) */
|
|
1463
1246
|
|
|
1464
|
-
|
|
1247
|
+
/** (deprecated) */
|
|
1248
|
+
var ruleOutput = function ruleOutput(
|
|
1249
|
+
// $FlowFixMe
|
|
1465
1250
|
rules, property) {
|
|
1466
1251
|
if (!property && typeof console !== "undefined") {
|
|
1467
1252
|
console.warn("simple-markdown ruleOutput should take 'react' or " + "'html' as the second argument.");
|
|
1468
1253
|
}
|
|
1469
|
-
|
|
1470
1254
|
var nestedRuleOutput = function nestedRuleOutput(ast, outputFunc, state) {
|
|
1255
|
+
// @ts-expect-error [FEI-5003] - TS2349 - This expression is not callable.
|
|
1256
|
+
// Type 'unknown' has no call signatures.
|
|
1471
1257
|
return rules[ast.type][property](ast, outputFunc, state);
|
|
1472
1258
|
};
|
|
1473
|
-
|
|
1474
1259
|
return nestedRuleOutput;
|
|
1475
1260
|
};
|
|
1261
|
+
|
|
1476
1262
|
/** (deprecated)
|
|
1477
1263
|
*/
|
|
1478
|
-
|
|
1479
|
-
|
|
1480
1264
|
var reactFor = function reactFor(outputFunc) {
|
|
1481
1265
|
var nestedOutput = function nestedOutput(ast, state) {
|
|
1482
1266
|
state = state || {};
|
|
1483
|
-
|
|
1484
1267
|
if (Array.isArray(ast)) {
|
|
1485
1268
|
var oldKey = state.key;
|
|
1486
|
-
var result = [];
|
|
1487
|
-
// nodes together into a single string output.
|
|
1269
|
+
var result = [];
|
|
1488
1270
|
|
|
1271
|
+
// map nestedOutput over the ast, except group any text
|
|
1272
|
+
// nodes together into a single string output.
|
|
1489
1273
|
var lastResult = null;
|
|
1490
|
-
|
|
1491
1274
|
for (var i = 0; i < ast.length; i++) {
|
|
1492
1275
|
state.key = "" + i;
|
|
1493
1276
|
var nodeOut = nestedOutput(ast[i], state);
|
|
1494
|
-
|
|
1495
1277
|
if (typeof nodeOut === "string" && typeof lastResult === "string") {
|
|
1278
|
+
// @ts-expect-error [FEI-5003] - TS2322 - Type 'string' is not assignable to type 'null'.
|
|
1496
1279
|
lastResult = lastResult + nodeOut;
|
|
1497
1280
|
result[result.length - 1] = lastResult;
|
|
1498
1281
|
} else {
|
|
1499
1282
|
result.push(nodeOut);
|
|
1283
|
+
// @ts-expect-error [FEI-5003] - TS2322 - Type 'ReactNode' is not assignable to type 'null'.
|
|
1500
1284
|
lastResult = nodeOut;
|
|
1501
1285
|
}
|
|
1502
1286
|
}
|
|
1503
|
-
|
|
1504
1287
|
state.key = oldKey;
|
|
1505
1288
|
return result;
|
|
1506
1289
|
} else {
|
|
1507
1290
|
return outputFunc(ast, nestedOutput, state);
|
|
1508
1291
|
}
|
|
1509
1292
|
};
|
|
1510
|
-
|
|
1511
1293
|
return nestedOutput;
|
|
1512
1294
|
};
|
|
1295
|
+
|
|
1513
1296
|
/** (deprecated)
|
|
1514
1297
|
*/
|
|
1515
|
-
|
|
1516
|
-
|
|
1517
1298
|
var htmlFor = function htmlFor(outputFunc) {
|
|
1518
1299
|
var nestedOutput = function nestedOutput(ast, state) {
|
|
1519
1300
|
state = state || {};
|
|
1520
|
-
|
|
1521
1301
|
if (Array.isArray(ast)) {
|
|
1522
1302
|
return ast.map(function (node) {
|
|
1523
1303
|
return nestedOutput(node, state);
|
|
@@ -1526,99 +1306,83 @@ var htmlFor = function htmlFor(outputFunc) {
|
|
|
1526
1306
|
return outputFunc(ast, nestedOutput, state);
|
|
1527
1307
|
}
|
|
1528
1308
|
};
|
|
1529
|
-
|
|
1530
1309
|
return nestedOutput;
|
|
1531
1310
|
};
|
|
1532
|
-
|
|
1533
|
-
var outputFor = function outputFor(rules, property) {
|
|
1534
|
-
var defaultState = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
|
|
1535
|
-
|
|
1311
|
+
var outputFor = function outputFor(rules, property, defaultState = {}) {
|
|
1536
1312
|
if (!property) {
|
|
1537
1313
|
throw new Error("simple-markdown: outputFor: `property` must be " + "defined. " + "if you just upgraded, you probably need to replace `outputFor` " + "with `reactFor`");
|
|
1538
1314
|
}
|
|
1315
|
+
var latestState;
|
|
1316
|
+
var arrayRule = rules.Array || defaultRules.Array;
|
|
1539
1317
|
|
|
1540
|
-
var
|
|
1541
|
-
|
|
1542
|
-
var arrayRule = rules.Array || defaultRules.Array; // Tricks to convince tsc that this var is not null:
|
|
1543
|
-
|
|
1318
|
+
// Tricks to convince tsc that this var is not null:
|
|
1319
|
+
// @ts-expect-error [FEI-5003] - TS2538 - Type 'symbol' cannot be used as an index type.
|
|
1544
1320
|
var arrayRuleCheck = arrayRule[property];
|
|
1545
|
-
|
|
1546
1321
|
if (!arrayRuleCheck) {
|
|
1547
|
-
throw new Error("simple-markdown: outputFor: to join nodes of type `" +
|
|
1322
|
+
throw new Error("simple-markdown: outputFor: to join nodes of type `" +
|
|
1323
|
+
// @ts-expect-error [FEI-5003] - TS2469 - The '+' operator cannot be applied to type 'symbol'.
|
|
1324
|
+
property + "` you must provide an `Array:` joiner rule with that type, " + "Please see the docs for details on specifying an Array rule.");
|
|
1548
1325
|
}
|
|
1549
|
-
|
|
1550
1326
|
var arrayRuleOutput = arrayRuleCheck;
|
|
1551
|
-
|
|
1552
1327
|
var nestedOutput = function nestedOutput(ast, state) {
|
|
1553
1328
|
state = state || latestState;
|
|
1554
1329
|
latestState = state;
|
|
1555
|
-
|
|
1556
1330
|
if (Array.isArray(ast)) {
|
|
1557
1331
|
return arrayRuleOutput(ast, nestedOutput, state);
|
|
1558
1332
|
} else {
|
|
1333
|
+
// @ts-expect-error [FEI-5003] - TS2349 - This expression is not callable.
|
|
1334
|
+
// Type 'unknown' has no call signatures.
|
|
1559
1335
|
return rules[ast.type][property](ast, nestedOutput, state);
|
|
1560
1336
|
}
|
|
1561
1337
|
};
|
|
1562
|
-
|
|
1563
1338
|
var outerOutput = function outerOutput(ast, state) {
|
|
1564
1339
|
latestState = populateInitialState(state, defaultState);
|
|
1565
1340
|
return nestedOutput(ast, latestState);
|
|
1566
1341
|
};
|
|
1567
|
-
|
|
1568
1342
|
return outerOutput;
|
|
1569
|
-
};
|
|
1570
|
-
|
|
1343
|
+
};
|
|
1571
1344
|
|
|
1345
|
+
// @ts-expect-error [FEI-5003] - TS2345 - Argument of type 'DefaultRules' is not assignable to parameter of type 'ParserRules'.
|
|
1572
1346
|
var defaultRawParse = parserFor(defaultRules);
|
|
1573
|
-
|
|
1574
1347
|
var defaultBlockParse = function defaultBlockParse(source, state) {
|
|
1575
1348
|
state = state || {};
|
|
1576
1349
|
state.inline = false;
|
|
1577
1350
|
return defaultRawParse(source, state);
|
|
1578
1351
|
};
|
|
1579
|
-
|
|
1580
1352
|
var defaultInlineParse = function defaultInlineParse(source, state) {
|
|
1581
1353
|
state = state || {};
|
|
1582
1354
|
state.inline = true;
|
|
1583
1355
|
return defaultRawParse(source, state);
|
|
1584
1356
|
};
|
|
1585
|
-
|
|
1586
1357
|
var defaultImplicitParse = function defaultImplicitParse(source, state) {
|
|
1587
1358
|
var isBlock = BLOCK_END_R.test(source);
|
|
1588
1359
|
state = state || {};
|
|
1589
1360
|
state.inline = !isBlock;
|
|
1590
1361
|
return defaultRawParse(source, state);
|
|
1591
|
-
};
|
|
1592
|
-
|
|
1593
|
-
|
|
1594
|
-
var defaultReactOutput = outputFor(defaultRules, "react"); // $FlowFixMe[incompatible-call]
|
|
1595
|
-
|
|
1362
|
+
};
|
|
1363
|
+
var defaultReactOutput = outputFor(defaultRules, "react");
|
|
1596
1364
|
var defaultHtmlOutput = outputFor(defaultRules, "html");
|
|
1597
|
-
|
|
1598
1365
|
var markdownToReact = function markdownToReact(source, state) {
|
|
1599
1366
|
return defaultReactOutput(defaultBlockParse(source, state), state);
|
|
1600
1367
|
};
|
|
1601
|
-
|
|
1602
1368
|
var markdownToHtml = function markdownToHtml(source, state) {
|
|
1603
1369
|
return defaultHtmlOutput(defaultBlockParse(source, state), state);
|
|
1604
|
-
};
|
|
1370
|
+
};
|
|
1605
1371
|
|
|
1372
|
+
// TODO: This needs definition
|
|
1606
1373
|
|
|
1607
1374
|
var ReactMarkdown = function ReactMarkdown(props) {
|
|
1608
1375
|
var divProps = {};
|
|
1609
|
-
|
|
1610
1376
|
for (var prop in props) {
|
|
1611
|
-
if (prop !== "source" &&
|
|
1377
|
+
if (prop !== "source" &&
|
|
1378
|
+
// $FlowFixMe
|
|
1612
1379
|
Object.prototype.hasOwnProperty.call(props, prop)) {
|
|
1613
1380
|
divProps[prop] = props[prop];
|
|
1614
1381
|
}
|
|
1615
1382
|
}
|
|
1616
|
-
|
|
1617
1383
|
divProps.children = markdownToReact(props.source);
|
|
1618
1384
|
return reactElement("div", null, divProps);
|
|
1619
1385
|
};
|
|
1620
|
-
|
|
1621
|
-
// $FlowFixMe
|
|
1622
1386
|
var SimpleMarkdown = {
|
|
1623
1387
|
defaultRules: defaultRules,
|
|
1624
1388
|
parserFor: parserFor,
|
|
@@ -1631,6 +1395,7 @@ var SimpleMarkdown = {
|
|
|
1631
1395
|
// default wrappers:
|
|
1632
1396
|
markdownToReact: markdownToReact,
|
|
1633
1397
|
markdownToHtml: markdownToHtml,
|
|
1398
|
+
// @ts-expect-error [FEI-5003] - TS2322 - Type 'FC<any>' is not assignable to type '(props: { [key: string]: any; source: string; }) => ReactElement'.
|
|
1634
1399
|
ReactMarkdown: ReactMarkdown,
|
|
1635
1400
|
defaultBlockParse: defaultBlockParse,
|
|
1636
1401
|
defaultInlineParse: defaultInlineParse,
|
|
@@ -1648,19 +1413,17 @@ var SimpleMarkdown = {
|
|
|
1648
1413
|
ruleOutput: ruleOutput,
|
|
1649
1414
|
reactFor: reactFor,
|
|
1650
1415
|
htmlFor: htmlFor,
|
|
1651
|
-
defaultParse: function
|
|
1416
|
+
defaultParse: function (...args) {
|
|
1652
1417
|
if (typeof console !== "undefined") {
|
|
1653
1418
|
console.warn("defaultParse is deprecated, please use `defaultImplicitParse`");
|
|
1654
1419
|
}
|
|
1655
|
-
|
|
1656
|
-
return defaultImplicitParse.apply(null, arguments);
|
|
1420
|
+
return defaultImplicitParse.apply(null, args);
|
|
1657
1421
|
},
|
|
1658
|
-
defaultOutput: function
|
|
1422
|
+
defaultOutput: function (...args) {
|
|
1659
1423
|
if (typeof console !== "undefined") {
|
|
1660
1424
|
console.warn("defaultOutput is deprecated, please use `defaultReactOutput`");
|
|
1661
1425
|
}
|
|
1662
|
-
|
|
1663
|
-
return defaultReactOutput.apply(null, arguments);
|
|
1426
|
+
return defaultReactOutput.apply(null, args);
|
|
1664
1427
|
}
|
|
1665
1428
|
};
|
|
1666
1429
|
|