Skip to content

Instantly share code, notes, and snippets.

@arthurattwell
Last active January 10, 2023 14:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save arthurattwell/7fa3f615609417e06d0300b5764cc1cb to your computer and use it in GitHub Desktop.
Save arthurattwell/7fa3f615609417e06d0300b5764cc1cb to your computer and use it in GitHub Desktop.
Converting markdown MCQs to Betterquiz BQF format

Converting markdown MCQs to Betterquiz BQF format

Betterquiz is a format and engine for creating multiple-choice tests and embedding them on websites in an iframe. It’s an open-source project hosted here.

For Bettercare, we create MCQ quizzes for books in kramdown-flavoured markdown. We then need to quickly convert them to BQF for uploading to our Betterquiz server.

This series of regex search-and-replaces turns a kramdown quiz file into a BQF file. In each case, the first line is the search, and the second line the replace (unless you should replace with nothing).

  1. Remove numbers from questions.

    Find (and replace with an empty line) lines starting with a number between 1 and 99, a dot, and a tab (regex background):

    \n^[0-9]{1,2}\.\t
    \n\n
    
  2. Remove the tab before bullet characters and +:

    \n\t([\-,\+])\t
    \n$1\t
    
  3. Remove YAML style:

    style:.*\n
    

    Note: You must manually add the book title. E.g.

    title: Quiz 1. HIV Infection

    must become

    title: Adult HIV. Quiz 1. HIV Infection

  4. Remove # heading, by replacing this with nothing:

    \n#(.*)\n
    

    Also manually remove any {% include metadata %} tag.

  5. Remove the opening instruction phrase:

    Please choose.*\n
    
  6. Remove layout YAML, if any, by replacing this with nothing:

    \nlayout: (.*)
    
  7. Remove -s around YAML frontmatter, by replacing this with nothing:

    ---\n
    
  8. Remove markdown emphasis and strong elements with a non-regex search-and-replace to remove *.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment