Line numbers - philosophy

773 views
Skip to first unread message

John Norman

unread,
Aug 30, 2014, 5:31:44 PM8/30/14
to highl...@googlegroups.com
I notice that the discussion of the lack of line numbers support suggests one might discuss it here.

The doc says: "The only real use-case that ever was brought up in support of line numbers is referencing code from the descriptive text around it. On my own blog I was always solving this either with comments within the code itself or by breaking the larger snippets into smaller ones and describing each small part separately."

Well, I do have another use case:

Lecturing with slides (e.g., in reveal.js).

In that situation, one gets live comments, and it is very helpful to be able to situate the student with a suggestion with one's voice along the lines of: "Well, take a look at line 5."

We all know that code can be hard to read -- indeed, presuppositions about what makes code hard to read for all readers is probably not going to get one very far.

So one typically doesn't know in advance which line is being asked about, or which one needs discussion, given the back-and-forth of the classroom.

Ivan Sagalaev

unread,
Sep 8, 2014, 6:51:33 PM9/8/14
to highl...@googlegroups.com
Hello John,

Sorry for the delay, I was on vacation :-)

> Well, I do have another use case:
>
> Lecturing with slides (e.g., in reveal.js).

This is a fair point. It is also the case where my usual suggestion of
adding line numbers with additional scripting is not very practical as
the author of a presentation is not necessarily a JavaScript coder. Nor
is it any more practical to persuade all presentation tools to include
such scripting.

The problem is however with the (perceived) downside of having line
numbers in the script leading to people using it everywhere even when
it's not needed. I'll try to re-evaluate my views on that. It may be
that just not having the feature on by default may remove the problem as
people rarely fiddle with settings anyway. I'll take some (not very
long) time to ponder on that.

Another question is implementation. I don't like the one with which I
came up myself that wraps individual lines in `<span class="line">`,
there are a couple of problems with it. Will you be up to discuss and
implement line numbers if we ultimately decide to go with it?

John Norman

unread,
Sep 8, 2014, 7:39:22 PM9/8/14
to highl...@googlegroups.com
Sure -- Definitely available to discuss; I can offer a set of eyes for the implementation, but I shouldn't be the primary implementor.

John




--
You received this message because you are subscribed to a topic in the Google Groups "highlight.js" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/highlightjs/UVJaQcQNC1c/unsubscribe.
To unsubscribe from this group and all its topics, send an email to highlightjs+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

gitarman69

unread,
Dec 8, 2014, 6:40:26 PM12/8/14
to highl...@googlegroups.com
Hello John and Ivan,

Why don't you simply put all lines in LI elements. Although there will be people disapproving due to their specific taste for semantic HTML but it makes perfect sense to me: A piece of code is a 'listing'. This way you can use CSS to style the line numbers and set the initial number for the first line. Copying and pasting highlighted code into an text editor will still work without line numbers added to the pasted code.

This might or might not be added to highlightjs. One can easily do this after highlighting as well. Perhaps it is an idea to add an event 'afterhighlight' so anyone is able to do their own post processing if they wish.

Ravi Hasija

unread,
Dec 17, 2014, 1:55:31 AM12/17/14
to highl...@googlegroups.com
+1 on line numbers. Very essential!

Ivan Sagalaev

unread,
Dec 22, 2014, 7:50:25 PM12/22/14
to highl...@googlegroups.com
Hello,

> Why don't you simply put all lines in LI elements.

The problem is that an author may not have this control over the source
code. Think of a presentation tool that uses markdown or any other
wiki-like syntax.

This is one valid use-case for adding line numbers generation into the
library. It is now a matter of finding someone to champion a decent
implementation.

John Norman

unread,
Dec 22, 2014, 7:54:31 PM12/22/14
to highl...@googlegroups.com
I agree with Ivan about the lack of code control. Right now I'm just too swamped to come up with a good impl but I'm thinking about it . . .

Ali Dbg

unread,
Jan 22, 2015, 7:42:06 AM1/22/15
to highl...@googlegroups.com

Евгений Пакало

unread,
Apr 19, 2015, 1:50:38 PM4/19/15
to highl...@googlegroups.com

Tobias Beer

unread,
Sep 15, 2015, 5:22:40 AM9/15/15
to highlight.js
Especially for referring to an example from outside the page where higlight.js is being used, line numbers are essential.

— tb

Tommy Hodgins

unread,
Nov 3, 2015, 1:41:37 PM11/3/15
to highlight.js
I have another use-case for it, though after reading the author's reason for excluding line numbers I'm okay with his decision, I would like to offer another perspective to the discussion!

One of the tools I lack on mobile is a good 'View Source' for mobile web browsers, so I wrote a teeny tiny PHP proxy that I can use to display the source of a website, and I can also use this with a bookmarklet. https://github.com/tomhodgins/sourceror

I was going to have a solarized theme no matter what, but I decided to use Highlight.js to add syntax highlighting for HTML, CSS, EQCSS, and JavaScript files. Now I have the problem that this tool is too useful, and I end up using it to read source all the time. I use Highlight.js to read syntax-highlighted code with pretty fonts in-browser instead of reading them in an editor, so my use-case is being able to refer to a line number, or compare line numbers between two different files.

Just my 2¢, love the plugin and how easy it is to use :)
Tommy Hodgins
Reply all
Reply to author
Forward
0 new messages