469,361 Members | 2,376 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,361 developers. It's quick & easy.

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

Aug 11 '06 #1
13 15608
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. And even if it had - what about browsers like lynx which ignore CSS?
Aug 11 '06 #2
michaelp wrote:
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.
Aug 11 '06 #3
On 11 Aug 2006, michaelp <mi******@hio.nowrote:
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
Aug 11 '06 #4
michaelp <mi******@hio.nowrote:
>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
Aug 11 '06 #5
Spartanicus <in*****@invalid.invalidwrote:
>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
Aug 11 '06 #6
Spartanicus wrote:
Spartanicus <in*****@invalid.invalidwrote:
>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
Aug 11 '06 #7
Jeremy <je****@pinacol.comwrote:
>>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
Aug 11 '06 #8
Christian Kirsch wrote:
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.
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
Aug 12 '06 #9
JRS: In article <eb**********@dolly.uninett.no>, dated Fri, 11 Aug 2006
16:35:53 remote, seen in news:comp.infosystems.www.authoring.stylesheets
, michaelp <mi******@hio.noposted :
>
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.
Aug 12 '06 #10
On Fri, 11 Aug 2006 16:35:53 +0200, michaelp <mi******@hio.nowrote:
>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.
Aug 21 '06 #11


Christopher P. Winter wrote:
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
Aug 23 '06 #12
michaelp wrote:
I am teaching programming, and display code snippets with line numbers
for easy reference.
What's a "line number" ?

Is that like FORTRAN?

Aug 23 '06 #13
On Wed, 23 Aug 2006 01:55:16 GMT, Wes Groleau <gr**********@freeshell.org>
wrote:
>

Christopher P. Winter wrote:
>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.
Aug 24 '06 #14

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by Mario | last post: by
25 posts views Thread by Yves Glodt | last post: by
32 posts views Thread by Adrian Herscu | last post: by
8 posts views Thread by Bern McCarty | last post: by
14 posts views Thread by Patrick Kowalzick | last post: by
399 posts views Thread by =?UTF-8?B?Ik1hcnRpbiB2LiBMw7Z3aXMi?= | last post: by
12 posts views Thread by puzzlecracker | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by suresh191 | last post: by
1 post views Thread by Marylou17 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.