Copy button copies incorrect code to clipboard
This issue originally came up here.
It seems like in some cases, the "Copy to clipboard button" copies incorrect code to the clipboard. For example (from that issue), we get this:
#![allow(unused_variables)]
#![feature(panic_implementation)]
#![feature(core_intrinsics)]
#![no_std]
#![no_main]
fn main() {
use core::intrinsics;
use core::panic::PanicInfo;
#[panic_implementation]
#[no_mangle]
fn panic(_info: &PanicInfo) -> ! {
unsafe { intrinsics::abort() }
}
#[no_mangle]
pub fn _start() -> ! {
loop {}
}
}
where we'd expect this:
#![feature(panic_implementation)]
#![feature(core_intrinsics)]
#![no_std]
#![no_main]
use core::intrinsics;
use core::panic::PanicInfo;
#[panic_implementation]
#[no_mangle]
fn panic(_info: &PanicInfo) -> ! {
unsafe { intrinsics::abort() }
}
#[no_mangle]
pub fn _start() -> ! {
loop {}
}
Edit: I guess it has something to do with a number of span class="hidden"s being created. What's the motivation behind these?
I guess it has something to do with a number of span class="hidden"s being created. What's the motivation behind these?
This happens due to https://doc.rust-lang.org/stable/rustdoc/documentation-tests.html#pre-processing-examples and https://doc.rust-lang.org/stable/rustdoc/documentation-tests.html#hiding-portions-of-the-example ; mdbook does this just like rustdoc does.
That said, I think when we ignore, we shouldn't do this, which is the root of this issue. That is, whenever this logic is not useful, we shouldn't add it. We currently always add it, but that only matters for stuff that's rust.
would it be feasible to add a configuration option on the mdbook level to control whether the main gets added or not?
fixed it here https://github.com/rust-lang/mdBook/pull/1911#issue-1409974442