Help | Site Map
Connecting Tech Pros Worldwide
 
 
LinkBack Thread Tools
  #1  
Old August 11th, 2006, 03:25 PM
michaelp
Guest
 
Posts: n/a
Default Non-selectable text

Hello!

I am teaching programming, and display code snippets with line numbers
for easy reference.

If possible, I would like to make these line numbers non-sselectable, so
that if students copy my code from the browser, they do not need to
manually strip the line numbers to make the code work.

Does css have a style to this effect?

Thanks

Michael

  #2  
Old August 11th, 2006, 03:45 PM
Christian Kirsch
Guest
 
Posts: n/a
Default Re: Non-selectable text

michaelp schrieb:
Quote:
Hello!
>
I am teaching programming, and display code snippets with line numbers
for easy reference.
>
If possible, I would like to make these line numbers non-sselectable, so
that if students copy my code from the browser, they do not need to
manually strip the line numbers to make the code work.
>
Does css have a style to this effect?
>
No. And even if it had - what about browsers like lynx which ignore CSS?
  #3  
Old August 11th, 2006, 04:45 PM
Harlan Messinger
Guest
 
Posts: n/a
Default Re: Non-selectable text

michaelp wrote:
Quote:
Hello!
>
I am teaching programming, and display code snippets with line numbers
for easy reference.
>
If possible, I would like to make these line numbers non-sselectable, so
that if students copy my code from the browser, they do not need to
manually strip the line numbers to make the code work.
>
Does css have a style to this effect?
No.

But if you use an ordered list (OL), you don't have to enter the line
numbers explicitly, and IE and Firefox, at least, don't include the
numbers in selected text.
  #4  
Old August 11th, 2006, 04:55 PM
David Tiktin
Guest
 
Posts: n/a
Default Re: Non-selectable text

On 11 Aug 2006, michaelp <michaelp@hio.nowrote:
Quote:
I am teaching programming, and display code snippets with line
numbers for easy reference.
>
If possible, I would like to make these line numbers
non-sselectable, so that if students copy my code from the
browser, they do not need to manually strip the line numbers to
make the code work.
>
Does css have a style to this effect?
As a programmer, I appreciate your thought, both in providing line
numbers and for looking for a way for you students to be able to cut
and paste the code without line numbers. I presume you thought of
providing a "cut and paste friendly" version of each page, like the
"printer friendly" versions you often see? If you store the code just
as text and insert line numbers with some kind of server side
processing (php?), that shouldn't be too onerous, just an extra link
to the source text file.

You probably already know that how a browser selects text (if it does)
could well vary from browser to browser? That said, how are you
inserting the line numbers? As inline text like:

<pre>
1 int main(int argc, char ** argv)
2 {
....
</pre>

In that case, I don't see how you can avoid selecting the numbers with
the text unless the browser supports column selection, which none I'm
aware of do. (My programming editor does, for which I'm very
grateful!) But what if the line numbers were in a separate div,
floated to the left of the div containing the code. I'll bet most
graphical browsers your students are likely to use would select the
code without including the line numbers since they're in a different
div. I haven't tried it, though. Just a thought.

Dave

--
D.a.v.i.d T.i.k.t.i.n
t.i.k.t.i.n [at] a.d.v.a.n.c.e.d.r.e.l.a.y [dot] c.o.m
  #5  
Old August 11th, 2006, 05:15 PM
Spartanicus
Guest
 
Posts: n/a
Default Re: Non-selectable text

michaelp <michaelp@hio.nowrote:
Quote:
>I am teaching programming, and display code snippets with line numbers
>for easy reference.
>
>If possible, I would like to make these line numbers non-sselectable, so
>that if students copy my code from the browser, they do not need to
>manually strip the line numbers to make the code work.
>
>Does css have a style to this effect?
Maybe. It requires a browser with support for generated content, CSS
counters and generated content should not be selectable.

Opera allows selection of the generated content. My copy of Firefox
(1.5.0.1) does not select generated content, but it's recent support for
CSS counters is buggy, maybe a more recent nightly build has fixed that.

Example code of how you could do that (apologies for posting code, I
don't currently have access to my webspace):

code:before{content:counter(line) " ";counter-increment:line}

<pre>
<code>&lt;table cellspacing="0" cellpadding="0" border="0"></code>
<code &lt;tr></code>
<code &lt;td>&lt;/td></code>
<code &lt;/tr></code>
<code>&lt;/table></code>
</pre>

--
Spartanicus
  #6  
Old August 11th, 2006, 05:25 PM
Spartanicus
Guest
 
Posts: n/a
Default Re: Non-selectable text

Spartanicus <invalid@invalid.invalidwrote:
Quote:
>apologies for posting code, I don't currently have access to my webspace
URL may not work:
http://homepage.ntlworld.ie/spartani..._numbering.htm

--
Spartanicus
  #7  
Old August 11th, 2006, 11:25 PM
Jeremy
Guest
 
Posts: n/a
Default Re: Non-selectable text

Spartanicus wrote:
Quote:
Spartanicus <invalid@invalid.invalidwrote:
>
Quote:
>apologies for posting code, I don't currently have access to my webspace
>
URL may not work:
http://homepage.ntlworld.ie/spartani..._numbering.htm
>
In Firefox, all lines are numbered 1.

In Opera, lines are numbered correctly, but line numbers are included in
selection.

Jeremy
  #8  
Old August 11th, 2006, 11:45 PM
Spartanicus
Guest
 
Posts: n/a
Default Re: Non-selectable text

Jeremy <jeremy@pinacol.comwrote:
Quote:
Quote:
Quote:
>>apologies for posting code, I don't currently have access to my webspace
>>
>URL may not work:
>http://homepage.ntlworld.ie/spartani..._numbering.htm
>>
>
>In Firefox, all lines are numbered 1.
>
>In Opera, lines are numbered correctly, but line numbers are included in
>selection.
Had you read the thread you would have noticed that my original message
already contained the possible caveats.

--
Spartanicus
  #9  
Old August 12th, 2006, 07:25 PM
Michael Preminger
Guest
 
Posts: n/a
Default Re: Non-selectable text

Christian Kirsch wrote:
Quote:
michaelp schrieb:
>
Quote:
>>Hello!
>>
>>I am teaching programming, and display code snippets with line numbers
>>for easy reference.
>>
>>If possible, I would like to make these line numbers non-sselectable, so
>>that if students copy my code from the browser, they do not need to
>>manually strip the line numbers to make the code work.
>>
>>Does css have a style to this effect?
>>
>
>
No.
Thanks for the prompt reply.
Quote:
And even if it had - what about browsers like lynx which ignore CSS?
The answer to this, I suppose, is twofold.

1. Generally speaking the world is not a perfect place.
We design our web pages legible to blind people, but they cannot enjoy
the typefaces, colors and images. We still use the latter effects!!

2. Specifically, if a style I am after was available, I would use it to
the benefit of those of my students who use graphical, css compliant
browsers. The rest of the students would have to strip the numbers
manually, without affecting the benefit of the former ones.

Michael
  #10  
Old August 12th, 2006, 07:55 PM
Dr John Stockton
Guest
 
Posts: n/a
Default Re: Non-selectable text

JRS: In article <ebi4k9$r9e$1@dolly.uninett.no>, dated Fri, 11 Aug 2006
16:35:53 remote, seen in news:comp.infosystems.www.authoring.stylesheets
, michaelp <michaelp@hio.noposted :
Quote:
>
>If possible, I would like to make these line numbers non-sselectable, so
>that if students copy my code from the browser, they do not need to
>manually strip the line numbers to make the code work.
It should be possible to add and remove, under user control, these
numbers by Javascript; or to arrange that onClick on the numbered code
pops up a window of unnumbered code. In either case only one copy of
the code statements would be needed.

Alternatively, use FORTRAN-style numbering, with the numbers on the
right in comment. That way a student who modifies the code can easily
maintain a record of your contributions.

--
© John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v4.00 IE 4 ©
<URL:http://www.jibbering.com/faq/>? JL/RC: FAQ of news:comp.lang.javascript
<URL:http://www.merlyn.demon.co.uk/js-index.htmjscr maths, dates, sources.
<URL:http://www.merlyn.demon.co.uk/TP/BP/Delphi/jscr/&c, FAQ items, links.
  #11  
Old August 21st, 2006, 02:55 AM
Christopher P. Winter
Guest
 
Posts: n/a
Default Re: Non-selectable text

On Fri, 11 Aug 2006 16:35:53 +0200, michaelp <michaelp@hio.nowrote:
Quote:
>Hello!
>
>I am teaching programming, and display code snippets with line numbers
>for easy reference.
>
>If possible, I would like to make these line numbers non-sselectable, so
>that if students copy my code from the browser, they do not need to
>manually strip the line numbers to make the code work.
>
>Does css have a style to this effect?
>
There's no CSS style to do this -- as others have noted.

But how about this: I assume your students have browsers that can save HTML
files as plain text. Then if you use an ordered list to generate the line
numbers, they can just save as text and the numbers won't appear.
  #12  
Old August 23rd, 2006, 02:45 AM
Wes Groleau
Guest
 
Posts: n/a
Default Re: Non-selectable text



Christopher P. Winter wrote:
Quote:
But how about this: I assume your students have browsers that can save HTML
files as plain text. Then if you use an ordered list to generate the line
numbers, they can just save as text and the numbers won't appear.
Are you sure? Seems to me that when you save as text,
many browsers attempt to make the text resemble what
was rendered.

--
Wes Groleau

"There ain't nothin' in this world that's worth being a snot over."
-- Larry Wall
  #13  
Old August 23rd, 2006, 10:25 AM
Andy Dingley
Guest
 
Posts: n/a
Default Re: Non-selectable text

michaelp wrote:
Quote:
I am teaching programming, and display code snippets with line numbers
for easy reference.
What's a "line number" ?

Is that like FORTRAN?

  #14  
Old August 24th, 2006, 03:15 AM
Christopher P. Winter
Guest
 
Posts: n/a
Default Re: Non-selectable text

On Wed, 23 Aug 2006 01:55:16 GMT, Wes Groleau <groleau+news@freeshell.org>
wrote:
Quote:
>
>
>Christopher P. Winter wrote:
Quote:
>But how about this: I assume your students have browsers that can save HTML
>files as plain text. Then if you use an ordered list to generate the line
>numbers, they can just save as text and the numbers won't appear.
>
>Are you sure? Seems to me that when you save as text,
>many browsers attempt to make the text resemble what
>was rendered.
Before posting, I tried it in IE6, and it did strip out the numbers.
 

Bookmarks

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over network members.
Post your question now . . .
It's fast and it's free

Popular Articles