@khanacademy/perseus-linter 7.0.2 → 8.0.0
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.d.ts +0 -1
- package/dist/index.js +403 -308
- package/dist/index.js.map +1 -1
- package/dist/lint.d.ts +24 -0
- package/dist/rule.d.ts +23 -105
- package/dist/rules/all-rules.d.ts +2 -1
- package/dist/rules/explanation.d.ts +2 -0
- package/dist/rules/fill-in-the-blank.d.ts +2 -0
- package/dist/rules/graded-group-set.d.ts +2 -0
- package/dist/rules/graded-group.d.ts +2 -0
- package/dist/rules/group.d.ts +2 -0
- package/dist/rules/lint-graded-group.d.ts +7 -0
- package/dist/run-linter.d.ts +1 -2
- package/package.json +3 -3
package/dist/index.js
CHANGED
|
@@ -1,18 +1,46 @@
|
|
|
1
1
|
import { addLibraryVersionToPerseusDebug as e } from "@khanacademy/perseus-utils";
|
|
2
2
|
import { CoreWidgetRegistry as t, Errors as n, PerseusError as r, SORTER_MAX_CARDS as i, makeSafeUrl as a } from "@khanacademy/perseus-core";
|
|
3
|
-
import
|
|
4
|
-
import
|
|
3
|
+
import { parse as o, traverseContent as s } from "@khanacademy/pure-markdown";
|
|
4
|
+
import * as c from "@khanacademy/kas";
|
|
5
5
|
import { vector as l } from "@khanacademy/kmath";
|
|
6
6
|
//#region \0rolldown/runtime.js
|
|
7
|
-
var u = "@khanacademy/perseus-linter", d = "
|
|
7
|
+
var u = "@khanacademy/perseus-linter", d = "8.0.0";
|
|
8
8
|
e(u, d);
|
|
9
9
|
//#endregion
|
|
10
10
|
//#region packages/perseus-linter/src/proptypes.ts
|
|
11
|
-
var
|
|
11
|
+
var ee = {
|
|
12
12
|
contentType: "",
|
|
13
13
|
highlightLint: !1,
|
|
14
14
|
stack: []
|
|
15
|
-
},
|
|
15
|
+
}, f = {
|
|
16
|
+
ERROR: 1,
|
|
17
|
+
WARNING: 2,
|
|
18
|
+
GUIDELINE: 3
|
|
19
|
+
};
|
|
20
|
+
function linterWarning(e, t) {
|
|
21
|
+
return {
|
|
22
|
+
message: e,
|
|
23
|
+
severity: f.WARNING,
|
|
24
|
+
...t
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
function linterError(e, t) {
|
|
28
|
+
return {
|
|
29
|
+
message: e,
|
|
30
|
+
severity: f.ERROR,
|
|
31
|
+
...t
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
function linterGuideline(e, t) {
|
|
35
|
+
return {
|
|
36
|
+
message: e,
|
|
37
|
+
severity: f.GUIDELINE,
|
|
38
|
+
...t
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
//#endregion
|
|
42
|
+
//#region packages/perseus-linter/src/selector.ts
|
|
43
|
+
var Selector = class {
|
|
16
44
|
static parse(e) {
|
|
17
45
|
return new p(e).parse();
|
|
18
46
|
}
|
|
@@ -180,38 +208,38 @@ var ParseError = class extends Error {
|
|
|
180
208
|
return this.left.toString() + " ~ " + this.right.toString();
|
|
181
209
|
}
|
|
182
210
|
}, m, h = class Rule {
|
|
183
|
-
constructor(e, t, i, a
|
|
184
|
-
if (!
|
|
185
|
-
this.name = e || "unnamed rule", this.
|
|
186
|
-
return !0;
|
|
187
|
-
};
|
|
211
|
+
constructor(e, t, i, a) {
|
|
212
|
+
if (!t && !i) throw new r("Lint rules must have a selector or pattern", n.InvalidInput, { metadata: { name: e } });
|
|
213
|
+
this.name = e || "unnamed rule", this.selector = t || Rule.DEFAULT_SELECTOR, this.pattern = i || null, this.lint = a;
|
|
188
214
|
}
|
|
189
215
|
static makeRule(e) {
|
|
190
|
-
return new Rule(e.name, e.
|
|
216
|
+
return new Rule(e.name, e.selector ? Selector.parse(e.selector) : null, Rule.makePattern(e.pattern), e.lint);
|
|
191
217
|
}
|
|
192
218
|
static makeWidgetRule(e) {
|
|
193
|
-
return new Rule(e.name,
|
|
219
|
+
return new Rule(e.name, Selector.parse("widget"), null, (t, n, r, i, a) => {
|
|
194
220
|
if (t.currentNode().widgetType !== e.widgetType) return;
|
|
195
221
|
let o = t.currentNode().id;
|
|
196
222
|
if (!o) return;
|
|
197
223
|
let s = a?.widgets?.[o];
|
|
198
|
-
if (s) return [e.lint(s)].
|
|
199
|
-
|
|
224
|
+
if (s) return [e.lint(s, a) ?? []].flat().map((e) => ({
|
|
225
|
+
...e,
|
|
226
|
+
message: `${o}: ${e.message}`
|
|
227
|
+
}));
|
|
228
|
+
});
|
|
200
229
|
}
|
|
201
230
|
check(e, t, n, r) {
|
|
202
|
-
let toLinterIssue = (e) =>
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
metadata: e.metadata
|
|
231
|
+
let toLinterIssue = (e) => {
|
|
232
|
+
let { location: t = {
|
|
233
|
+
start: 0,
|
|
234
|
+
end: n.length
|
|
235
|
+
} } = e;
|
|
236
|
+
return {
|
|
237
|
+
rule: this.name,
|
|
238
|
+
severity: e.severity,
|
|
239
|
+
message: e.message,
|
|
240
|
+
metadata: e.metadata,
|
|
241
|
+
...t
|
|
242
|
+
};
|
|
215
243
|
}, toLinterIssues = (e) => e == null ? [] : Array.isArray(e) ? e.map(toLinterIssue) : [toLinterIssue(e)], i = this.selector.match(t);
|
|
216
244
|
if (!i) return [];
|
|
217
245
|
let a;
|
|
@@ -221,7 +249,7 @@ var ParseError = class extends Error {
|
|
|
221
249
|
} catch (e) {
|
|
222
250
|
return [{
|
|
223
251
|
rule: "lint-rule-failure",
|
|
224
|
-
severity:
|
|
252
|
+
severity: Rule.Severity.ERROR,
|
|
225
253
|
message: `Exception in rule ${this.name}: ${e.message}
|
|
226
254
|
Stack trace:
|
|
227
255
|
${e.stack}`,
|
|
@@ -230,12 +258,15 @@ ${e.stack}`,
|
|
|
230
258
|
}];
|
|
231
259
|
}
|
|
232
260
|
}
|
|
233
|
-
|
|
234
|
-
return {
|
|
235
|
-
message:
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
261
|
+
static makeLintFunction({ message: e, severity: t }) {
|
|
262
|
+
return (n, r, i, a, o) => ({
|
|
263
|
+
message: e,
|
|
264
|
+
severity: t,
|
|
265
|
+
location: {
|
|
266
|
+
start: a.index,
|
|
267
|
+
end: a.index + a[0].length
|
|
268
|
+
}
|
|
269
|
+
});
|
|
239
270
|
}
|
|
240
271
|
static makePattern(e) {
|
|
241
272
|
if (!e) return null;
|
|
@@ -251,28 +282,55 @@ ${e.stack}`,
|
|
|
251
282
|
return r.index = n, r.input = e, r;
|
|
252
283
|
}
|
|
253
284
|
};
|
|
254
|
-
m = h, m.Severity =
|
|
255
|
-
ERROR: 1,
|
|
256
|
-
WARNING: 2,
|
|
257
|
-
GUIDELINE: 3
|
|
258
|
-
}, h.DEFAULT_SELECTOR = Selector.parse("text");
|
|
285
|
+
m = h, m.Severity = f, h.DEFAULT_SELECTOR = Selector.parse("text");
|
|
259
286
|
//#endregion
|
|
260
287
|
//#region packages/perseus-linter/src/rules/lint-utils.ts
|
|
261
|
-
var
|
|
288
|
+
var g = /\/\/([^/]+)/;
|
|
262
289
|
function getHostname(e) {
|
|
263
290
|
if (!e) return "";
|
|
264
|
-
let t = e.match(
|
|
291
|
+
let t = e.match(g);
|
|
265
292
|
return t ? t[1] : "";
|
|
266
293
|
}
|
|
267
294
|
//#endregion
|
|
268
295
|
//#region packages/perseus-linter/src/rules/absolute-url.ts
|
|
269
|
-
var
|
|
296
|
+
var te = h.makeRule({
|
|
270
297
|
name: "absolute-url",
|
|
271
|
-
severity: h.Severity.GUIDELINE,
|
|
272
298
|
selector: "link, image",
|
|
273
299
|
lint: function(e, t, n, r) {
|
|
274
300
|
let i = n[0].target, a = getHostname(i);
|
|
275
|
-
if (a === "khanacademy.org" || a.endsWith(".khanacademy.org")) return "Don't use absolute URLs:\nWhen linking to KA content or images, omit the\nhttps://www.khanacademy.org URL prefix.\nUse a relative URL beginning with / instead.";
|
|
301
|
+
if (a === "khanacademy.org" || a.endsWith(".khanacademy.org")) return linterGuideline("Don't use absolute URLs:\nWhen linking to KA content or images, omit the\nhttps://www.khanacademy.org URL prefix.\nUse a relative URL beginning with / instead.");
|
|
302
|
+
}
|
|
303
|
+
});
|
|
304
|
+
//#endregion
|
|
305
|
+
//#region packages/perseus-linter/src/lint-content.ts
|
|
306
|
+
function lintPerseusItem(e) {
|
|
307
|
+
return {
|
|
308
|
+
question: lintPerseusRenderer(e.question, "exercise"),
|
|
309
|
+
hints: e.hints.map((e) => lintPerseusRenderer(e, "exercise"))
|
|
310
|
+
};
|
|
311
|
+
}
|
|
312
|
+
function lintPerseusArticle(e) {
|
|
313
|
+
return (Array.isArray(e) ? e : [e]).map((e) => lintPerseusRenderer(e, "article"));
|
|
314
|
+
}
|
|
315
|
+
function lintPerseusRenderer(e, t) {
|
|
316
|
+
return [...runLinter(o(e.content), {
|
|
317
|
+
content: e.content,
|
|
318
|
+
widgets: e.widgets,
|
|
319
|
+
stack: [],
|
|
320
|
+
contentType: t
|
|
321
|
+
}, !1)];
|
|
322
|
+
}
|
|
323
|
+
//#endregion
|
|
324
|
+
//#region packages/perseus-linter/src/rules/explanation.ts
|
|
325
|
+
var ne = h.makeWidgetRule({
|
|
326
|
+
name: "explanation",
|
|
327
|
+
widgetType: "explanation",
|
|
328
|
+
lint(e, t) {
|
|
329
|
+
return lintPerseusRenderer({
|
|
330
|
+
content: e.options.explanation,
|
|
331
|
+
widgets: e.options.widgets,
|
|
332
|
+
images: {}
|
|
333
|
+
}, t);
|
|
276
334
|
}
|
|
277
335
|
});
|
|
278
336
|
//#endregion
|
|
@@ -280,20 +338,18 @@ var g = h.makeRule({
|
|
|
280
338
|
function hasExplanation(e) {
|
|
281
339
|
return Object.values(e).some((e) => e.type === "explanation");
|
|
282
340
|
}
|
|
283
|
-
var _ = "Don't use explanation widgets in graded groups. Use the Graded Group Hint instead.",
|
|
341
|
+
var _ = "Don't use explanation widgets in graded groups. Use the Graded Group Hint instead.", re = h.makeWidgetRule({
|
|
284
342
|
name: "explanation-in-graded-group",
|
|
285
|
-
severity: h.Severity.WARNING,
|
|
286
343
|
widgetType: "graded-group",
|
|
287
344
|
lint: function(e) {
|
|
288
|
-
if (hasExplanation(e.options.widgets)) return `Contains explanation widget. ${_}
|
|
345
|
+
if (hasExplanation(e.options.widgets)) return linterWarning(`Contains explanation widget. ${_}`);
|
|
289
346
|
}
|
|
290
|
-
}),
|
|
347
|
+
}), v = h.makeWidgetRule({
|
|
291
348
|
name: "explanation-in-graded-group-set",
|
|
292
|
-
severity: h.Severity.WARNING,
|
|
293
349
|
widgetType: "graded-group-set",
|
|
294
350
|
lint: function(e) {
|
|
295
351
|
let t = e.options.gradedGroups.map((e, t) => hasExplanation(e.widgets) ? t + 1 : 0).filter((e) => e > 0);
|
|
296
|
-
if (t.length > 0) return `Explanation widget in group ${t.join(" and ")}. ${_}
|
|
352
|
+
if (t.length > 0) return linterWarning(`Explanation widget in group ${t.join(" and ")}. ${_}`);
|
|
297
353
|
}
|
|
298
354
|
});
|
|
299
355
|
//#endregion
|
|
@@ -301,7 +357,7 @@ var _ = "Don't use explanation widgets in graded groups. Use the Graded Group Hi
|
|
|
301
357
|
function buttonNotInButtonSet(e, t) {
|
|
302
358
|
return `Answer requires a button not found in the button sets: ${e} (in ${t})`;
|
|
303
359
|
}
|
|
304
|
-
var
|
|
360
|
+
var y = {
|
|
305
361
|
"\\sqrt": "prealgebra",
|
|
306
362
|
"^": "prealgebra",
|
|
307
363
|
"\\sin": "trig",
|
|
@@ -309,27 +365,24 @@ var re = {
|
|
|
309
365
|
"\\tan": "trig",
|
|
310
366
|
"\\log": "logarithms",
|
|
311
367
|
"\\ln": "logarithms"
|
|
312
|
-
},
|
|
368
|
+
}, b = h.makeWidgetRule({
|
|
313
369
|
name: "expression-widget-buttons",
|
|
314
370
|
widgetType: "expression",
|
|
315
|
-
severity: h.Severity.WARNING,
|
|
316
371
|
lint(e) {
|
|
317
372
|
let t = e.options.answerForms, n = e.options.buttonSets;
|
|
318
|
-
for (let e of t) for (let [t, r] of Object.entries(
|
|
373
|
+
for (let e of t) for (let [t, r] of Object.entries(y)) if (e.value.includes(t) && !n.includes(r)) return linterWarning(buttonNotInButtonSet(t, r));
|
|
319
374
|
}
|
|
320
|
-
}),
|
|
375
|
+
}), x = h.makeWidgetRule({
|
|
321
376
|
name: "expression-widget-correct-answer",
|
|
322
377
|
widgetType: "expression",
|
|
323
|
-
severity: h.Severity.ERROR,
|
|
324
378
|
lint(e) {
|
|
325
379
|
let { answerForms: t } = e.options;
|
|
326
|
-
if (t.length === 0) return "No answers specified.";
|
|
327
|
-
if (!t.some((e) => e.considered === "correct")) return "No correct answer specified.";
|
|
380
|
+
if (t.length === 0) return linterError("No answers specified.");
|
|
381
|
+
if (!t.some((e) => e.considered === "correct")) return linterError("No correct answer specified.");
|
|
328
382
|
}
|
|
329
|
-
}),
|
|
383
|
+
}), S = h.makeWidgetRule({
|
|
330
384
|
name: "expression-widget-answer-forms",
|
|
331
385
|
widgetType: "expression",
|
|
332
|
-
severity: h.Severity.ERROR,
|
|
333
386
|
lint(e) {
|
|
334
387
|
let { answerForms: t, functions: n } = e.options, r = [];
|
|
335
388
|
return t.forEach((e, t) => {
|
|
@@ -337,43 +390,91 @@ var re = {
|
|
|
337
390
|
r.push(`Answer ${t + 1} is empty.`);
|
|
338
391
|
return;
|
|
339
392
|
}
|
|
340
|
-
let i =
|
|
393
|
+
let i = c.parse(e.value, { functions: n });
|
|
341
394
|
i.parsed ? e.simplify && !i.expr.isSimplified() && r.push(`${e.value} isn't simplified, but is required to be.`) : r.push(`Couldn't parse ${e.value}.`);
|
|
342
|
-
}), r;
|
|
343
|
-
}
|
|
344
|
-
}),
|
|
395
|
+
}), r.map((e) => linterError(e));
|
|
396
|
+
}
|
|
397
|
+
}), C = h.makeWidgetRule({
|
|
398
|
+
name: "fill-in-the-blank",
|
|
399
|
+
widgetType: "fill-in-the-blank",
|
|
400
|
+
lint(e, t) {
|
|
401
|
+
return lintPerseusRenderer({
|
|
402
|
+
content: e.options.content,
|
|
403
|
+
widgets: e.options.widgets,
|
|
404
|
+
images: {}
|
|
405
|
+
}, t);
|
|
406
|
+
}
|
|
407
|
+
}), w = /\[\[\u2603 (([a-z-]+) ([0-9]+))\]\]/, T = h.makeWidgetRule({
|
|
345
408
|
name: "free-response-widget-error",
|
|
346
409
|
widgetType: "free-response",
|
|
347
|
-
severity: h.Severity.ERROR,
|
|
348
410
|
lint(e) {
|
|
349
411
|
let t = e.options.question;
|
|
350
|
-
if (!t) return "The question is empty";
|
|
351
|
-
if (t.match(
|
|
412
|
+
if (!t) return linterError("The question is empty");
|
|
413
|
+
if (t.match(w) != null) return linterError("The question contains a widget");
|
|
352
414
|
}
|
|
353
|
-
})
|
|
415
|
+
});
|
|
416
|
+
//#endregion
|
|
417
|
+
//#region packages/perseus-linter/src/rules/lint-graded-group.ts
|
|
418
|
+
function lintGradedGroup(e, { contentType: t }) {
|
|
419
|
+
let { hint: n } = e, r = [...lintPerseusRenderer(e, t)];
|
|
420
|
+
if (n) {
|
|
421
|
+
let e = lintPerseusRenderer(n, t).map((e) => ({
|
|
422
|
+
...e,
|
|
423
|
+
message: `(in hint) ${e.message}`
|
|
424
|
+
}));
|
|
425
|
+
r.push(...e);
|
|
426
|
+
}
|
|
427
|
+
return r;
|
|
428
|
+
}
|
|
429
|
+
//#endregion
|
|
430
|
+
//#region packages/perseus-linter/src/rules/graded-group.ts
|
|
431
|
+
var E = h.makeWidgetRule({
|
|
432
|
+
name: "graded-group",
|
|
433
|
+
widgetType: "graded-group",
|
|
434
|
+
lint: (e, t) => lintGradedGroup(e.options, t)
|
|
435
|
+
}), D = h.makeWidgetRule({
|
|
436
|
+
name: "graded-group-set",
|
|
437
|
+
widgetType: "graded-group-set",
|
|
438
|
+
lint: (e, t) => e.options.gradedGroups.flatMap((e, n) => lintGradedGroup(e, t).map(prefixGroupNumber(n + 1)))
|
|
439
|
+
});
|
|
440
|
+
function prefixGroupNumber(e) {
|
|
441
|
+
return (t) => ({
|
|
442
|
+
...t,
|
|
443
|
+
message: `group ${e}: ${t.message}`
|
|
444
|
+
});
|
|
445
|
+
}
|
|
446
|
+
//#endregion
|
|
447
|
+
//#region packages/perseus-linter/src/rules/group.ts
|
|
448
|
+
var O = h.makeWidgetRule({
|
|
449
|
+
name: "group",
|
|
450
|
+
widgetType: "group",
|
|
451
|
+
lint(e, t) {
|
|
452
|
+
return lintPerseusRenderer(e.options, t);
|
|
453
|
+
}
|
|
454
|
+
}), k = h.makeRule({
|
|
354
455
|
name: "heading-level-1",
|
|
355
|
-
severity: h.Severity.WARNING,
|
|
356
456
|
selector: "heading",
|
|
357
457
|
lint: function(e, t, n, r) {
|
|
358
|
-
if (n[0].level === 1) return "Don't use level-1 headings:\nBegin headings with two or more # characters.";
|
|
458
|
+
if (n[0].level === 1) return linterWarning("Don't use level-1 headings:\nBegin headings with two or more # characters.");
|
|
359
459
|
}
|
|
360
|
-
}),
|
|
460
|
+
}), A = h.makeRule({
|
|
361
461
|
name: "heading-level-skip",
|
|
362
|
-
severity: h.Severity.WARNING,
|
|
363
462
|
selector: "heading ~ heading",
|
|
364
463
|
lint: function(e, t, n, r) {
|
|
365
464
|
let i = n[1], a = n[0];
|
|
366
|
-
if (i.level > a.level + 1) return `Skipped heading level:
|
|
465
|
+
if (i.level > a.level + 1) return linterWarning(`Skipped heading level:
|
|
367
466
|
this heading is level ${i.level} but
|
|
368
|
-
the previous heading was level ${a.level}
|
|
467
|
+
the previous heading was level ${a.level}`);
|
|
369
468
|
}
|
|
370
|
-
}),
|
|
469
|
+
}), j = h.makeRule({
|
|
371
470
|
name: "heading-sentence-case",
|
|
372
|
-
severity: h.Severity.GUIDELINE,
|
|
373
471
|
selector: "heading",
|
|
374
472
|
pattern: /^\W*[a-z]/,
|
|
375
|
-
|
|
376
|
-
|
|
473
|
+
lint: h.makeLintFunction({
|
|
474
|
+
severity: h.Severity.GUIDELINE,
|
|
475
|
+
message: "First letter is lowercase:\nthe first letter of a heading should be capitalized."
|
|
476
|
+
})
|
|
477
|
+
}), M = {
|
|
377
478
|
and: !0,
|
|
378
479
|
nor: !0,
|
|
379
480
|
but: !0,
|
|
@@ -384,115 +485,107 @@ function isCapitalized(e) {
|
|
|
384
485
|
let t = e[0];
|
|
385
486
|
return t === t.toUpperCase();
|
|
386
487
|
}
|
|
387
|
-
var
|
|
488
|
+
var N = h.makeRule({
|
|
388
489
|
name: "heading-title-case",
|
|
389
|
-
severity: h.Severity.GUIDELINE,
|
|
390
490
|
selector: "heading",
|
|
391
491
|
pattern: /[^\s:]\s+[A-Z]+[a-z]/,
|
|
392
492
|
locale: "en",
|
|
393
493
|
lint: function(e, t, n, r) {
|
|
394
494
|
let i = t.trim().split(/\s+/);
|
|
395
|
-
if (i.shift(), i = i.filter((e) => e.length > 2 && !
|
|
495
|
+
if (i.shift(), i = i.filter((e) => e.length > 2 && !M.hasOwnProperty(e)), i.length >= 3 && i.every((e) => isCapitalized(e))) return linterGuideline("Title-case heading:\nThis heading appears to be in title-case, but should be sentence-case.\nOnly capitalize the first letter and proper nouns.");
|
|
396
496
|
}
|
|
397
|
-
}),
|
|
497
|
+
}), P = h.makeRule({
|
|
398
498
|
name: "image-alt-text",
|
|
399
|
-
severity: h.Severity.WARNING,
|
|
400
499
|
selector: "image",
|
|
401
500
|
lint: function(e, t, n, r) {
|
|
402
501
|
let i = n[0];
|
|
403
|
-
if (!i.alt || !i.alt.trim()) return "Images should have alt text:\nfor accessibility, all images should have alt text.\nSpecify alt text inside square brackets after the !.";
|
|
404
|
-
if (i.alt.length < 8) return `Images should have alt text:
|
|
502
|
+
if (!i.alt || !i.alt.trim()) return linterWarning("Images should have alt text:\nfor accessibility, all images should have alt text.\nSpecify alt text inside square brackets after the !.");
|
|
503
|
+
if (i.alt.length < 8) return linterWarning(`Images should have alt text:
|
|
405
504
|
for accessibility, all images should have descriptive alt text.
|
|
406
|
-
This image's alt text is only ${i.alt.length} characters long
|
|
505
|
+
This image's alt text is only ${i.alt.length} characters long.`);
|
|
407
506
|
}
|
|
408
|
-
}),
|
|
507
|
+
}), F = h.makeRule({
|
|
409
508
|
name: "image-markdown",
|
|
410
|
-
severity: h.Severity.WARNING,
|
|
411
509
|
selector: "image",
|
|
412
510
|
lint: function(e, t, n, r, i) {
|
|
413
511
|
if (i?.stack && i.stack.includes("widget")) return;
|
|
414
|
-
let a =
|
|
415
|
-
if (
|
|
416
|
-
e.type === "image" && (
|
|
417
|
-
}),
|
|
512
|
+
let a = o(i?.content || "", {}), c = !1;
|
|
513
|
+
if (s(a, (e) => {
|
|
514
|
+
e.type === "image" && (c = !0);
|
|
515
|
+
}), c) return linterWarning("[Inline markdown image]:\nMarkdown images are not recommended - these are images that use the\n format. Please use the Image widget instead.");
|
|
418
516
|
}
|
|
419
|
-
}),
|
|
517
|
+
}), I = h.makeRule({
|
|
420
518
|
name: "image-spaces-around-urls",
|
|
421
|
-
severity: h.Severity.ERROR,
|
|
422
519
|
selector: "image",
|
|
423
520
|
lint: function(e, t, n, r, i) {
|
|
424
521
|
let a = n[0].target;
|
|
425
522
|
if (i && i.content) {
|
|
426
523
|
let e = i.content.indexOf(a);
|
|
427
524
|
if (e === -1) return;
|
|
428
|
-
if (i.content[e - 1] !== "(" || i.content[e + a.length] !== ")") return "Whitespace before or after image url:\nFor images, don't include any space or newlines after '(' or before ')'.\nWhitespace in image URLs causes translation difficulties.";
|
|
525
|
+
if (i.content[e - 1] !== "(" || i.content[e + a.length] !== ")") return linterError("Whitespace before or after image url:\nFor images, don't include any space or newlines after '(' or before ')'.\nWhitespace in image URLs causes translation difficulties.");
|
|
429
526
|
}
|
|
430
527
|
}
|
|
431
|
-
}),
|
|
528
|
+
}), L = h.makeRule({
|
|
432
529
|
name: "image-url-empty",
|
|
433
|
-
severity: h.Severity.ERROR,
|
|
434
530
|
selector: "image",
|
|
435
531
|
lint: function(e, t, n) {
|
|
436
532
|
let r = n[0].target;
|
|
437
|
-
if (!r || !r.trim()) return "Images should have a URL";
|
|
533
|
+
if (!r || !r.trim()) return linterError("Images should have a URL");
|
|
438
534
|
}
|
|
439
|
-
}),
|
|
535
|
+
}), R = h.makeWidgetRule({
|
|
440
536
|
name: "image-widget-alt-text",
|
|
441
537
|
widgetType: "image",
|
|
442
|
-
severity: h.Severity.WARNING,
|
|
443
538
|
lint(e) {
|
|
444
539
|
if (e.options.decorative) return;
|
|
445
540
|
let t = e.options.alt;
|
|
446
|
-
if (!t) return "Images should have alt text:\nfor accessibility, all images should have a text description.\nAdd a description in the \"Alt Text\" box of the image widget.";
|
|
447
|
-
if (t.trim().length < 8) return `Images should have alt text:
|
|
541
|
+
if (!t) return linterWarning("Images should have alt text:\nfor accessibility, all images should have a text description.\nAdd a description in the \"Alt Text\" box of the image widget.");
|
|
542
|
+
if (t.trim().length < 8) return linterWarning(`Images should have alt text:
|
|
448
543
|
for accessibility, all images should have descriptive alt text.
|
|
449
|
-
This image's alt text is only ${t.trim().length} characters long
|
|
450
|
-
if (t.trim().length > 125) return `Images should have alt text:
|
|
544
|
+
This image's alt text is only ${t.trim().length} characters long.`);
|
|
545
|
+
if (t.trim().length > 125) return linterWarning(`Images should have alt text:
|
|
451
546
|
for accessibility, image alt text should not exceed 125 characters.
|
|
452
547
|
This image's alt text is ${t.trim().length} characters long.
|
|
453
548
|
Please pair your alt with a long description below if you need significantly
|
|
454
|
-
more text to sufficiently describe the image
|
|
549
|
+
more text to sufficiently describe the image.`);
|
|
455
550
|
}
|
|
456
|
-
}),
|
|
551
|
+
}), z = h.makeWidgetRule({
|
|
457
552
|
name: "image-widget-empty-size",
|
|
458
553
|
widgetType: "image",
|
|
459
|
-
severity: h.Severity.WARNING,
|
|
460
554
|
lint(e) {
|
|
461
555
|
if (!e.options.backgroundImage.url) return;
|
|
462
556
|
let { width: t, height: n } = e.options.backgroundImage;
|
|
463
|
-
if (!t || !n) return `Images should have a non-zero size.
|
|
557
|
+
if (!t || !n) return linterWarning(`Images should have a non-zero size.
|
|
464
558
|
This image has a width of ${t} and a height of ${n}.
|
|
465
|
-
Please use the "Reset to original size" button to set the size of the image
|
|
559
|
+
Please use the "Reset to original size" button to set the size of the image.`);
|
|
466
560
|
}
|
|
467
|
-
}),
|
|
561
|
+
}), B = h.makeRule({
|
|
468
562
|
name: "inaccessible-widget",
|
|
469
|
-
severity: h.Severity.WARNING,
|
|
470
563
|
selector: "widget",
|
|
471
564
|
lint: function(e, n, r, i, a) {
|
|
472
565
|
let o = e.currentNode(), s = o.widgetType, c = o.id;
|
|
473
566
|
if (!s || !c) return;
|
|
474
567
|
let l = a?.widgets?.[c];
|
|
475
|
-
if (l && !t.isAccessible(s, l.options)) return {
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
568
|
+
if (l && !t.isAccessible(s, l.options)) return linterWarning(`The "${s}" widget is not accessible.`, {
|
|
569
|
+
location: {
|
|
570
|
+
start: 0,
|
|
571
|
+
end: n.length
|
|
572
|
+
},
|
|
479
573
|
metadata: {
|
|
480
574
|
widgetType: s,
|
|
481
575
|
widgetId: c
|
|
482
576
|
}
|
|
483
|
-
};
|
|
577
|
+
});
|
|
484
578
|
}
|
|
485
|
-
}),
|
|
579
|
+
}), V = h.makeWidgetRule({
|
|
486
580
|
name: "interactive-graph-locked-figure-oob",
|
|
487
581
|
widgetType: "interactive-graph",
|
|
488
|
-
severity: h.Severity.WARNING,
|
|
489
582
|
lint(e) {
|
|
490
583
|
let { range: t, lockedFigures: n } = e.options, r = [];
|
|
491
584
|
for (let e of n ?? []) if (!hasPointInRange(e, t)) {
|
|
492
585
|
let t = getPreciseFigureType(e), n = e.type === "point" || e.type === "label";
|
|
493
586
|
r.push(n ? `Locked ${t} is outside the graph bounds.` : `All defining points for locked ${t} are outside the graph bounds.`);
|
|
494
587
|
}
|
|
495
|
-
return r;
|
|
588
|
+
return r.map((e) => linterWarning(e));
|
|
496
589
|
}
|
|
497
590
|
});
|
|
498
591
|
function getPreciseFigureType(e) {
|
|
@@ -530,10 +623,9 @@ function definingPoints(e) {
|
|
|
530
623
|
}
|
|
531
624
|
//#endregion
|
|
532
625
|
//#region packages/perseus-linter/src/rules/interactive-graph-widget-error.ts
|
|
533
|
-
var
|
|
626
|
+
var H = h.makeWidgetRule({
|
|
534
627
|
name: "interactive-graph-widget-error",
|
|
535
628
|
widgetType: "interactive-graph",
|
|
536
|
-
severity: h.Severity.ERROR,
|
|
537
629
|
lint(e) {
|
|
538
630
|
let t = [], { correct: n, graph: r, lockedFigures: i } = e.options;
|
|
539
631
|
for (let e of i ?? []) e.type === "line" && l.equal(e.points[0].coord, e.points[1].coord) && t.push("Locked line cannot have length 0."), e.type === "polygon" && e.points.every((t) => l.equal(t, e.points[0])) && t.push("Locked polygon cannot have all coordinates be the same."), e.type === "ellipse" && (e.radius[0] <= 0 || e.radius[1] <= 0) && t.push("Locked ellipse must have positive radius values.");
|
|
@@ -541,7 +633,7 @@ var F = h.makeWidgetRule({
|
|
|
541
633
|
let { coords: e, asymptote: n } = r.startCoords, i = n, a = Math.min(e[0][1], e[1][1]), o = Math.max(e[0][1], e[1][1]);
|
|
542
634
|
i >= a && i <= o && t.push("The exponential start asymptote must not fall between or on the curve's start points.");
|
|
543
635
|
}
|
|
544
|
-
return checkShowPointLabelsHasLabels(r, t), checkShowPointLabelsHasLabels(n, t), t;
|
|
636
|
+
return checkShowPointLabelsHasLabels(r, t), checkShowPointLabelsHasLabels(n, t), t.map((e) => linterError(e));
|
|
545
637
|
}
|
|
546
638
|
});
|
|
547
639
|
function checkShowPointLabelsHasLabels(e, t) {
|
|
@@ -575,10 +667,9 @@ function expectedLabelCount(e) {
|
|
|
575
667
|
}
|
|
576
668
|
//#endregion
|
|
577
669
|
//#region packages/perseus-linter/src/rules/label-image-widget-error.ts
|
|
578
|
-
var
|
|
670
|
+
var U = h.makeWidgetRule({
|
|
579
671
|
name: "label-image-widget-error",
|
|
580
672
|
widgetType: "label-image",
|
|
581
|
-
severity: h.Severity.ERROR,
|
|
582
673
|
lint(e) {
|
|
583
674
|
let t = [], { choices: n, imageAlt: r, imageUrl: i, markers: a } = e.options;
|
|
584
675
|
if (n.length < 2 && t.push("label-image widget must have at least two answer choices"), i ? r || t.push("No image alt text provided") : t.push("No image url provided"), a.length === 0) t.push("label-image widget requires at least one marker");
|
|
@@ -587,57 +678,59 @@ var I = h.makeWidgetRule({
|
|
|
587
678
|
for (let t of a) t.answers.length === 0 && e++, t.label || n++;
|
|
588
679
|
e > 0 && t.push(`label-image widget has ${e} markers with no answers selected`), n > 0 && t.push(`label-image widget has ${n} markers with no ARIA label`);
|
|
589
680
|
}
|
|
590
|
-
return t;
|
|
681
|
+
return t.map((e) => linterError(e));
|
|
591
682
|
}
|
|
592
|
-
}),
|
|
683
|
+
}), W = "ka-perseus-images.s3.amazonaws.com", G = h.makeWidgetRule({
|
|
593
684
|
name: "legacy-gif-url",
|
|
594
685
|
widgetType: "image",
|
|
595
|
-
severity: h.Severity.GUIDELINE,
|
|
596
686
|
lint(e) {
|
|
597
687
|
let t = e.options?.backgroundImage?.url;
|
|
598
|
-
if (t && getHostname(t) ===
|
|
599
|
-
gifs hosted at ${
|
|
688
|
+
if (t && getHostname(t) === W && t.toLowerCase().endsWith(".gif")) return linterGuideline(`Legacy gif URL:
|
|
689
|
+
gifs hosted at ${W} might not appear in the editor preview,
|
|
600
690
|
but can still be viewed in the published content. Please use a
|
|
601
691
|
cdn.kastatic.org/ka-perseus-images/ URL instead or confirm the
|
|
602
|
-
image displays correctly in the published content
|
|
692
|
+
image displays correctly in the published content.`);
|
|
603
693
|
}
|
|
604
|
-
}),
|
|
694
|
+
}), ie = h.makeRule({
|
|
605
695
|
name: "link-click-here",
|
|
606
|
-
severity: h.Severity.WARNING,
|
|
607
696
|
selector: "link",
|
|
608
697
|
pattern: /click here/i,
|
|
609
|
-
|
|
610
|
-
|
|
698
|
+
lint: h.makeLintFunction({
|
|
699
|
+
severity: h.Severity.WARNING,
|
|
700
|
+
message: "Inappropriate link text:\nDo not use the words \"click here\" in links."
|
|
701
|
+
})
|
|
702
|
+
}), K = h.makeRule({
|
|
611
703
|
name: "long-paragraph",
|
|
612
|
-
severity: h.Severity.GUIDELINE,
|
|
613
704
|
selector: "paragraph",
|
|
614
705
|
pattern: /^.{501,}/,
|
|
615
706
|
lint: function(e, t, n, r) {
|
|
616
|
-
return `Paragraph too long:
|
|
707
|
+
return linterGuideline(`Paragraph too long:
|
|
617
708
|
This paragraph is ${t.length} characters long.
|
|
618
|
-
Shorten it to 500 characters or fewer
|
|
709
|
+
Shorten it to 500 characters or fewer.`);
|
|
619
710
|
}
|
|
620
|
-
}),
|
|
711
|
+
}), q = h.makeWidgetRule({
|
|
621
712
|
name: "matcher-widget-error",
|
|
622
713
|
widgetType: "matcher",
|
|
623
|
-
severity: h.Severity.ERROR,
|
|
624
714
|
lint(e) {
|
|
625
|
-
if (e.options.left.length !== e.options.right.length) return "The two halves of the matcher have different numbers of cards.";
|
|
715
|
+
if (e.options.left.length !== e.options.right.length) return linterError("The two halves of the matcher have different numbers of cards.");
|
|
626
716
|
}
|
|
627
|
-
}),
|
|
717
|
+
}), J = h.makeRule({
|
|
628
718
|
name: "math-adjacent",
|
|
629
|
-
severity: h.Severity.WARNING,
|
|
630
719
|
selector: "blockMath+blockMath",
|
|
631
|
-
|
|
632
|
-
|
|
720
|
+
lint: h.makeLintFunction({
|
|
721
|
+
severity: h.Severity.WARNING,
|
|
722
|
+
message: "Adjacent math blocks:\ncombine the blocks between \\begin{align} and \\end{align}"
|
|
723
|
+
})
|
|
724
|
+
}), Y = h.makeRule({
|
|
633
725
|
name: "math-align-extra-break",
|
|
634
|
-
severity: h.Severity.WARNING,
|
|
635
726
|
selector: "blockMath",
|
|
636
727
|
pattern: /(\\{2,})\s*\\end{align}/,
|
|
637
|
-
|
|
638
|
-
|
|
728
|
+
lint: h.makeLintFunction({
|
|
729
|
+
severity: h.Severity.WARNING,
|
|
730
|
+
message: "Extra space at end of block:\nDon't end an align block with backslashes"
|
|
731
|
+
})
|
|
732
|
+
}), ae = h.makeRule({
|
|
639
733
|
name: "math-align-linebreaks",
|
|
640
|
-
severity: h.Severity.WARNING,
|
|
641
734
|
selector: "blockMath",
|
|
642
735
|
pattern: /\\begin{align}[\s\S]*\\\\[\s\S]+\\end{align}/,
|
|
643
736
|
lint: function(e, t, n, r) {
|
|
@@ -647,211 +740,232 @@ Shorten it to 500 characters or fewer.`;
|
|
|
647
740
|
if (e === -1) return;
|
|
648
741
|
i = i.substring(e + 2);
|
|
649
742
|
let t = i.match(/^\s*\\\\\s*(?!\\\\)/);
|
|
650
|
-
if (!t) return "Use four backslashes between lines of an align block";
|
|
743
|
+
if (!t) return linterWarning("Use four backslashes between lines of an align block");
|
|
651
744
|
i = i.substring(t[0].length);
|
|
652
745
|
}
|
|
653
746
|
}
|
|
654
|
-
}),
|
|
747
|
+
}), oe = h.makeRule({
|
|
655
748
|
name: "math-empty",
|
|
656
|
-
severity: h.Severity.WARNING,
|
|
657
749
|
selector: "math, blockMath",
|
|
658
750
|
pattern: /^$/,
|
|
659
|
-
|
|
660
|
-
|
|
751
|
+
lint: h.makeLintFunction({
|
|
752
|
+
severity: h.Severity.WARNING,
|
|
753
|
+
message: "Empty math: don't use $$ in your markdown."
|
|
754
|
+
})
|
|
755
|
+
}), se = h.makeRule({
|
|
661
756
|
name: "math-frac",
|
|
662
|
-
severity: h.Severity.GUIDELINE,
|
|
663
757
|
selector: "math, blockMath",
|
|
664
758
|
pattern: /\\frac[ {]/,
|
|
665
|
-
|
|
666
|
-
|
|
759
|
+
lint: h.makeLintFunction({
|
|
760
|
+
severity: h.Severity.GUIDELINE,
|
|
761
|
+
message: "Use \\dfrac instead of \\frac in your math expressions."
|
|
762
|
+
})
|
|
763
|
+
}), ce = h.makeRule({
|
|
667
764
|
name: "math-nested",
|
|
668
|
-
severity: h.Severity.ERROR,
|
|
669
765
|
selector: "math, blockMath",
|
|
670
766
|
pattern: /\\text{[^$}]*\$[^$}]*\$[^}]*}/,
|
|
671
|
-
|
|
672
|
-
|
|
767
|
+
lint: h.makeLintFunction({
|
|
768
|
+
severity: h.Severity.ERROR,
|
|
769
|
+
message: "Nested math:\nDon't nest math expressions inside \\text{} blocks"
|
|
770
|
+
})
|
|
771
|
+
}), le = h.makeRule({
|
|
673
772
|
name: "math-starts-with-space",
|
|
674
|
-
severity: h.Severity.GUIDELINE,
|
|
675
773
|
selector: "math, blockMath",
|
|
676
774
|
pattern: /^\s*(~|\\qquad|\\quad|\\,|\\;|\\:|\\ |\\!|\\enspace|\\phantom)/,
|
|
677
|
-
|
|
678
|
-
|
|
775
|
+
lint: h.makeLintFunction({
|
|
776
|
+
severity: h.Severity.GUIDELINE,
|
|
777
|
+
message: "Math starts with space:\nmath should not be indented. Do not begin math expressions with\nLaTeX space commands like ~, \\;, \\quad, or \\phantom"
|
|
778
|
+
})
|
|
779
|
+
}), ue = h.makeRule({
|
|
679
780
|
name: "math-text-empty",
|
|
680
|
-
severity: h.Severity.WARNING,
|
|
681
781
|
selector: "math, blockMath",
|
|
682
782
|
pattern: /\\text{\s*}/,
|
|
683
|
-
|
|
684
|
-
|
|
783
|
+
lint: h.makeLintFunction({
|
|
784
|
+
severity: h.Severity.WARNING,
|
|
785
|
+
message: "Empty \\text{} block in math expression"
|
|
786
|
+
})
|
|
787
|
+
}), de = h.makeRule({
|
|
685
788
|
name: "math-without-dollars",
|
|
686
|
-
severity: h.Severity.GUIDELINE,
|
|
687
789
|
pattern: /\\\w+{[^}]*}|{|}/,
|
|
688
|
-
|
|
689
|
-
|
|
790
|
+
lint: h.makeLintFunction({
|
|
791
|
+
severity: h.Severity.GUIDELINE,
|
|
792
|
+
message: "This looks like LaTeX:\ndid you mean to put it inside dollar signs?"
|
|
793
|
+
})
|
|
794
|
+
}), fe = h.makeRule({
|
|
690
795
|
name: "nested-lists",
|
|
691
|
-
severity: h.Severity.WARNING,
|
|
692
796
|
selector: "list list",
|
|
693
|
-
|
|
694
|
-
|
|
797
|
+
lint: h.makeLintFunction({
|
|
798
|
+
severity: h.Severity.WARNING,
|
|
799
|
+
message: "Nested lists:\nnested lists are hard to read on mobile devices;\ndo not use additional indentation."
|
|
800
|
+
})
|
|
801
|
+
}), pe = h.makeWidgetRule({
|
|
695
802
|
name: "numeric-input-missing-label",
|
|
696
803
|
widgetType: "numeric-input",
|
|
697
|
-
severity: h.Severity.WARNING,
|
|
698
804
|
lint(e) {
|
|
699
|
-
if (!e.options.labelText) return "Inputs should have an aria label:\nWhile screen readers will fallback to a default label of 'Your answer', a more descriptive label would improve accessibility.";
|
|
805
|
+
if (!e.options.labelText) return linterWarning("Inputs should have an aria label:\nWhile screen readers will fallback to a default label of 'Your answer', a more descriptive label would improve accessibility.");
|
|
700
806
|
}
|
|
701
|
-
}),
|
|
807
|
+
}), me = h.makeWidgetRule({
|
|
702
808
|
name: "numeric-input-widget-error",
|
|
703
809
|
widgetType: "numeric-input",
|
|
704
|
-
severity: h.Severity.ERROR,
|
|
705
810
|
lint(e) {
|
|
706
811
|
let t = [], n = e.options.answers;
|
|
707
812
|
return n.some((e) => e.value == null) && t.push("One or more answers is empty"), n.forEach((e, n) => {
|
|
708
813
|
e.strict && (!e.answerForms || e.answerForms.length === 0) && t.push(`Answer ${n + 1} requires a format, but no format was selected`);
|
|
709
814
|
}), t;
|
|
710
815
|
}
|
|
711
|
-
}),
|
|
816
|
+
}), he = h.makeWidgetRule({
|
|
712
817
|
name: "phet-simulation-widget-error",
|
|
713
818
|
widgetType: "phet-simulation",
|
|
714
|
-
severity: h.Severity.ERROR,
|
|
715
819
|
lint(e) {
|
|
716
|
-
if (a(e.options.url, "en", "https://phet.colorado.edu") === null) return "The URL is not from the PhET domain.";
|
|
820
|
+
if (a(e.options.url, "en", "https://phet.colorado.edu") === null) return linterError("The URL is not from the PhET domain.");
|
|
717
821
|
}
|
|
718
|
-
}),
|
|
822
|
+
}), ge = h.makeWidgetRule({
|
|
719
823
|
name: "python-program-widget-error",
|
|
720
824
|
widgetType: "python-program",
|
|
721
|
-
severity: h.Severity.ERROR,
|
|
722
825
|
lint(e) {
|
|
723
826
|
let t = [], n = e.options.height;
|
|
724
|
-
return e.options.programID === "" && t.push("The program ID is required."), (!Number.isInteger(n) || n < 1) && t.push("The height must be a positive integer."), t;
|
|
827
|
+
return e.options.programID === "" && t.push("The program ID is required."), (!Number.isInteger(n) || n < 1) && t.push("The height must be a positive integer."), t.map((e) => linterError(e));
|
|
725
828
|
}
|
|
726
|
-
}),
|
|
829
|
+
}), _e = h.makeWidgetRule({
|
|
727
830
|
name: "radio-widget-error",
|
|
728
831
|
widgetType: "radio",
|
|
729
|
-
severity: h.Severity.ERROR,
|
|
730
832
|
lint(e) {
|
|
731
833
|
let t = e.options.choices;
|
|
732
|
-
if (!t.some((e) => e.correct)) return "No choice is marked as correct.";
|
|
834
|
+
if (!t.some((e) => e.correct)) return linterError("No choice is marked as correct.");
|
|
733
835
|
let n = t.filter((e) => e.correct);
|
|
734
|
-
if (n.some((e) => e.isNoneOfTheAbove) && n.length > 1) return "Cannot mark both None of the Above and another choice as correct.";
|
|
836
|
+
if (n.some((e) => e.isNoneOfTheAbove) && n.length > 1) return linterError("Cannot mark both None of the Above and another choice as correct.");
|
|
735
837
|
}
|
|
736
|
-
}),
|
|
838
|
+
}), X = 2;
|
|
737
839
|
function hasMixedContent(e) {
|
|
738
840
|
let t = [];
|
|
739
|
-
return
|
|
841
|
+
return s(o(e.trim(), {}), (e) => {
|
|
740
842
|
e.type !== "paragraph" && t.push(e);
|
|
741
843
|
}), t.length > 1 && t.some((e) => e.type === "image");
|
|
742
844
|
}
|
|
743
|
-
var
|
|
845
|
+
var ve = h.makeWidgetRule({
|
|
744
846
|
name: "sorter-widget-error",
|
|
745
847
|
widgetType: "sorter",
|
|
746
|
-
severity: h.Severity.ERROR,
|
|
747
848
|
lint(e) {
|
|
748
849
|
let t = [], n = e.options.correct ?? [];
|
|
749
|
-
return n.length <
|
|
850
|
+
return n.length < X && t.push(`Sorter requires at least ${X} cards.`), n.some((e) => e.trim() === "") && t.push("Sorter cards cannot be blank."), n.some(hasMixedContent) && t.push("Sorter cards cannot mix images with other content."), t.map((e) => linterError(e));
|
|
750
851
|
}
|
|
751
|
-
}),
|
|
852
|
+
}), ye = h.makeWidgetRule({
|
|
752
853
|
name: "sorter-widget-warning",
|
|
753
854
|
widgetType: "sorter",
|
|
754
|
-
severity: h.Severity.WARNING,
|
|
755
855
|
lint(e) {
|
|
756
856
|
let t = [], { layout: n, correct: r = [] } = e.options;
|
|
757
|
-
return r.length > i && t.push(`Sorter cannot have more than ${i} cards.`), n === "horizontal" && r.length > 5 && t.push("Sorter cannot have more than 5 cards in horizontal layout."), r.length > 5 && t.push("Having more than 5 cards in Sorter is discouraged."), t;
|
|
857
|
+
return r.length > i && t.push(`Sorter cannot have more than ${i} cards.`), n === "horizontal" && r.length > 5 && t.push("Sorter cannot have more than 5 cards in horizontal layout."), r.length > 5 && t.push("Having more than 5 cards in Sorter is discouraged."), t.map((e) => linterWarning(e));
|
|
758
858
|
}
|
|
759
|
-
}),
|
|
859
|
+
}), be = h.makeRule({
|
|
760
860
|
name: "static-widget-in-question-stem",
|
|
761
|
-
severity: h.Severity.WARNING,
|
|
762
861
|
selector: "widget",
|
|
763
862
|
lint: (e, t, n, r, i) => {
|
|
764
863
|
if (i?.contentType !== "exercise" || i.stack.includes("hint")) return;
|
|
765
864
|
let a = e.currentNode().id;
|
|
766
865
|
if (!a) return;
|
|
767
866
|
let o = i?.widgets?.[a];
|
|
768
|
-
if (o && o.static) return "Widget in question stem is static (non-interactive).";
|
|
867
|
+
if (o && o.static) return linterWarning("Widget in question stem is static (non-interactive).");
|
|
769
868
|
}
|
|
770
|
-
}),
|
|
869
|
+
}), xe = "Table is missing a caption:\nScreen reader users rely on a caption to understand what a table contains\nbefore navigating its cells. Add one by putting a line of the form:\n|| Your caption here || directly above the table or using our Titled Table\ntemplate below.", Se = "Table caption is empty:\nThis table has a caption line, but there is no text between the || markers,\nso screen reader users hear an empty caption. Please add the appropriate\ntitle for your table.";
|
|
771
870
|
function getTextContent(e) {
|
|
772
871
|
return typeof e == "string" ? e : Array.isArray(e) ? e.map(getTextContent).join("") : e && typeof e == "object" ? getTextContent(e.content) : "";
|
|
773
872
|
}
|
|
774
873
|
function getTitleText(e) {
|
|
775
874
|
return getTextContent(e?.title).trim();
|
|
776
875
|
}
|
|
777
|
-
var
|
|
876
|
+
var Z = h.makeRule({
|
|
778
877
|
name: "table-missing-caption",
|
|
779
|
-
severity: h.Severity.GUIDELINE,
|
|
780
878
|
selector: "table",
|
|
781
879
|
lint: function(e) {
|
|
782
880
|
let t = e.parent();
|
|
783
|
-
if (t?.type !== "titledTable") return
|
|
784
|
-
if (getTitleText(t) === "") return
|
|
881
|
+
if (t?.type !== "titledTable") return linterGuideline(xe);
|
|
882
|
+
if (getTitleText(t) === "") return linterGuideline(Se);
|
|
785
883
|
}
|
|
786
|
-
}),
|
|
884
|
+
}), Ce = h.makeRule({
|
|
787
885
|
name: "table-missing-cells",
|
|
788
|
-
severity: h.Severity.WARNING,
|
|
789
886
|
selector: "table",
|
|
790
887
|
lint: function(e, t, n, r) {
|
|
791
888
|
let i = n[0], a = i.header.length, o = i.cells.map((e) => e.length);
|
|
792
|
-
for (let e = 0; e < o.length; e++) if (o[e] !== a) return `Table rows don't match header:
|
|
889
|
+
for (let e = 0; e < o.length; e++) if (o[e] !== a) return linterWarning(`Table rows don't match header:
|
|
793
890
|
The table header has ${a} cells, but
|
|
794
|
-
Row ${e + 1} has ${o[e]} cells
|
|
891
|
+
Row ${e + 1} has ${o[e]} cells.`);
|
|
795
892
|
}
|
|
796
|
-
}),
|
|
893
|
+
}), we = h.makeRule({
|
|
797
894
|
name: "unbalanced-code-delimiters",
|
|
798
|
-
severity: h.Severity.ERROR,
|
|
799
895
|
pattern: /[`~]+/,
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
w,
|
|
809
|
-
E,
|
|
810
|
-
D,
|
|
811
|
-
O,
|
|
812
|
-
z,
|
|
813
|
-
B,
|
|
814
|
-
ae,
|
|
815
|
-
H,
|
|
816
|
-
U,
|
|
817
|
-
W,
|
|
818
|
-
G,
|
|
819
|
-
K,
|
|
820
|
-
q,
|
|
821
|
-
J,
|
|
822
|
-
se,
|
|
823
|
-
he,
|
|
824
|
-
_e,
|
|
825
|
-
ve,
|
|
826
|
-
h.makeRule({
|
|
827
|
-
name: "unescaped-dollar",
|
|
896
|
+
lint: h.makeLintFunction({
|
|
897
|
+
severity: h.Severity.ERROR,
|
|
898
|
+
message: "Unbalanced code delimiters:\ncode blocks should begin and end with the same type and number of delimiters"
|
|
899
|
+
})
|
|
900
|
+
}), Te = h.makeRule({
|
|
901
|
+
name: "unescaped-dollar",
|
|
902
|
+
selector: "unescapedDollar",
|
|
903
|
+
lint: h.makeLintFunction({
|
|
828
904
|
severity: h.Severity.ERROR,
|
|
829
|
-
selector: "unescapedDollar",
|
|
830
905
|
message: "Unescaped dollar sign:\nDollar signs must appear in pairs or be escaped as \\$"
|
|
831
|
-
})
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
906
|
+
})
|
|
907
|
+
});
|
|
908
|
+
//#endregion
|
|
909
|
+
//#region packages/perseus-linter/src/rules/all-rules.ts
|
|
910
|
+
function allRules() {
|
|
911
|
+
return [
|
|
912
|
+
te,
|
|
913
|
+
re,
|
|
914
|
+
v,
|
|
915
|
+
ne,
|
|
916
|
+
S,
|
|
917
|
+
b,
|
|
918
|
+
x,
|
|
919
|
+
C,
|
|
920
|
+
T,
|
|
921
|
+
D,
|
|
922
|
+
E,
|
|
923
|
+
O,
|
|
924
|
+
k,
|
|
925
|
+
A,
|
|
926
|
+
j,
|
|
927
|
+
N,
|
|
928
|
+
P,
|
|
929
|
+
F,
|
|
930
|
+
I,
|
|
931
|
+
L,
|
|
932
|
+
R,
|
|
933
|
+
z,
|
|
934
|
+
B,
|
|
935
|
+
V,
|
|
936
|
+
H,
|
|
937
|
+
U,
|
|
938
|
+
G,
|
|
939
|
+
ie,
|
|
940
|
+
K,
|
|
941
|
+
q,
|
|
942
|
+
J,
|
|
943
|
+
Y,
|
|
944
|
+
ae,
|
|
945
|
+
oe,
|
|
946
|
+
se,
|
|
947
|
+
ce,
|
|
948
|
+
le,
|
|
949
|
+
ue,
|
|
950
|
+
de,
|
|
951
|
+
fe,
|
|
952
|
+
pe,
|
|
953
|
+
me,
|
|
954
|
+
he,
|
|
955
|
+
ge,
|
|
956
|
+
_e,
|
|
957
|
+
ve,
|
|
958
|
+
ye,
|
|
959
|
+
be,
|
|
960
|
+
Z,
|
|
961
|
+
Ce,
|
|
962
|
+
we,
|
|
963
|
+
Te
|
|
964
|
+
];
|
|
965
|
+
}
|
|
966
|
+
//#endregion
|
|
967
|
+
//#region packages/perseus-linter/src/tree-transformer.ts
|
|
968
|
+
var Q = class TreeTransformer {
|
|
855
969
|
constructor(e) {
|
|
856
970
|
this.root = e;
|
|
857
971
|
}
|
|
@@ -862,7 +976,7 @@ Row ${e + 1} has ${o[e]} cells.`;
|
|
|
862
976
|
return TreeTransformer.isNode(e) && e.type === "text" && typeof e.content == "string";
|
|
863
977
|
}
|
|
864
978
|
traverse(e) {
|
|
865
|
-
this._traverse(this.root, new
|
|
979
|
+
this._traverse(this.root, new Ee(this.root), e);
|
|
866
980
|
}
|
|
867
981
|
_traverse(e, t, n) {
|
|
868
982
|
let r = "";
|
|
@@ -882,7 +996,7 @@ Row ${e + 1} has ${o[e]} cells.`;
|
|
|
882
996
|
}
|
|
883
997
|
return r;
|
|
884
998
|
}
|
|
885
|
-
},
|
|
999
|
+
}, Ee = class TraversalState {
|
|
886
1000
|
constructor(e) {
|
|
887
1001
|
this.root = e, this._currentNode = null, this._containers = new $(), this._indexes = new $(), this._ancestors = new $();
|
|
888
1002
|
}
|
|
@@ -982,76 +1096,57 @@ Row ${e + 1} has ${o[e]} cells.`;
|
|
|
982
1096
|
};
|
|
983
1097
|
//#endregion
|
|
984
1098
|
//#region packages/perseus-linter/src/run-linter.ts
|
|
985
|
-
function runLinter(e, t, n
|
|
986
|
-
let
|
|
987
|
-
|
|
1099
|
+
function runLinter(e, t, n) {
|
|
1100
|
+
let r = [], i = new Q(e);
|
|
1101
|
+
i.traverse((e, t, n) => {
|
|
988
1102
|
if (Q.isTextNode(e)) {
|
|
989
1103
|
let n = t.nextSibling();
|
|
990
1104
|
for (; Q.isTextNode(n);) e.content += n.content, t.removeNextSibling(), n = t.nextSibling();
|
|
991
1105
|
}
|
|
992
1106
|
});
|
|
993
|
-
let
|
|
994
|
-
return
|
|
995
|
-
let
|
|
996
|
-
|
|
997
|
-
let
|
|
1107
|
+
let a = [], o = !1;
|
|
1108
|
+
return i.traverse((e, i, s) => {
|
|
1109
|
+
let c = [], l = [...t.stack];
|
|
1110
|
+
l.push(e.type);
|
|
1111
|
+
let u = {
|
|
998
1112
|
...t,
|
|
999
|
-
stack:
|
|
1113
|
+
stack: l.join(".")
|
|
1000
1114
|
};
|
|
1001
|
-
if (
|
|
1002
|
-
let
|
|
1003
|
-
for (let e of
|
|
1004
|
-
}), n && (e.type === "table" ? (
|
|
1005
|
-
if (
|
|
1115
|
+
if (allRules().forEach((t) => {
|
|
1116
|
+
let a = t.check(e, i, s, u);
|
|
1117
|
+
for (let e of a) (e.start || e.end) && (e.target = s.substring(e.start, e.end)), r.push(e), n && c.push(e);
|
|
1118
|
+
}), n && (e.type === "table" ? (a.length && c.push(...a), o = !1, a = []) : o || (o = i.ancestors().some((e) => e.type === "table")), o && c.length > 0 && a.push(...c), c.length > 0)) {
|
|
1119
|
+
if (c.sort((e, t) => e.severity - t.severity), e.type !== "text" || c.length > 1) i.replace({
|
|
1006
1120
|
type: "lint",
|
|
1007
1121
|
content: e,
|
|
1008
|
-
message:
|
|
1009
|
-
ruleName:
|
|
1010
|
-
blockHighlight:
|
|
1011
|
-
insideTable:
|
|
1012
|
-
severity:
|
|
1122
|
+
message: c.map((e) => e.message).join("\n\n"),
|
|
1123
|
+
ruleName: c[0].rule,
|
|
1124
|
+
blockHighlight: u.blockHighlight,
|
|
1125
|
+
insideTable: o,
|
|
1126
|
+
severity: c[0].severity
|
|
1013
1127
|
});
|
|
1014
1128
|
else {
|
|
1015
|
-
let t = e.content, n =
|
|
1016
|
-
|
|
1129
|
+
let t = e.content, n = c[0], r = n.start, a = n.end, s = t.substring(0, r), l = t.substring(r, a), u = t.substring(a), d = [];
|
|
1130
|
+
s && d.push({
|
|
1017
1131
|
type: "text",
|
|
1018
|
-
content:
|
|
1132
|
+
content: s
|
|
1019
1133
|
}), d.push({
|
|
1020
1134
|
type: "lint",
|
|
1021
1135
|
content: {
|
|
1022
1136
|
type: "text",
|
|
1023
|
-
content:
|
|
1137
|
+
content: l
|
|
1024
1138
|
},
|
|
1025
1139
|
message: n.message,
|
|
1026
1140
|
ruleName: n.rule,
|
|
1027
|
-
insideTable:
|
|
1141
|
+
insideTable: o,
|
|
1028
1142
|
severity: n.severity
|
|
1029
1143
|
}), u && d.push({
|
|
1030
1144
|
type: "text",
|
|
1031
1145
|
content: u
|
|
1032
|
-
}),
|
|
1146
|
+
}), i.replace(...d);
|
|
1033
1147
|
}
|
|
1034
1148
|
}
|
|
1035
|
-
}),
|
|
1036
|
-
}
|
|
1037
|
-
//#endregion
|
|
1038
|
-
//#region packages/perseus-linter/src/lint-content.ts
|
|
1039
|
-
function lintPerseusItem(e) {
|
|
1040
|
-
return {
|
|
1041
|
-
question: lintPerseusRenderer(e.question, "exercise"),
|
|
1042
|
-
hints: e.hints.map((e) => lintPerseusRenderer(e, "exercise"))
|
|
1043
|
-
};
|
|
1044
|
-
}
|
|
1045
|
-
function lintPerseusArticle(e) {
|
|
1046
|
-
return (Array.isArray(e) ? e : [e]).map((e) => lintPerseusRenderer(e, "article"));
|
|
1047
|
-
}
|
|
1048
|
-
function lintPerseusRenderer(e, t) {
|
|
1049
|
-
return [...runLinter(s(e.content), {
|
|
1050
|
-
content: e.content,
|
|
1051
|
-
widgets: e.widgets,
|
|
1052
|
-
stack: [],
|
|
1053
|
-
contentType: t
|
|
1054
|
-
}, !1)];
|
|
1149
|
+
}), r;
|
|
1055
1150
|
}
|
|
1056
1151
|
//#endregion
|
|
1057
1152
|
//#region packages/perseus-linter/src/index.ts
|
|
@@ -1063,6 +1158,6 @@ function pushContextStack(e, t) {
|
|
|
1063
1158
|
};
|
|
1064
1159
|
}
|
|
1065
1160
|
//#endregion
|
|
1066
|
-
export { h as Rule, d as libVersion, lintPerseusArticle, lintPerseusItem, lintPerseusRenderer,
|
|
1161
|
+
export { h as Rule, d as libVersion, lintPerseusArticle, lintPerseusItem, lintPerseusRenderer, ee as linterContextDefault, pushContextStack, runLinter };
|
|
1067
1162
|
|
|
1068
1163
|
//# sourceMappingURL=index.js.map
|