Repository: google/comprehensive-rust
File: theme/book.js (JavaScript)

Code before:
        }
    }

    function run_rust_code(code_block) {
        var result_stderr_block = code_block.querySelector(".result.stderr");
        if (!result_stderr_block) {
            result_stderr_block = document.createElement('code');
            result_stderr_block.className = 'result stderr hljs nohighlight hidden';

            code_block.append(result_stderr_block);
        }
        var result_block = code_block.querySelector(".result.stdout");
        if (!result_block) {
            result_block = document.createElement('code');
            result_block.className = 'result stdout hljs nohighlight';

            code_block.append(result_block);
        }

        let text = playground_text(code_block);
        let classes = code_block.querySelector('code').classList;
        let edition = "2015";
        if(classes.contains("edition2018")) {
            edition = "2018";
        } else if(classes.contains("edition2021")) {
            edition = "2021";
        }
        var params = {
            backtrace: true,
            channel: "stable",
            code: text,
            edition: edition,
            mode: "debug",
            tests: false,
            crateType: "bin",
        };

        if (text.indexOf("#![feature") !== -1) {
            params.version = "nightly";
        }

        result_block.innerText = "Running...";
        // hide stderr block while running
        result_stderr_block.innerText = "";
        result_stderr_block.classList.add("hidden");

        const playgroundModified = isPlaygroundModified(code_block);
        const startTime = window.performance.now();
        fetch_with_timeout("https://play.rust-lang.org/execute", {
            headers: {
                'Content-Type': "application/json",

Review comment (suggestion):
The idea here is cool, and I like @max-heller's comment a lot on https://github.com/rust-lang/mdBook/issues/2527#issuecomment-2602904546.

However, it should be noted that every modification to `book.js` required work when we update `mdbook.` There is unfortunately a coupling between versions of `mdbook` and the default theme, which is what we've customized here :grimacing: I now created #2924 to record this problem (which has been with us for ages).

Cc @gribozavr for reference.

Code after:
        }
    }

    function run_rust_code(code_block) {
        var result_stderr_block = code_block.querySelector(".result.stderr");
        if (!result_stderr_block) {
            result_stderr_block = document.createElement('code');
            result_stderr_block.className = 'result stderr hljs nohighlight hidden';

            code_block.append(result_stderr_block);
        }
        var result_block = code_block.querySelector(".result.stdout");
        if (!result_block) {
            result_block = document.createElement('code');
            result_block.className = 'result stdout hljs nohighlight';

            code_block.append(result_block);
        }

        let text = playground_text(code_block);
        let classes = code_block.querySelector('code').classList;
        // Unless the code block has `warnunused`, allow all "unused" lints to avoid cluttering
        // the output.
        if(!classes.contains("warnunused")) {
            text = '#![allow(unused)]\n' + text;
        }
        let edition = "2015";
        if(classes.contains("edition2018")) {
            edition = "2018";
        } else if(classes.contains("edition2021")) {
            edition = "2021";
        }
        var params = {
            backtrace: true,
            channel: "stable",
            code: text,
            edition: edition,
            mode: "debug",
            tests: false,
            crateType: "bin",
        };

        if (text.indexOf("#![feature") !== -1) {
            params.version = "nightly";
        }

        result_block.innerText = "Running...";
        // hide stderr block while running
        result_stderr_block.innerText = "";
        result_stderr_block.classList.add("hidden");