diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 7512530..2334c8c 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -1,6 +1,6 @@ # Contributing to mdbook-quiz -Thanks for your interest in contributing to mdbook-quiz! To get started, you'll want to install [cargo-make](https://github.com/sagiegurari/cargo-make) and [pnpm](https://pnpm.io/installation). Then from the root of the repository, run: +Thanks for your interest in contributing to mdbook-quiz! To get started, you'll want to install, [graco](https://github.com/willcrichton/graco), [cargo-watch](https://github.com/watchexec/cargo-watch.git), [cargo-make](https://github.com/sagiegurari/cargo-make) and [pnpm](https://pnpm.io/installation). Then from the root of the repository, run: ``` cargo make watch diff --git a/example/src/quiz.toml b/example/src/quiz.toml index 3029cf5..b864f5d 100644 --- a/example/src/quiz.toml +++ b/example/src/quiz.toml @@ -1,6 +1,23 @@ [[questions]] type = "MultipleChoice" -prompt.prompt = "What does it mean if a variable `x` is immutable?" +prompt.prompt = """ +What does it mean if a variable `x` is immutable? + +Rust: +```rust +let x = 0; +``` + +C++: +```cpp +const int x = 0; +``` + +Java: +```java +final int x = 0; +``` +""" answer.answer = "`x` cannot be changed after being assigned to a value." prompt.distractors = [ "`x` is stored in the immutable region of memory.", @@ -21,6 +38,7 @@ For example, you can make a mutable variable `x` by writing: `let mut x = 1`. [[questions]] type = "Tracing" +prompt.language="rust" prompt.program = """ fn main() { let x = 1; @@ -33,4 +51,24 @@ answer.doesCompile = false answer.lineNumber = 4 context = """ This is a compiler error because line 4 tries to mutate `x` when `x` is not marked as `mut`. +""" + +[[questions]] +type = "Tracing" +prompt.language="cpp" +prompt.program = """ + +#include + +int main() { + const int x = 1; + std::cout << x << std::endl; + x += 1; + std::cout << x << std::endl; +} +""" +answer.doesCompile = false +answer.lineNumber = 6 +context = """ +This is a compiler error because line 6 tries to mutate `x` when `x` is marked as `const`. """ \ No newline at end of file diff --git a/js/packages/quiz-schema/src/tracing.ts b/js/packages/quiz-schema/src/tracing.ts index 01bd14d..f807ce5 100644 --- a/js/packages/quiz-schema/src/tracing.ts +++ b/js/packages/quiz-schema/src/tracing.ts @@ -3,6 +3,8 @@ import { QuestionFields } from "./common"; export interface TracingPrompt { /** The contents of the program to trace */ program: string; + + language?: string; } export interface TracingAnswer { diff --git a/js/packages/quiz/src/components/snippet.tsx b/js/packages/quiz/src/components/snippet.tsx index 52a88ff..a90b913 100644 --- a/js/packages/quiz/src/components/snippet.tsx +++ b/js/packages/quiz/src/components/snippet.tsx @@ -1,16 +1,12 @@ import * as rustEditor from "@wcrichto/rust-editor"; import type { monaco } from "@wcrichto/rust-editor"; //@ts-ignore -import hljs from "highlight.js/lib/core"; -//@ts-ignore -import rust from "highlight.js/lib/languages/rust"; +import hljs from "highlight.js"; //@ts-ignore import lean from "highlightjs-lean"; import React, { useContext, useEffect, useRef } from "react"; import ReactDOM from "react-dom/client"; -// This reduces bundle size by not including a bunch of extra languages -hljs.registerLanguage("rust", rust); hljs.registerLanguage("lean", lean); export let DefaultLanguageContext = React.createContext( diff --git a/js/packages/quiz/src/questions/tracing.tsx b/js/packages/quiz/src/questions/tracing.tsx index 9d21945..2dde255 100644 --- a/js/packages/quiz/src/questions/tracing.tsx +++ b/js/packages/quiz/src/questions/tracing.tsx @@ -30,7 +30,11 @@ export let TracingMethods: QuestionMethods = { {/* If the program does not pass, indicate the last line number involved in the compiler error. */}

- + ),