Skip to content

Commit

Permalink
Improve check
Browse files Browse the repository at this point in the history
  • Loading branch information
FAMarfuaty authored and leonidasmi committed Oct 30, 2024
1 parent 3e4eb95 commit 8f217a3
Showing 1 changed file with 6 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -47,17 +47,13 @@ export default class ListAssessment extends Assessment {
*/
findList( paper ) {
const foundLists = paper.getTree().findAll( node => node.name === "ul" || node.name === "ol" );
/*
This is a helper function to check if a list is not empty.
A list is not empty if it has at least one <li> child with paragraph node.
*/
const isListNotEmpty = list => list.childNodes.some( child => child.name === "li" && child.childNodes.some( node => node.name === "p" ) );

for ( const list of foundLists ) {
for ( const child of list.childNodes ) {
// A list is not empty if it has at least one <li> child with text.
if ( child.name === "li" && child.childNodes.some( node => node.name === "p" ) ) {
return true;
}
}
}

return false;
return foundLists.some( isListNotEmpty );
}

/**
Expand Down

0 comments on commit 8f217a3

Please sign in to comment.