HighDots Forums  

Non-selectable text

Cascading Style Sheets Layout/presentation on the WWW (comp.infosystems.www.authoring.stylesheets)


Discuss Non-selectable text in the Cascading Style Sheets forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
michaelp
 
Posts: n/a

Default Non-selectable text - 08-11-2006 , 10:35 AM






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


Reply With Quote
  #2  
Old   
Christian Kirsch
 
Posts: n/a

Default Re: Non-selectable text - 08-11-2006 , 10:51 AM






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?


Reply With Quote
  #3  
Old   
Harlan Messinger
 
Posts: n/a

Default Re: Non-selectable text - 08-11-2006 , 11:50 AM



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.


Reply With Quote
  #4  
Old   
David Tiktin
 
Posts: n/a

Default Re: Non-selectable text - 08-11-2006 , 12:06 PM



On 11 Aug 2006, michaelp <michaelp (AT) hio (DOT) no> wrote:

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


Reply With Quote
  #5  
Old   
Spartanicus
 
Posts: n/a

Default Re: Non-selectable text - 08-11-2006 , 12:22 PM



michaelp <michaelp (AT) hio (DOT) no> wrote:

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


Reply With Quote
  #6  
Old   
Spartanicus
 
Posts: n/a

Default Re: Non-selectable text - 08-11-2006 , 12:32 PM



Spartanicus <invalid (AT) invalid (DOT) invalid> wrote:

Quote:
apologies for posting code, I don't currently have access to my webspace
URL may not work:
http://homepage.ntlworld.ie/spartanicus/generated_line_numbering.htm

--
Spartanicus


Reply With Quote
  #7  
Old   
Jeremy
 
Posts: n/a

Default Re: Non-selectable text - 08-11-2006 , 06:29 PM



Spartanicus wrote:
Quote:
Spartanicus <invalid (AT) invalid (DOT) invalid> wrote:

apologies for posting code, I don't currently have access to my webspace

URL may not work:
http://homepage.ntlworld.ie/spartanicus/generated_line_numbering.htm

In Firefox, all lines are numbered 1.

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

Jeremy


Reply With Quote
  #8  
Old   
Spartanicus
 
Posts: n/a

Default Re: Non-selectable text - 08-11-2006 , 06:54 PM



Jeremy <jeremy (AT) pinacol (DOT) com> wrote:

Quote:
apologies for posting code, I don't currently have access to my webspace

URL may not work:
http://homepage.ntlworld.ie/spartanicus/generated_line_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


Reply With Quote
  #9  
Old   
Dr John Stockton
 
Posts: n/a

Default Re: Non-selectable text - 08-12-2006 , 01:47 PM



JRS: In article <ebi4k9$r9e$1 (AT) dolly (DOT) uninett.no>, dated Fri, 11 Aug 2006
16:35:53 remote, seen in news:comp.infosystems.www.authoring.stylesheets
, michaelp <michaelp (AT) hio (DOT) no> posted :
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.htm> jscr maths, dates, sources.
<URL:http://www.merlyn.demon.co.uk/> TP/BP/Delphi/jscr/&c, FAQ items, links.


Reply With Quote
  #10  
Old   
Michael Preminger
 
Posts: n/a

Default Re: Non-selectable text - 08-12-2006 , 02:37 PM



Christian Kirsch wrote:
Quote:
michaelp schrieb:

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


Reply With Quote
Reply




Thread Tools
Display Modes

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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.