@khanacademy/perseus-linter 8.2.0 → 8.3.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.js CHANGED
@@ -1,18 +1,24 @@
1
1
  import { addLibraryVersionToPerseusDebug as e } from "@khanacademy/perseus-utils";
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 { parse as o, traverseContent as s } from "@khanacademy/pure-markdown";
4
- import * as c from "@khanacademy/kas";
5
- import { vector as l } from "@khanacademy/kmath";
2
+ import { CoreWidgetRegistry as t, Errors as n, PerseusError as r, SORTER_MAX_CARDS as i, isEmptyTableCell as a, makeSafeUrl as o } from "@khanacademy/perseus-core";
3
+ import { parse as s, traverseContent as c } from "@khanacademy/pure-markdown";
4
+ import * as l from "@khanacademy/kas";
5
+ import { vector as u } from "@khanacademy/kmath";
6
6
  //#region \0rolldown/runtime.js
7
- var u = "@khanacademy/perseus-linter", d = "8.2.0";
8
- e(u, d);
7
+ var d = "@khanacademy/perseus-linter", f = "8.3.0";
8
+ e(d, f);
9
9
  //#endregion
10
10
  //#region packages/perseus-linter/src/proptypes.ts
11
11
  var ee = {
12
12
  contentType: "",
13
13
  highlightLint: !1,
14
14
  stack: []
15
- }, f = {
15
+ }, p = {
16
+ text: "Learn more about best practices for authoring items",
17
+ url: "https://docs.google.com/document/d/1N13f4sY-7EXWDwQ04ivA9vJBVvPPd60qjBT73B4NHuM/edit?tab=t.0"
18
+ }, m = {
19
+ text: "Learn more about perseus table markup",
20
+ url: "https://khanacademy.atlassian.net/wiki/x/vQC-LQE"
21
+ }, h = {
16
22
  ERROR: 1,
17
23
  WARNING: 2,
18
24
  GUIDELINE: 3
@@ -20,21 +26,21 @@ var ee = {
20
26
  function linterWarning(e, t) {
21
27
  return {
22
28
  message: e,
23
- severity: f.WARNING,
29
+ severity: h.WARNING,
24
30
  ...t
25
31
  };
26
32
  }
27
33
  function linterError(e, t) {
28
34
  return {
29
35
  message: e,
30
- severity: f.ERROR,
36
+ severity: h.ERROR,
31
37
  ...t
32
38
  };
33
39
  }
34
40
  function linterGuideline(e, t) {
35
41
  return {
36
42
  message: e,
37
- severity: f.GUIDELINE,
43
+ severity: h.GUIDELINE,
38
44
  ...t
39
45
  };
40
46
  }
@@ -42,7 +48,7 @@ function linterGuideline(e, t) {
42
48
  //#region packages/perseus-linter/src/selector.ts
43
49
  var Selector = class {
44
50
  static parse(e) {
45
- return new p(e).parse();
51
+ return new g(e).parse();
46
52
  }
47
53
  match(e) {
48
54
  throw new r("Selector subclasses must implement match()", n.NotAllowed);
@@ -50,7 +56,7 @@ var Selector = class {
50
56
  toString() {
51
57
  return "Unknown selector class";
52
58
  }
53
- }, p = class Parser {
59
+ }, g = class Parser {
54
60
  constructor(e) {
55
61
  e = e.trim().replace(/\s+/g, " "), this.tokens = e.match(Parser.TOKENS) || [], this.tokenIndex = 0;
56
62
  }
@@ -100,7 +106,7 @@ var Selector = class {
100
106
  throw new ParseError("Expected node type");
101
107
  }
102
108
  };
103
- p.TOKENS = /([a-zA-Z][\w-]*)|(\d+)|[^\s]|(\s(?=[a-zA-Z*]))/g;
109
+ g.TOKENS = /([a-zA-Z][\w-]*)|(\d+)|[^\s]|(\s(?=[a-zA-Z*]))/g;
104
110
  var ParseError = class extends Error {
105
111
  constructor(e) {
106
112
  super(e);
@@ -207,13 +213,13 @@ var ParseError = class extends Error {
207
213
  toString() {
208
214
  return this.left.toString() + " ~ " + this.right.toString();
209
215
  }
210
- }, m, h = class Rule {
211
- constructor(e, t, i, a) {
216
+ }, _, v = class Rule {
217
+ constructor(e, t, i, a, o) {
212
218
  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;
219
+ this.name = e || "unnamed rule", this.selector = t || Rule.DEFAULT_SELECTOR, this.pattern = i || null, this.lint = a, this.helpLink = o ?? p;
214
220
  }
215
221
  static makeRule(e) {
216
- return new Rule(e.name, e.selector ? Selector.parse(e.selector) : null, Rule.makePattern(e.pattern), e.lint);
222
+ return new Rule(e.name, e.selector ? Selector.parse(e.selector) : null, Rule.makePattern(e.pattern), e.lint, e.helpLink);
217
223
  }
218
224
  static makeWidgetRule(e) {
219
225
  return new Rule(e.name, Selector.parse("widget"), null, (t, n, r, i, a) => {
@@ -225,7 +231,7 @@ var ParseError = class extends Error {
225
231
  ...e,
226
232
  message: `${o}: ${e.message}`
227
233
  }));
228
- });
234
+ }, e.helpLink);
229
235
  }
230
236
  check(e, t, n, r) {
231
237
  let toLinterIssue = (e) => {
@@ -238,6 +244,7 @@ var ParseError = class extends Error {
238
244
  severity: e.severity,
239
245
  message: e.message,
240
246
  metadata: e.metadata,
247
+ helpLink: this.helpLink,
241
248
  ...t
242
249
  };
243
250
  }, toLinterIssues = (e) => e == null ? [] : Array.isArray(e) ? e.map(toLinterIssue) : [toLinterIssue(e)], i = this.selector.match(t);
@@ -254,7 +261,8 @@ var ParseError = class extends Error {
254
261
  Stack trace:
255
262
  ${e.stack}`,
256
263
  start: 0,
257
- end: n.length
264
+ end: n.length,
265
+ helpLink: p
258
266
  }];
259
267
  }
260
268
  }
@@ -282,18 +290,18 @@ ${e.stack}`,
282
290
  return r.index = n, r.input = e, r;
283
291
  }
284
292
  };
285
- m = h, m.Severity = f, h.DEFAULT_SELECTOR = Selector.parse("text");
293
+ _ = v, _.Severity = h, v.DEFAULT_SELECTOR = Selector.parse("text");
286
294
  //#endregion
287
295
  //#region packages/perseus-linter/src/rules/lint-utils.ts
288
- var g = /\/\/([^/]+)/;
296
+ var y = /\/\/([^/]+)/;
289
297
  function getHostname(e) {
290
298
  if (!e) return "";
291
- let t = e.match(g);
299
+ let t = e.match(y);
292
300
  return t ? t[1] : "";
293
301
  }
294
302
  //#endregion
295
303
  //#region packages/perseus-linter/src/rules/absolute-url.ts
296
- var te = h.makeRule({
304
+ var te = v.makeRule({
297
305
  name: "absolute-url",
298
306
  selector: "link, image",
299
307
  lint: function(e, t, n, r) {
@@ -313,7 +321,7 @@ function lintPerseusArticle(e) {
313
321
  return (Array.isArray(e) ? e : [e]).map((e) => lintPerseusRenderer(e, "article"));
314
322
  }
315
323
  function lintPerseusRenderer(e, t) {
316
- return [...runLinter(o(e.content), {
324
+ return [...runLinter(s(e.content), {
317
325
  content: e.content,
318
326
  widgets: e.widgets,
319
327
  stack: [],
@@ -322,7 +330,7 @@ function lintPerseusRenderer(e, t) {
322
330
  }
323
331
  //#endregion
324
332
  //#region packages/perseus-linter/src/rules/explanation.ts
325
- var ne = h.makeWidgetRule({
333
+ var ne = v.makeWidgetRule({
326
334
  name: "explanation",
327
335
  widgetType: "explanation",
328
336
  lint(e, t) {
@@ -338,18 +346,18 @@ var ne = h.makeWidgetRule({
338
346
  function hasExplanation(e) {
339
347
  return Object.values(e).some((e) => e.type === "explanation");
340
348
  }
341
- var _ = "Don't use explanation widgets in graded groups. Use the Graded Group Hint instead.", re = h.makeWidgetRule({
349
+ var b = "Don't use explanation widgets in graded groups. Use the Graded Group Hint instead.", re = v.makeWidgetRule({
342
350
  name: "explanation-in-graded-group",
343
351
  widgetType: "graded-group",
344
352
  lint: function(e) {
345
- if (hasExplanation(e.options.widgets)) return linterWarning(`Contains explanation widget. ${_}`);
353
+ if (hasExplanation(e.options.widgets)) return linterWarning(`Contains explanation widget. ${b}`);
346
354
  }
347
- }), ie = h.makeWidgetRule({
355
+ }), ie = v.makeWidgetRule({
348
356
  name: "explanation-in-graded-group-set",
349
357
  widgetType: "graded-group-set",
350
358
  lint: function(e) {
351
359
  let t = e.options.gradedGroups.map((e, t) => hasExplanation(e.widgets) ? t + 1 : 0).filter((e) => e > 0);
352
- if (t.length > 0) return linterWarning(`Explanation widget in group ${t.join(" and ")}. ${_}`);
360
+ if (t.length > 0) return linterWarning(`Explanation widget in group ${t.join(" and ")}. ${b}`);
353
361
  }
354
362
  });
355
363
  //#endregion
@@ -357,7 +365,7 @@ var _ = "Don't use explanation widgets in graded groups. Use the Graded Group Hi
357
365
  function buttonNotInButtonSet(e, t) {
358
366
  return `Answer requires a button not found in the button sets: ${e} (in ${t})`;
359
367
  }
360
- var v = {
368
+ var x = {
361
369
  "\\sqrt": "prealgebra",
362
370
  "^": "prealgebra",
363
371
  "\\sin": "trig",
@@ -365,14 +373,14 @@ var v = {
365
373
  "\\tan": "trig",
366
374
  "\\log": "logarithms",
367
375
  "\\ln": "logarithms"
368
- }, y = h.makeWidgetRule({
376
+ }, S = v.makeWidgetRule({
369
377
  name: "expression-widget-buttons",
370
378
  widgetType: "expression",
371
379
  lint(e) {
372
380
  let t = e.options.answerForms, n = e.options.buttonSets;
373
- for (let e of t) for (let [t, r] of Object.entries(v)) if (e.value.includes(t) && !n.includes(r)) return linterWarning(buttonNotInButtonSet(t, r));
381
+ for (let e of t) for (let [t, r] of Object.entries(x)) if (e.value.includes(t) && !n.includes(r)) return linterWarning(buttonNotInButtonSet(t, r));
374
382
  }
375
- }), b = h.makeWidgetRule({
383
+ }), C = v.makeWidgetRule({
376
384
  name: "expression-widget-correct-answer",
377
385
  widgetType: "expression",
378
386
  lint(e) {
@@ -380,7 +388,7 @@ var v = {
380
388
  if (t.length === 0) return linterError("No answers specified.");
381
389
  if (!t.some((e) => e.considered === "correct")) return linterError("No correct answer specified.");
382
390
  }
383
- }), x = h.makeWidgetRule({
391
+ }), w = v.makeWidgetRule({
384
392
  name: "expression-widget-answer-forms",
385
393
  widgetType: "expression",
386
394
  lint(e) {
@@ -390,11 +398,11 @@ var v = {
390
398
  r.push(`Answer ${t + 1} is empty.`);
391
399
  return;
392
400
  }
393
- let i = c.parse(e.value, { functions: n });
401
+ let i = l.parse(e.value, { functions: n });
394
402
  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}.`);
395
403
  }), r.map((e) => linterError(e));
396
404
  }
397
- }), S = h.makeWidgetRule({
405
+ }), T = v.makeWidgetRule({
398
406
  name: "fill-in-the-blank",
399
407
  widgetType: "fill-in-the-blank",
400
408
  lint(e, t) {
@@ -404,13 +412,13 @@ var v = {
404
412
  images: {}
405
413
  }, t);
406
414
  }
407
- }), C = /\[\[\u2603 (([a-z-]+) ([0-9]+))\]\]/, w = h.makeWidgetRule({
415
+ }), E = /\[\[\u2603 (([a-z-]+) ([0-9]+))\]\]/, D = v.makeWidgetRule({
408
416
  name: "free-response-widget-error",
409
417
  widgetType: "free-response",
410
418
  lint(e) {
411
419
  let t = e.options.question;
412
420
  if (!t) return linterError("The question is empty");
413
- if (t.match(C) != null) return linterError("The question contains a widget");
421
+ if (t.match(E) != null) return linterError("The question contains a widget");
414
422
  }
415
423
  });
416
424
  //#endregion
@@ -428,11 +436,11 @@ function lintGradedGroup(e, { contentType: t }) {
428
436
  }
429
437
  //#endregion
430
438
  //#region packages/perseus-linter/src/rules/graded-group.ts
431
- var T = h.makeWidgetRule({
439
+ var O = v.makeWidgetRule({
432
440
  name: "graded-group",
433
441
  widgetType: "graded-group",
434
442
  lint: (e, t) => lintGradedGroup(e.options, t)
435
- }), E = h.makeWidgetRule({
443
+ }), k = v.makeWidgetRule({
436
444
  name: "graded-group-set",
437
445
  widgetType: "graded-group-set",
438
446
  lint: (e, t) => e.options.gradedGroups.flatMap((e, n) => lintGradedGroup(e, t).map(prefixGroupNumber(n + 1)))
@@ -445,19 +453,19 @@ function prefixGroupNumber(e) {
445
453
  }
446
454
  //#endregion
447
455
  //#region packages/perseus-linter/src/rules/group.ts
448
- var D = h.makeWidgetRule({
456
+ var A = v.makeWidgetRule({
449
457
  name: "group",
450
458
  widgetType: "group",
451
459
  lint(e, t) {
452
460
  return lintPerseusRenderer(e.options, t);
453
461
  }
454
- }), O = h.makeRule({
462
+ }), j = v.makeRule({
455
463
  name: "heading-level-1",
456
464
  selector: "heading",
457
465
  lint: function(e, t, n, r) {
458
466
  if (n[0].level === 1) return linterWarning("Don't use level-1 headings:\nBegin headings with two or more # characters.");
459
467
  }
460
- }), k = h.makeRule({
468
+ }), M = v.makeRule({
461
469
  name: "heading-level-skip",
462
470
  selector: "heading ~ heading",
463
471
  lint: function(e, t, n, r) {
@@ -466,15 +474,15 @@ var D = h.makeWidgetRule({
466
474
  this heading is level ${i.level} but
467
475
  the previous heading was level ${a.level}`);
468
476
  }
469
- }), A = h.makeRule({
477
+ }), N = v.makeRule({
470
478
  name: "heading-sentence-case",
471
479
  selector: "heading",
472
480
  pattern: /^\W*[a-z]/,
473
- lint: h.makeLintFunction({
474
- severity: h.Severity.GUIDELINE,
481
+ lint: v.makeLintFunction({
482
+ severity: v.Severity.GUIDELINE,
475
483
  message: "First letter is lowercase:\nthe first letter of a heading should be capitalized."
476
484
  })
477
- }), j = {
485
+ }), P = {
478
486
  and: !0,
479
487
  nor: !0,
480
488
  but: !0,
@@ -485,16 +493,16 @@ function isCapitalized(e) {
485
493
  let t = e[0];
486
494
  return t === t.toUpperCase();
487
495
  }
488
- var M = h.makeRule({
496
+ var F = v.makeRule({
489
497
  name: "heading-title-case",
490
498
  selector: "heading",
491
499
  pattern: /[^\s:]\s+[A-Z]+[a-z]/,
492
500
  locale: "en",
493
501
  lint: function(e, t, n, r) {
494
502
  let i = t.trim().split(/\s+/);
495
- if (i.shift(), i = i.filter((e) => e.length > 2 && !j.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.");
503
+ if (i.shift(), i = i.filter((e) => e.length > 2 && !P.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.");
496
504
  }
497
- }), N = h.makeRule({
505
+ }), I = v.makeRule({
498
506
  name: "image-alt-text",
499
507
  selector: "image",
500
508
  lint: function(e, t, n, r) {
@@ -504,17 +512,17 @@ var M = h.makeRule({
504
512
  for accessibility, all images should have descriptive alt text.
505
513
  This image's alt text is only ${i.alt.length} characters long.`);
506
514
  }
507
- }), P = h.makeRule({
515
+ }), L = v.makeRule({
508
516
  name: "image-markdown",
509
517
  selector: "image",
510
518
  lint: function(e, t, n, r, i) {
511
519
  if (i?.stack && i.stack.includes("widget")) return;
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![alt](url) format. Please use the Image widget instead.");
520
+ let a = s(i?.content || "", {}), o = !1;
521
+ if (c(a, (e) => {
522
+ e.type === "image" && (o = !0);
523
+ }), o) return linterWarning("[Inline markdown image]:\nMarkdown images are not recommended - these are images that use the\n![alt](url) format. Please use the Image widget instead.");
516
524
  }
517
- }), F = h.makeRule({
525
+ }), R = v.makeRule({
518
526
  name: "image-spaces-around-urls",
519
527
  selector: "image",
520
528
  lint: function(e, t, n, r, i) {
@@ -525,14 +533,14 @@ This image's alt text is only ${i.alt.length} characters long.`);
525
533
  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.");
526
534
  }
527
535
  }
528
- }), I = h.makeRule({
536
+ }), z = v.makeRule({
529
537
  name: "image-url-empty",
530
538
  selector: "image",
531
539
  lint: function(e, t, n) {
532
540
  let r = n[0].target;
533
541
  if (!r || !r.trim()) return linterError("Images should have a URL");
534
542
  }
535
- }), L = h.makeWidgetRule({
543
+ }), B = v.makeWidgetRule({
536
544
  name: "image-widget-alt-text",
537
545
  widgetType: "image",
538
546
  lint(e) {
@@ -548,7 +556,7 @@ This image's alt text is ${t.trim().length} characters long.
548
556
  Please pair your alt with a long description below if you need significantly
549
557
  more text to sufficiently describe the image.`);
550
558
  }
551
- }), R = h.makeWidgetRule({
559
+ }), V = v.makeWidgetRule({
552
560
  name: "image-widget-empty-size",
553
561
  widgetType: "image",
554
562
  lint(e) {
@@ -558,7 +566,7 @@ more text to sufficiently describe the image.`);
558
566
  This image has a width of ${t} and a height of ${n}.
559
567
  Please use the "Reset to original size" button to set the size of the image.`);
560
568
  }
561
- }), z = h.makeRule({
569
+ }), H = v.makeRule({
562
570
  name: "inaccessible-widget",
563
571
  selector: "widget",
564
572
  lint: function(e, n, r, i, a) {
@@ -576,7 +584,7 @@ Please use the "Reset to original size" button to set the size of the image.`);
576
584
  }
577
585
  });
578
586
  }
579
- }), B = h.makeWidgetRule({
587
+ }), U = v.makeWidgetRule({
580
588
  name: "interactive-graph-locked-figure-oob",
581
589
  widgetType: "interactive-graph",
582
590
  lint(e) {
@@ -623,12 +631,12 @@ function definingPoints(e) {
623
631
  }
624
632
  //#endregion
625
633
  //#region packages/perseus-linter/src/rules/interactive-graph-widget-error.ts
626
- var V = h.makeWidgetRule({
634
+ var W = v.makeWidgetRule({
627
635
  name: "interactive-graph-widget-error",
628
636
  widgetType: "interactive-graph",
629
637
  lint(e) {
630
638
  let t = [], { correct: n, graph: r, lockedFigures: i } = e.options;
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.");
639
+ for (let e of i ?? []) e.type === "line" && u.equal(e.points[0].coord, e.points[1].coord) && t.push("Locked line cannot have length 0."), e.type === "polygon" && e.points.every((t) => u.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.");
632
640
  if (n?.type === "polygon" && n.numSides === "unlimited" && n.coords == null && t.push("Polygon must be closed."), r?.type === "exponential" && r.startCoords != null) {
633
641
  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]);
634
642
  i >= a && i <= o && t.push("The exponential start asymptote must not fall between or on the curve's start points.");
@@ -667,7 +675,7 @@ function expectedLabelCount(e) {
667
675
  }
668
676
  //#endregion
669
677
  //#region packages/perseus-linter/src/rules/label-image-widget-error.ts
670
- var H = h.makeWidgetRule({
678
+ var G = v.makeWidgetRule({
671
679
  name: "label-image-widget-error",
672
680
  widgetType: "label-image",
673
681
  lint(e) {
@@ -680,26 +688,26 @@ var H = h.makeWidgetRule({
680
688
  }
681
689
  return t.map((e) => linterError(e));
682
690
  }
683
- }), U = "ka-perseus-images.s3.amazonaws.com", W = h.makeWidgetRule({
691
+ }), K = "ka-perseus-images.s3.amazonaws.com", q = v.makeWidgetRule({
684
692
  name: "legacy-gif-url",
685
693
  widgetType: "image",
686
694
  lint(e) {
687
695
  let t = e.options?.backgroundImage?.url;
688
- if (t && getHostname(t) === U && t.toLowerCase().endsWith(".gif")) return linterGuideline(`Legacy gif URL:
689
- gifs hosted at ${U} might not appear in the editor preview,
696
+ if (t && getHostname(t) === K && t.toLowerCase().endsWith(".gif")) return linterGuideline(`Legacy gif URL:
697
+ gifs hosted at ${K} might not appear in the editor preview,
690
698
  but can still be viewed in the published content. Please use a
691
699
  cdn.kastatic.org/ka-perseus-images/ URL instead or confirm the
692
700
  image displays correctly in the published content.`);
693
701
  }
694
- }), G = h.makeRule({
702
+ }), J = v.makeRule({
695
703
  name: "link-click-here",
696
704
  selector: "link",
697
705
  pattern: /click here/i,
698
- lint: h.makeLintFunction({
699
- severity: h.Severity.WARNING,
706
+ lint: v.makeLintFunction({
707
+ severity: v.Severity.WARNING,
700
708
  message: "Inappropriate link text:\nDo not use the words \"click here\" in links."
701
709
  })
702
- }), K = h.makeRule({
710
+ }), Y = v.makeRule({
703
711
  name: "long-paragraph",
704
712
  selector: "paragraph",
705
713
  pattern: /^.{501,}/,
@@ -708,28 +716,28 @@ image displays correctly in the published content.`);
708
716
  This paragraph is ${t.length} characters long.
709
717
  Shorten it to 500 characters or fewer.`);
710
718
  }
711
- }), q = h.makeWidgetRule({
719
+ }), ae = v.makeWidgetRule({
712
720
  name: "matcher-widget-error",
713
721
  widgetType: "matcher",
714
722
  lint(e) {
715
723
  if (e.options.left.length !== e.options.right.length) return linterError("The two halves of the matcher have different numbers of cards.");
716
724
  }
717
- }), J = h.makeRule({
725
+ }), oe = v.makeRule({
718
726
  name: "math-adjacent",
719
727
  selector: "blockMath+blockMath",
720
- lint: h.makeLintFunction({
721
- severity: h.Severity.WARNING,
728
+ lint: v.makeLintFunction({
729
+ severity: v.Severity.WARNING,
722
730
  message: "Adjacent math blocks:\ncombine the blocks between \\begin{align} and \\end{align}"
723
731
  })
724
- }), Y = h.makeRule({
732
+ }), se = v.makeRule({
725
733
  name: "math-align-extra-break",
726
734
  selector: "blockMath",
727
735
  pattern: /(\\{2,})\s*\\end{align}/,
728
- lint: h.makeLintFunction({
729
- severity: h.Severity.WARNING,
736
+ lint: v.makeLintFunction({
737
+ severity: v.Severity.WARNING,
730
738
  message: "Extra space at end of block:\nDon't end an align block with backslashes"
731
739
  })
732
- }), ae = h.makeRule({
740
+ }), ce = v.makeRule({
733
741
  name: "math-align-linebreaks",
734
742
  selector: "blockMath",
735
743
  pattern: /\\begin{align}[\s\S]*\\\\[\s\S]+\\end{align}/,
@@ -744,67 +752,67 @@ Shorten it to 500 characters or fewer.`);
744
752
  i = i.substring(t[0].length);
745
753
  }
746
754
  }
747
- }), oe = h.makeRule({
755
+ }), le = v.makeRule({
748
756
  name: "math-empty",
749
757
  selector: "math, blockMath",
750
758
  pattern: /^$/,
751
- lint: h.makeLintFunction({
752
- severity: h.Severity.WARNING,
759
+ lint: v.makeLintFunction({
760
+ severity: v.Severity.WARNING,
753
761
  message: "Empty math: don't use $$ in your markdown."
754
762
  })
755
- }), se = h.makeRule({
763
+ }), ue = v.makeRule({
756
764
  name: "math-frac",
757
765
  selector: "math, blockMath",
758
766
  pattern: /\\frac[ {]/,
759
- lint: h.makeLintFunction({
760
- severity: h.Severity.GUIDELINE,
767
+ lint: v.makeLintFunction({
768
+ severity: v.Severity.GUIDELINE,
761
769
  message: "Use \\dfrac instead of \\frac in your math expressions."
762
770
  })
763
- }), ce = h.makeRule({
771
+ }), de = v.makeRule({
764
772
  name: "math-nested",
765
773
  selector: "math, blockMath",
766
774
  pattern: /\\text{[^$}]*\$[^$}]*\$[^}]*}/,
767
- lint: h.makeLintFunction({
768
- severity: h.Severity.ERROR,
775
+ lint: v.makeLintFunction({
776
+ severity: v.Severity.ERROR,
769
777
  message: "Nested math:\nDon't nest math expressions inside \\text{} blocks"
770
778
  })
771
- }), le = h.makeRule({
779
+ }), fe = v.makeRule({
772
780
  name: "math-starts-with-space",
773
781
  selector: "math, blockMath",
774
782
  pattern: /^\s*(~|\\qquad|\\quad|\\,|\\;|\\:|\\ |\\!|\\enspace|\\phantom)/,
775
- lint: h.makeLintFunction({
776
- severity: h.Severity.GUIDELINE,
783
+ lint: v.makeLintFunction({
784
+ severity: v.Severity.GUIDELINE,
777
785
  message: "Math starts with space:\nmath should not be indented. Do not begin math expressions with\nLaTeX space commands like ~, \\;, \\quad, or \\phantom"
778
786
  })
779
- }), ue = h.makeRule({
787
+ }), pe = v.makeRule({
780
788
  name: "math-text-empty",
781
789
  selector: "math, blockMath",
782
790
  pattern: /\\text{\s*}/,
783
- lint: h.makeLintFunction({
784
- severity: h.Severity.WARNING,
791
+ lint: v.makeLintFunction({
792
+ severity: v.Severity.WARNING,
785
793
  message: "Empty \\text{} block in math expression"
786
794
  })
787
- }), de = h.makeRule({
795
+ }), me = v.makeRule({
788
796
  name: "math-without-dollars",
789
797
  pattern: /\\\w+{[^}]*}|{|}/,
790
- lint: h.makeLintFunction({
791
- severity: h.Severity.GUIDELINE,
798
+ lint: v.makeLintFunction({
799
+ severity: v.Severity.GUIDELINE,
792
800
  message: "This looks like LaTeX:\ndid you mean to put it inside dollar signs?"
793
801
  })
794
- }), fe = h.makeRule({
802
+ }), he = v.makeRule({
795
803
  name: "nested-lists",
796
804
  selector: "list list",
797
- lint: h.makeLintFunction({
798
- severity: h.Severity.WARNING,
805
+ lint: v.makeLintFunction({
806
+ severity: v.Severity.WARNING,
799
807
  message: "Nested lists:\nnested lists are hard to read on mobile devices;\ndo not use additional indentation."
800
808
  })
801
- }), pe = h.makeWidgetRule({
809
+ }), ge = v.makeWidgetRule({
802
810
  name: "numeric-input-missing-label",
803
811
  widgetType: "numeric-input",
804
812
  lint(e) {
805
813
  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.");
806
814
  }
807
- }), me = h.makeWidgetRule({
815
+ }), _e = v.makeWidgetRule({
808
816
  name: "numeric-input-widget-error",
809
817
  widgetType: "numeric-input",
810
818
  lint(e) {
@@ -813,20 +821,20 @@ Shorten it to 500 characters or fewer.`);
813
821
  e.strict && (!e.answerForms || e.answerForms.length === 0) && t.push(linterError(`Answer ${n + 1} requires a format, but no format was selected`));
814
822
  }), t;
815
823
  }
816
- }), he = h.makeWidgetRule({
824
+ }), ve = v.makeWidgetRule({
817
825
  name: "phet-simulation-widget-error",
818
826
  widgetType: "phet-simulation",
819
827
  lint(e) {
820
- if (a(e.options.url, "en", "https://phet.colorado.edu") === null) return linterError("The URL is not from the PhET domain.");
828
+ if (o(e.options.url, "en", "https://phet.colorado.edu") === null) return linterError("The URL is not from the PhET domain.");
821
829
  }
822
- }), ge = h.makeWidgetRule({
830
+ }), ye = v.makeWidgetRule({
823
831
  name: "python-program-widget-error",
824
832
  widgetType: "python-program",
825
833
  lint(e) {
826
834
  let t = [], n = e.options.height;
827
835
  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));
828
836
  }
829
- }), _e = h.makeWidgetRule({
837
+ }), be = v.makeWidgetRule({
830
838
  name: "radio-widget-error",
831
839
  widgetType: "radio",
832
840
  lint(e) {
@@ -838,31 +846,31 @@ Shorten it to 500 characters or fewer.`);
838
846
  }), X = 2;
839
847
  function hasMixedContent(e) {
840
848
  let t = [];
841
- return s(o(e.trim(), {}), (e) => {
849
+ return c(s(e.trim(), {}), (e) => {
842
850
  e.type !== "paragraph" && t.push(e);
843
851
  }), t.length > 1 && t.some((e) => e.type === "image");
844
852
  }
845
- var ve = h.makeWidgetRule({
853
+ var xe = v.makeWidgetRule({
846
854
  name: "sorter-widget-error",
847
855
  widgetType: "sorter",
848
856
  lint(e) {
849
857
  let t = [], n = e.options.correct ?? [];
850
858
  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));
851
859
  }
852
- }), ye = h.makeWidgetRule({
860
+ }), Se = v.makeWidgetRule({
853
861
  name: "sorter-legend-missing",
854
862
  widgetType: "sorter",
855
863
  lint(e) {
856
864
  if (e.options.legend == null) return linterWarning("Sorter exercises without a labeled legend are marked inaccessible.");
857
865
  }
858
- }), be = h.makeWidgetRule({
866
+ }), Ce = v.makeWidgetRule({
859
867
  name: "sorter-legend-description",
860
868
  widgetType: "sorter",
861
869
  lint(e) {
862
870
  let { legend: t } = e.options;
863
871
  if (t != null && t.ariaLabel.trim() === "") return linterWarning("Sorter legend description cannot be blank.");
864
872
  }
865
- }), xe = h.makeWidgetRule({
873
+ }), we = v.makeWidgetRule({
866
874
  name: "sorter-legend-labels",
867
875
  widgetType: "sorter",
868
876
  lint(e) {
@@ -878,14 +886,14 @@ var ve = h.makeWidgetRule({
878
886
  for (let { side: e, text: t } of n) t.trim() === "" ? r.push(`Sorter legend ${e} label cannot be blank.`) : t.length > 30 && r.push(`Sorter legend ${e} label is longer than 30 characters.`);
879
887
  return r.map((e) => linterWarning(e));
880
888
  }
881
- }), Se = h.makeWidgetRule({
889
+ }), Te = v.makeWidgetRule({
882
890
  name: "sorter-widget-warning",
883
891
  widgetType: "sorter",
884
892
  lint(e) {
885
893
  let t = [], { layout: n, correct: r = [] } = e.options;
886
894
  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));
887
895
  }
888
- }), Z = h.makeRule({
896
+ }), Ee = v.makeRule({
889
897
  name: "static-widget-in-question-stem",
890
898
  selector: "widget",
891
899
  lint: (e, t, n, r, i) => {
@@ -895,7 +903,32 @@ var ve = h.makeWidgetRule({
895
903
  let o = i?.widgets?.[a];
896
904
  if (o && o.static) return linterWarning("Widget in question stem is static (non-interactive).");
897
905
  }
898
- }), Ce = "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.", we = "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.";
906
+ });
907
+ //#endregion
908
+ //#region packages/perseus-linter/src/rules/table-empty-column-header.ts
909
+ function isTableNode(e) {
910
+ return e.type === "table";
911
+ }
912
+ function emptyColumnHeaderMessage(e) {
913
+ return `${e.length > 1 ? `Columns ${e.join(", ")} have` : `Column ${e[0]} has`} no header text. Screen reader users hear a column's header as they
914
+ move between its cells, so an empty header leaves them without context for
915
+ that data. Add a header, or leave every column header empty if this is a
916
+ layout table.`;
917
+ }
918
+ var De = v.makeRule({
919
+ name: "table-empty-column-header",
920
+ selector: "table",
921
+ helpLink: m,
922
+ lint: function(e, t, n) {
923
+ let r = n[0];
924
+ if (!isTableNode(r)) return;
925
+ let i = r.header;
926
+ if (i.every(a)) return;
927
+ let o = [];
928
+ for (let e = 1; e < i.length; e++) a(i[e]) && o.push(e + 1);
929
+ if (o.length > 0) return linterWarning(emptyColumnHeaderMessage(o));
930
+ }
931
+ }), Oe = "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.", ke = "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.";
899
932
  function getTextContent(e) {
900
933
  return typeof e == "string" ? e : Array.isArray(e) ? e.map(getTextContent).join("") : e && typeof e == "object" ? getTextContent(e.content) : "";
901
934
  }
@@ -905,46 +938,49 @@ function getTitleText(e) {
905
938
  function hasEmptyHeaders(e) {
906
939
  return e.header.every((e) => getTextContent(e).trim() === "");
907
940
  }
908
- var Te = h.makeRule({
941
+ var Z = v.makeRule({
909
942
  name: "table-missing-caption",
910
943
  selector: "table",
944
+ helpLink: m,
911
945
  lint: function(e, t, n) {
912
946
  if (hasEmptyHeaders(n[0])) return;
913
947
  let r = e.parent();
914
- if (r?.type !== "titledTable") return linterGuideline(Ce);
915
- if (getTitleText(r) === "") return linterGuideline(we);
948
+ if (r?.type !== "titledTable") return linterGuideline(Oe);
949
+ if (getTitleText(r) === "") return linterGuideline(ke);
916
950
  }
917
- }), Ee = h.makeRule({
951
+ }), Ae = v.makeRule({
918
952
  name: "table-missing-cells",
919
953
  selector: "table",
954
+ helpLink: m,
920
955
  lint: function(e, t, n, r) {
921
956
  let i = n[0], a = i.header.length, o = i.cells.map((e) => e.length);
922
957
  for (let e = 0; e < o.length; e++) if (o[e] !== a) return linterWarning(`Table rows don't match header:
923
958
  The table header has ${a} cells, but
924
959
  Row ${e + 1} has ${o[e]} cells.`);
925
960
  }
926
- }), De = "This table has only one cell:\nScreen readers announce a table's structure (rows, columns and headers)\nbefore its content, which adds noise when a table holds a single value. Please use\na paragraph or bold text instead.";
961
+ }), je = "This table has only one cell:\nScreen readers announce a table's structure (rows, columns and headers)\nbefore its content, which adds noise when a table holds a single value. Please use\na paragraph or bold text instead.";
927
962
  function isSingleCellTable(e) {
928
963
  return e.header.length === 1 && e.cells.length <= 1;
929
964
  }
930
- var Oe = h.makeRule({
965
+ var Me = v.makeRule({
931
966
  name: "table-single-cell",
932
967
  selector: "table",
968
+ helpLink: m,
933
969
  lint: function(e, t, n) {
934
- if (isSingleCellTable(n[0])) return linterWarning(De);
970
+ if (isSingleCellTable(n[0])) return linterWarning(je);
935
971
  }
936
- }), ke = h.makeRule({
972
+ }), Ne = v.makeRule({
937
973
  name: "unbalanced-code-delimiters",
938
974
  pattern: /[`~]+/,
939
- lint: h.makeLintFunction({
940
- severity: h.Severity.ERROR,
975
+ lint: v.makeLintFunction({
976
+ severity: v.Severity.ERROR,
941
977
  message: "Unbalanced code delimiters:\ncode blocks should begin and end with the same type and number of delimiters"
942
978
  })
943
- }), Ae = h.makeRule({
979
+ }), Pe = v.makeRule({
944
980
  name: "unescaped-dollar",
945
981
  selector: "unescapedDollar",
946
- lint: h.makeLintFunction({
947
- severity: h.Severity.ERROR,
982
+ lint: v.makeLintFunction({
983
+ severity: v.Severity.ERROR,
948
984
  message: "Unescaped dollar sign:\nDollar signs must appear in pairs or be escaped as \\$"
949
985
  })
950
986
  });
@@ -956,20 +992,17 @@ function allRules() {
956
992
  re,
957
993
  ie,
958
994
  ne,
959
- x,
960
- y,
961
- b,
962
- S,
963
995
  w,
964
- E,
996
+ S,
997
+ C,
965
998
  T,
966
999
  D,
967
- O,
968
1000
  k,
1001
+ O,
969
1002
  A,
1003
+ j,
970
1004
  M,
971
1005
  N,
972
- P,
973
1006
  F,
974
1007
  I,
975
1008
  L,
@@ -978,9 +1011,9 @@ function allRules() {
978
1011
  B,
979
1012
  V,
980
1013
  H,
1014
+ U,
981
1015
  W,
982
1016
  G,
983
- K,
984
1017
  q,
985
1018
  J,
986
1019
  Y,
@@ -998,16 +1031,20 @@ function allRules() {
998
1031
  ge,
999
1032
  _e,
1000
1033
  ve,
1001
- Se,
1002
1034
  ye,
1003
1035
  be,
1004
1036
  xe,
1005
- Z,
1006
1037
  Te,
1038
+ Se,
1039
+ Ce,
1040
+ we,
1007
1041
  Ee,
1008
- Oe,
1009
- ke,
1010
- Ae
1042
+ De,
1043
+ Z,
1044
+ Ae,
1045
+ Me,
1046
+ Ne,
1047
+ Pe
1011
1048
  ];
1012
1049
  }
1013
1050
  //#endregion
@@ -1023,7 +1060,7 @@ var Q = class TreeTransformer {
1023
1060
  return TreeTransformer.isNode(e) && e.type === "text" && typeof e.content == "string";
1024
1061
  }
1025
1062
  traverse(e) {
1026
- this._traverse(this.root, new je(this.root), e);
1063
+ this._traverse(this.root, new Fe(this.root), e);
1027
1064
  }
1028
1065
  _traverse(e, t, n) {
1029
1066
  let r = "";
@@ -1043,7 +1080,7 @@ var Q = class TreeTransformer {
1043
1080
  }
1044
1081
  return r;
1045
1082
  }
1046
- }, je = class TraversalState {
1083
+ }, Fe = class TraversalState {
1047
1084
  constructor(e) {
1048
1085
  this.root = e, this._currentNode = null, this._containers = new $(), this._indexes = new $(), this._ancestors = new $();
1049
1086
  }
@@ -1204,6 +1241,6 @@ function pushContextStack(e, t) {
1204
1241
  };
1205
1242
  }
1206
1243
  //#endregion
1207
- export { h as Rule, d as libVersion, lintPerseusArticle, lintPerseusItem, lintPerseusRenderer, ee as linterContextDefault, pushContextStack, runLinter };
1244
+ export { v as Rule, f as libVersion, lintPerseusArticle, lintPerseusItem, lintPerseusRenderer, ee as linterContextDefault, pushContextStack, runLinter };
1208
1245
 
1209
1246
  //# sourceMappingURL=index.js.map