Jump to content


Photo

phpBB Line Numbers (in code boxes)


  • Please log in to reply
9 replies to this topic

Poll: Do you want code boxes with line numbers? (11 member(s) have cast votes)

Do you want code boxes with line numbers?

  1. Yes. I want line numbers. (8 votes [72.73%])

    Percentage of vote: 72.73%

  2. No. I like the forum the way it is. (3 votes [27.27%])

    Percentage of vote: 27.27%

Vote Guests cannot vote

#1 Frankie

Frankie
  • Members
  • 2930 posts

Posted 10 October 2010 - 11:18 PM

A lot of times when posting/reading code in the various subforms I would like to be able to say something like:

Your problem is in line 27. Change the ... to ...
or...
I made changes to lines 11, 14 and 19.
or...
Change line 3 to the title of your window.
etc.

So my request is to change the forum code for code blocks to show a line number before each line.
An example would be cplusplus's forum.
http://www.cplusplus...beginner/29768/ (example thread with a code box)

#2 SKAN

SKAN
  • Administrators
  • 9062 posts

Posted 11 October 2010 - 08:42 AM

An example would be cplusplus's forum.
http://www.cplusplus...beginner/29768/

That example would not be much helpful, I guess.
Have you seen a BBCode v2 forum with same facility?

..and yes, I think it would be very helpful.

#3 Frankie

Frankie
  • Members
  • 2930 posts

Posted 11 October 2010 - 04:47 PM

I can't find any examples for phpBB2. If a phpBB3 code would work there is a request forum for mods here:
<!-- m -->http://www.phpbb.com...wforum.php?f=72<!-- m -->

phpBB2 seems not supported anymore. I doubt there is any chance we will upgrade to v3.

Can you link to the files that control the code boxes? I would like to have a look at them incase anything stands out.

#4 SKAN

SKAN
  • Administrators
  • 9062 posts

Posted 11 October 2010 - 05:32 PM

You may ask Titan ( polyethene ), I think he wrote the code for copy button.

#5 lexios

lexios
  • Guests

Posted 12 October 2010 - 05:47 AM

I've successfully used a JavaScript syntax-highlighter on this forum via GreaseMonkey in Firefox, though I chose to disable line numbers. Unfortunately, it tends to freeze up the browser temporarily when there are a few long scripts on a page.

#6 polyethene

polyethene

    Administrator

  • Administrators
  • 5473 posts

Posted 12 October 2010 - 06:30 AM

I don't browse the forums as much as I used to so I haven't made any attempts to modify the code. If you kindly ask lexios he may give you his instructions for enabling syntax highlighting and line numbering with GreaseMonkey.

If anyone decides to edit code.js as it is then I'll share an important observation. When designing the pastebin I noticed a challenge with line numbering.

In HTML there are three ways to display line numbers: ordered lists, a table with two columns or the CSS text-before property.

Ordered lists break copy and pasting, select the middle two lines from the following list in your browser:[*:3i4ny9pf]line 1[*:3i4ny9pf]line 2[*:3i4ny9pf]line 3[*:3i4ny9pf]line 4Paste it into Notepad or any text editor, you will see something like:
# line 2
# line 3
pastebin.com and other similar sites have this flaw.

The table trick does not break copying but you sacrifice text wrapping since every line has to be the same vertical height for the numbers on the left column to match the line of code on the right. This is the option I chose, but in some cases it results in ugly horizontal scrolling.

CSS has a text-before property which could work but is not supported by IE8 and below. 40-50% of users on my sites are still using a version of IE which is too significant to ignore.

#7 PhiLho

PhiLho
  • Fellows
  • 6850 posts

Posted 12 October 2010 - 09:07 AM

Greasemonkey won't help here, as only those with the script will see line numbers, while the motivation is to point to a given line.
And you are right with numbering: either it goes in the way of copy/paste, or in the way of formatting. And the functionality won't be used that often, I think.
A possible solution, though, could be to add a switch button: "Add line number" (becoming "Hide" when activated) - not displayed by default, can show them if somebody need to find a given line.

#8 MacroMan!

MacroMan!
  • Members
  • 604 posts

Posted 12 October 2010 - 09:53 AM

After some searching, the only viable solution I can find involves a forum upgrade to v3.

David

#9 Lexikos

Lexikos
  • Administrators
  • 8855 posts

Posted 12 October 2010 - 01:17 PM

# line 2
# line 3

I get that from Firefox, but not IE8 or Iron.

#10 Frankie

Frankie
  • Members
  • 2930 posts

Posted 12 October 2010 - 06:55 PM

I get that from Firefox, but not IE8 or Iron.

I don't get it in IE9 either. Maybe this would be the way to go; and if anyone using firefox wants to get the code they could use the copy button.