@khanacademy/perseus-linter 5.4.0 → 5.4.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -28,7 +28,7 @@ function _interopNamespaceCompat(e) {
28
28
 
29
29
  var KAS__namespace = /*#__PURE__*/_interopNamespaceCompat(KAS);
30
30
 
31
- const libName="@khanacademy/perseus-linter";const libVersion="5.4.0";perseusUtils.addLibraryVersionToPerseusDebug(libName,libVersion);
31
+ const libName="@khanacademy/perseus-linter";const libVersion="5.4.2";perseusUtils.addLibraryVersionToPerseusDebug(libName,libVersion);
32
32
 
33
33
  const linterContextDefault={contentType:"",highlightLint:false,stack:[]};
34
34
 
@@ -163,7 +163,7 @@ var PythonProgramWidgetError = Rule.makeRule({name:"python-program-widget-error"
163
163
 
164
164
  var RadioWidgetError = Rule.makeRule({name:"radio-widget-error",severity:Rule.Severity.ERROR,selector:"widget",lint:function(state,content,nodes,match,context){if(state.currentNode().widgetType!=="radio"){return}const nodeId=state.currentNode().id;if(!nodeId){return}const widget=context?.widgets?.[nodeId];if(!widget){return}const choices=widget.options.choices;if(!choices.some(choice=>choice.correct)){return "No choice is marked as correct."}const correctChoices=choices.filter(choice=>choice.correct);const hasNotaCorrect=correctChoices.some(choice=>choice.isNoneOfTheAbove);if(hasNotaCorrect&&correctChoices.length>1){return "Cannot mark both None of the Above and another choice as correct."}return}});
165
165
 
166
- const minCards=2;var SorterWidgetError = Rule.makeRule({name:"sorter-widget-error",severity:Rule.Severity.ERROR,selector:"widget",lint:function(state,content,nodes,match,context){if(state.currentNode().widgetType!=="sorter"){return}const nodeId=state.currentNode().id;if(!nodeId){return}const widget=context?.widgets?.[nodeId];if(!widget){return}const warnings=[];const correct=widget.options.correct??[];if(correct.length<minCards){warnings.push(`Sorter requires at least ${minCards} cards.`);}if(correct.some(card=>card.trim()==="")){warnings.push("Sorter cards cannot be blank.");}return warnings.join("\n\n")}});
166
+ const minCards=2;function hasMixedContent(card){const contentNodes=[];pureMarkdown.traverseContent(pureMarkdown.parse(card.trim(),{}),node=>{if(node.type!=="paragraph"){contentNodes.push(node);}});return contentNodes.length>1&&contentNodes.some(node=>node.type==="image")}var SorterWidgetError = Rule.makeRule({name:"sorter-widget-error",severity:Rule.Severity.ERROR,selector:"widget",lint:function(state,content,nodes,match,context){if(state.currentNode().widgetType!=="sorter"){return}const nodeId=state.currentNode().id;if(!nodeId){return}const widget=context?.widgets?.[nodeId];if(!widget){return}const warnings=[];const correct=widget.options.correct??[];if(correct.length<minCards){warnings.push(`Sorter requires at least ${minCards} cards.`);}if(correct.some(card=>card.trim()==="")){warnings.push("Sorter cards cannot be blank.");}if(correct.some(hasMixedContent)){warnings.push("Sorter cards cannot mix images with other content.");}return warnings.join("\n\n")}});
167
167
 
168
168
  const sorterMaxIdealCards=5;const sorterMaxHorizontalCards=5;var SorterWidgetWarning = Rule.makeRule({name:"sorter-widget-warning",severity:Rule.Severity.WARNING,selector:"widget",lint:function(state,content,nodes,match,context){if(state.currentNode().widgetType!=="sorter"){return}const nodeId=state.currentNode().id;if(!nodeId){return}const widget=context?.widgets?.[nodeId];if(!widget){return}const warnings=[];const options=widget.options;const{layout,correct=[]}=options;if(correct.length>perseusCore.SORTER_MAX_CARDS){warnings.push(`Sorter cannot have more than ${perseusCore.SORTER_MAX_CARDS} cards.`);}if(layout==="horizontal"&&correct.length>sorterMaxHorizontalCards){warnings.push(`Sorter cannot have more than ${sorterMaxHorizontalCards} cards in horizontal layout.`);}if(correct.length>sorterMaxIdealCards){warnings.push(`Having more than ${sorterMaxIdealCards} cards in Sorter is discouraged.`);}return warnings.join("\n\n")}});
169
169