Repository: rust-lang/mdBook (language: rust)

Issue:
Rust 2024 edition is ignored for code examples
### Problem

As discussed in the Forum, mdbook seems to ignore new restrictions required by the new Rust 2024 edition:

Some days ago, I started porting the books's examples to Rust 2024 -- actually it is more testing with Rust 2024, as most examples should be compatible.

For that, I edited book.toml:

[rust]
edition = "2024"

and rebuild the book with "mdbook clean; mdbook build" and shipped it with rsync.

The strange thing is, that the FFI example runs fine when clicking the run button, but when I copy it into Rust's playground (which uses now Rust 2024 as default) compile fails, because extern needs now an unsafe block. If I switch playground to 2021 edition, it works.

My only explanation is currently, that mdbook masks 2024 internally still ?

### Steps

$ cat book.toml 
[book]
authors = ["S. Salewski"]
language = "en"
multilingual = false
src = "src"
title = "Rust for C-Programmers"
[rust]
edition = "2024"
[output.html.playground]
editable = true
[output.html]
git-repository-url = "https://github.com/StefanSalewski/Rust_for_C-Programmers"
smart-punctuation = true
[output.html.print]
enable = true    # include support for printable output
page-break = true # insert page-break after each chapter

mdbook build

$ rsync -r  book ...

firefox https://rust-for-c-programmers.salewskis.de/ch25/25_6_calling_c_functions_ffi.html

Click the "run" button (runs, while it should fail to compile as in the playground with 2024 edition)

### Possible Solution(s)

Fix it.

### Notes

The same with Chromium web browser.

### Version

```text
$ mdbook --version
mdbook v0.4.45
```


Discussion / hints:

Fix patch:
diff --git a/src/theme/book.js b/src/theme/book.js
index d78bd79651..089bd1296b 100644
--- a/src/theme/book.js
+++ b/src/theme/book.js
@@ -111,11 +111,11 @@ function playground_text(playground, hidden = true) {
         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";
-        }
+        classes.forEach(className => {
+            if (className.startsWith("edition")) {
+                edition = className.slice(7);
+            }
+        });
         var params = {
             version: "stable",
             optimize: "0",


Test patch: