mitodl / ocw-to-hugo

A command line utility for taking master.json output from ocw-data-parser and producing markdown for use with hugo-course-publisher
3 stars 0 forks source link

fix overzealous turndown filter on quiz rule #497

Closed gumaerc closed 2 years ago

gumaerc commented 2 years ago

Pre-Flight checklist

What are the relevant tickets?

Closes https://github.com/mitodl/ocw-to-hugo/issues/493

What's this PR do?

In https://github.com/mitodl/ocw-to-hugo/pull/418 we added support for parsing multiple choice type quizzes embedded in legacy OCW courses. One of the turndown rules that does this, multiple_choice_question, was filtering on:

        node.getAttribute("class") === "problem_question" &&
        node.getElementsByClassName("problem_radio_input")

The issue with this is that even if getElementsByClassName doesn't find anything, it still returns an object. This means that HTML that shouldn't have been matching that rule was being matched and processed as if it were an multiple choice question. I corrected this by changing it to:

        node.getAttribute("class") === "problem_question" &&
        node.getElementsByClassName("problem_radio_input").length > 0

A try / catch statement with Winston file logging was also added to the html2markdown function so any errors converting html to markdown are logged.

How should this be manually tested?

codecov-commenter commented 2 years ago

Codecov Report

Merging #497 (d0148c4) into master (0e394ac) will decrease coverage by 0.13%. The diff coverage is 80.00%.

@@            Coverage Diff             @@
##           master     #497      +/-   ##
==========================================
- Coverage   96.47%   96.33%   -0.14%     
==========================================
  Files          18       18              
  Lines        2126     2130       +4     
==========================================
+ Hits         2051     2052       +1     
- Misses         75       78       +3     
Impacted Files Coverage Δ
src/turndown.js 92.30% <80.00%> (-0.25%) :arrow_down:
src/markdown_generators.js 97.22% <0.00%> (-1.39%) :arrow_down:

Continue to review full report at Codecov.

Legend - Click here to learn more Δ = absolute <relative> (impact), ø = not affected, ? = missing data Powered by Codecov. Last update 0e394ac...d0148c4. Read the comment docs.