import { GraderSpecificationFor } from "../graders/QuestionGrader"; import { ResponseHandler, SubmissionType } from "./responses"; /** * ## Fill-In-The-Blank (FITB) Response Element Specification * * An FITB response includes markdown-formatted content containing "blanks" and "boxes" that * students fill in to compose their response. * * The [[`FITBSpecification`]] type alias represents the information needed to specify an FITB * response as part of a question. * * Here's an example of a question with an FITB response. The content is specified as a * backtick-quoted multi-string literal in typescript. (Note there are also escaped backticks * around a markdown code block). * * ![image](media://response-sample-fitb-replacer.png) * * ```typescript * export const Practice_Questions_Iterators_And_Functors_Replacer: QuestionSpecification = { * question_id: "practice_iterators_and_functors_replacer_fitb", * tags: [], * points: 8, * mk_description: * ` * Complete the implementation of \`Replacer\` below by filling in the boxes. * * If you believe a blank/box should be **empty**, write \`BLANK\`. * `, * response: { * kind: "fill_in_the_blank", * content: * ` * \`\`\`cpp * template ; // Note: T must support == * class Replacer { * private: * const T ⌖ * const T &replacement; * * public: * Replacer(_________________________________BLANK_________________________________) * : _________________________________BLANK_________________________________ { } * * // Function call operator * _______BLANK_______ operator()(_______________BLANK_______________ item) const { * [[BOX___________________________________________________________ * * * ]] * } * }; * \`\`\` * `, * sample_solution: [ * "const T &target_in, const T &replacement_in", * "target(target_in), replacement(replacement_in)", * "void", * "T &", * "if (item == target) {\n item = replacement;\n}" * ] * } * }; * ``` * * ### Blanks and Boxes * * To specify a blank, use a pattern like `____BLANK____`. Blanks are rendered as an HTML * text input. The number of underscores controls the `size` and `maxlength` of that text * input - students may not enter more content than will "fit" in the box. A blank may occur * in the middle of a line or on its own. * * To specify a box, use a pattern like `[[____BOX____\n\n\n]]`. Boxes are rendered as an HTML * textarea input. The number of underscores controls the width of the textarea, and the number * of newlines controls the height. There must be at least one newline (otherwise use a blank). * If there are no underscores, the box will take up the full available width. A box may occur * in the middle of a line or on its own. Those are real newlines, though if you're writing in code * you'd use the escape sequence `\n`. Or, if you use backtick-quoted multi-line string literals, * those can just contain natural newlines. * * ### Markdown Formatting * * The content specification for an FITB response element may contain markdown formatting. In * particular, blank/box placeholders may be included inside code boxes. * * ### FITB Submissions * * A submission for an FITB response is an array of strings that specify * the content submitted for each blank/box. See [[FITBSubmission]] for details. * */ export type FITBSpecification = { /** * The discriminant `"fill_in_the_blank"` is used to distinguish FITB specifications. */ kind: "fill_in_the_blank"; /** * The content specification of the FITB response. May include markdown and placeholders for blanks/boxes. */ content: string; /** * A sample solution, which may not be blank or invalid. */ sample_solution?: SubmissionType<"fill_in_the_blank">; /** * A default grader, used to evaluate submissions for this response. */ default_grader?: GraderSpecificationFor<"fill_in_the_blank">; }; /** * A submission for an FITB response is an array of strings that specify * the content submitted for each blank. * * The subset of [[`FITBSubmissions`]] that are valid (see [[`validate_submission`]]) for a * particular FITB response are those with exactly the right number of array elements to * match the number of blanks and boxes in the response. */ export type FITBSubmission = readonly string[]; export declare const FITB_HANDLER: ResponseHandler<"fill_in_the_blank">;