Page MenuHomePhabricator

Enable line numbers for pages handled by SyntaxHighlight
Closed, ResolvedPublic

Description

T30626 gave us a nice javascript validator. And it's throwing errors to the console and even knows the line number within the wiki script. All awesome, but.. It's another thing to actually get those line numbers.

I'm suggesting that on pages that are "isCssOrJsPage" or "isCssJsSubpage" (according to their respective methods in the Title-object), improved by showing line numbers at the beginning.

We already give them special treatment by wrapping the page in <pre> and not parsing the text. This would be a good next step, especially now that we have wgResourceLoaderValidateJS which provides line numbers.


Version: unspecified
Severity: enhancement

Event Timeline

bzimport raised the priority of this task from to Medium.Nov 21 2014, 11:47 PM
bzimport added a project: SyntaxHighlight.
bzimport set Reference to bz30773.
bzimport added a subscriber: Unknown Object (MLST).

Reminder: Make sure extensions like SyntaxHighlight_GeSHi don't throw up.

Hack, might as well do it all cool and make it part of SyntaxHighlight_GeSHi.

Renaming bug: Add line numbers for syntaxhighlight'ed pages and sections of pages

GeSHi supports line numbers, however it gets messy with autogenerated styles. Wait for a solution with a unified stylesheet.

Change 220994 had a related patch set uploaded (by TheDJ):
Add line numbers to CSS and JS content pages

https://gerrit.wikimedia.org/r/220994

Krinkle renamed this task from Add line numbers for syntaxhighlight'ed pages and sections of pages to Enable line numbers for pages handled by SyntaxHighlight.Jun 25 2015, 10:38 PM
Krinkle moved this task from Backlog to Accepted on the SyntaxHighlight board.
Krinkle set Security to None.
Krinkle removed a subscriber: wikibugs-l-list.

excluding the numbers is easy enough with user-select:none.

Styling however is a challenge. The following screenshot is with:

.mw-highlight .lineno {
        user-select: none;
        background-color: lightgray;
        margin-right: 0.5em;
        margin-left: -1em;
        border-right: 1px solid gray;
        display: inline-block;
}


Colors could use some work. Particularly problematic is the space char after the line number, which forces too much whitespace before the border in my opinion. And wrapped lines break the line number sidebar, but there is little we can do to avoid that I think.

Right, so user-selection:none doesn't really work here:

Apparently we need to be concerned about websites setting this on ALL their content and being pricks, as well as spoof sites, asking you to copy something and then getting a total different paste result then users would expect. So it only works if the text is the only element being copied, or if it is on the 'edge' of your selection or something....

Conclusion, we would need a total different way to generate line numbers to address Krinkle's concerns.

Change 220994 abandoned by TheDJ:
Add line numbers to CSS and JS content pages

Reason:
Don't see a way to easily do this with the current method of line numbering of pygments.

https://gerrit.wikimedia.org/r/220994

Change 652562 had a related patch set uploaded (by Esanders; owner: Esanders):
[mediawiki/extensions/SyntaxHighlight_GeSHi@master] Display line numbers as generated CSS content

https://gerrit.wikimedia.org/r/652562

Change 652563 had a related patch set uploaded (by Esanders; owner: Esanders):
[mediawiki/extensions/SyntaxHighlight_GeSHi@master] Enable line numbers on code content pages

https://gerrit.wikimedia.org/r/652563

And wrapped lines break the line number sidebar, but there is little we can do to avoid that I think.

We can absolutely position the line numbers, then pad the remaining content. (Using a sensible width, this will work fine for line numbers up to 9999)

Conclusion, we would need a total different way to generate line numbers to address Krinkle's concerns.

Generated content pseudo-elements are un-copyable in all browsers.

Example of all of the above and various other fixes: https://patchdemo.wmflabs.org/wikis/6fee4f0fd503f0bb10909c006aecf62a/w/index.php/MediaWiki:En.js

Change 652562 merged by jenkins-bot:
[mediawiki/extensions/SyntaxHighlight_GeSHi@master] Display line numbers as generated CSS content

https://gerrit.wikimedia.org/r/652562

Change 652563 merged by jenkins-bot:
[mediawiki/extensions/SyntaxHighlight_GeSHi@master] Enable line numbers on code content pages

https://gerrit.wikimedia.org/r/652563

Useful addition, though, may I suggest making these numbers lighter? They add a lot of visual distraction, yet they are needed only in a few situations.

Current color is #333 (nearly black), personally I'm going to tweak them to something a bit extreme, like #CCC (just barely readable on the grey background).

I set them to the same colour as they are in the editor. They could probably be a bit lighter but we will need to maintain an accessible contrast and consistency between interfaces.