doddoreul / google-code-prettify

Automatically exported from code.google.com/p/google-code-prettify
Apache License 2.0
0 stars 0 forks source link

When users copy code, line numbers are included with the copied text. #156

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?
1. Get prettyprint.js working on your site and turn line numbers on by 
including the linenums class.
2. Select the text (tested in latest version of chrome) and copy it (ctrl + c).
3. Paste the code somewhere. You will notice line numbers included with the 
paste.

What is the expected output?  What do you see instead?
There are some other sites that have code snippets similar to prettify and also 
include line numbers, but if you copy the text and are careful to not start 
highlighting on the number then you only get the code, no line numbers. It is 
very helpful when you are copying large snippets of code.

What version are you using?  On what browser?
I am using Google Chrome v11.0.696.71 and Windows 7.

Please provide any additional information below.
Is there a way to set this up so it lets users highlight only the code without 
the line numbers? If so, this would be great. If not, how hard would it be to 
add this feature?

Original issue reported on code.google.com by alex.f...@codetunnel.com on 3 Jun 2011 at 5:44

GoogleCodeExporter commented 8 years ago
UPDATE: I found a site with a good sample of this in action.

http://studiostyl.es/schemes/son-of-obsidian

The code samples in this theme gallery have line numbers, but you can freely 
highlight the text to the right of the line numbers and not copy the line 
numbers.

Original comment by alex.f...@codetunnel.com on 3 Jun 2011 at 6:55

GoogleCodeExporter commented 8 years ago
I am having trouble confirming the bug.  

I am using Chrome and I copied the example from 
http://google-code-prettify.googlecode.com/svn/trunk/README.html under "How do 
I put line numbers in my code?" and pasted it below and I don't get line 
numbers.  Does that code snippet exhibit the problem for you?

// This is line 4.
foo();
bar();
baz();
boo();
far();
faz();

Original comment by mikesamuel@gmail.com on 4 Jun 2011 at 9:50

GoogleCodeExporter commented 8 years ago
Actually you're right, in Chrome it highlights the numbers but does not 
actually copy them. However, I did open Firefox 3.6.17 and it does the 
opposite. It does not highlight the line numbers, but DOES copy them. I checked 
in IE 9 and it copies the numbers as well.

IE 9:

1.command.Parameters.Add(new SqlParameter("Username", 
"Alex"));2.command.Parameters.Add(new SqlParameter("Password", 
"Exp3rtC0d3r1"));3.command.Parameters.Add(new SqlParameter("Administrator", true

FF 3.6.17

   1. command.Parameters.Add(new SqlParameter("Username", "Alex"));
   2. command.Parameters.Add(new SqlParameter("Password", "Exp3rtC0d3r1"));
   3. command.Parameters.Add(new SqlParameter("Administrator", true);

^^Direct pastes from 
http://www.codetunnel.com/blog/post/73/introduction-to-entity-framework-part-i--
object-relational-mapping
No modifications made.

Here are pastes of the same text you tried to copy:

IE 9

// This is line 4.5.foo();bar();baz();boo();far();10.faz();

FF 3.6.17

   4. // This is line 4.
   5. foo();
   6. bar();
   7. baz();
   8. boo();
   9. far();
  10. faz();

^^ Note that it has line numbers for every line in the pasted text from 
firefox, even though only lines 5 and 10 had numbers on them in the 
readme.html. Weird. Something to do with the way FF decides to copy ordered 
lists I assume.

Anyway in all three browsers, the line numbered text on 
http://studiostyl.es/schemes/son-of-obsidian does not include numbers when you 
copy. And in all three browsers the numbers do not appear to highlight with the 
text you are highlighting. That's the functionality I would love to see in 
prettify :)

Original comment by alex.f...@codetunnel.com on 4 Jun 2011 at 10:04

GoogleCodeExporter commented 8 years ago
Update: Now that I am at my normal computer, here is a paste from Firfox 4.0

    // This is line 4.
    foo();
    bar();
    baz();
    boo();
    far();
    faz();

Looks like they changed the way it pastes ordered lists now. I am still 
interested in preventing line number pasting more natively than depending on 
the browser to decide. CodeTunnel.com, the site I use prettify with, tries to 
be backward compatible with most browser versions. It would be awesome if it 
worked like the sample I linked to.

Original comment by alex.f...@codetunnel.com on 5 Jun 2011 at 3:20

GoogleCodeExporter commented 8 years ago
Thanks for the cross-browser comparison.

I agree that cross-browser support of copy-paste is important, and the IE 9 
behavior is just horrible.  Ideally I would like a solution that does both that 
and degrades well when width is limited and source code uses 
white-space:pre-wrap.

http://code.google.com/p/google-code-prettify/source/browse/trunk/src/prettify.c
ss uses a table instead of an ordered list to display code.  Such an approach 
might work.  A table with one cell to the left containing the numbers and 
another on the right would work, but would be fragile when the right cell has 
white-space:pre-wrap.

Original comment by mikesamuel@gmail.com on 5 Jun 2011 at 4:15

GoogleCodeExporter commented 8 years ago
Keep me posted on what you figure out. I'll be watching for updates and am 
excited to see if this gets implemented.

Original comment by alex.f...@codetunnel.com on 6 Jun 2011 at 3:22

GoogleCodeExporter commented 8 years ago
Will do.  I think if you keep this issue starred, you should be notified when I 
update it.

Original comment by mikesamuel@gmail.com on 6 Jun 2011 at 4:38

GoogleCodeExporter commented 8 years ago
Indeed I am ;)

Original comment by alex.f...@codetunnel.com on 6 Jun 2011 at 4:39