Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Copy button copies incorrect code to clipboard #712

Open
mtn opened this issue Jun 20, 2018 · 3 comments
Open

Copy button copies incorrect code to clipboard #712

mtn opened this issue Jun 20, 2018 · 3 comments
Labels
A-Code-Blocks Area: Code blocks

Comments

@mtn
Copy link

mtn commented Jun 20, 2018

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?

@steveklabnik
Copy link
Member

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.

@iolivia
Copy link

iolivia commented Jul 13, 2020

would it be feasible to add a configuration option on the mdbook level to control whether the main gets added or not?

@yoyomo
Copy link

yoyomo commented Oct 17, 2022

fixed it here #1911 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-Code-Blocks Area: Code blocks
Projects
None yet
Development

No branches or pull requests

5 participants