ChiliProject is not maintained anymore. Please be advised that there will be no more updates.

We do not recommend that you setup new ChiliProject instances and we urge all existing users to migrate their data to a maintained system, e.g. Redmine. We will provide a migration script later. In the meantime, you can use the instructions by Christian Daehn.

Don't select line numbers on code blocks (Bug #194)


Added by Felix Schäfer at 2011-02-14 08:47 am. Updated at 2011-06-06 08:58 am.


Status:Needs more information Start date:2011-02-14
Priority:Normal Due date:
Assignee:- % Done:

0%

Category:Wikis
Target version:-
Remote issue URL:http://www.redmine.org/issues/3382 Affected version:

Description

Currently, the line numbers in the <code> blocks are selected with the text in the block when usually the only thing you want is the text. The line numbers should be reworked so that they don't get selected with the rest of the text.


Screenshot.png - Selectable code text without line numbers (27.5 kB) Eric Thomas, 2011-02-15 03:56 am

code_highlighter_in_preview.png (18.9 kB) Felix Schäfer, 2011-02-18 07:18 am


History

Updated by Holger Just at 2011-02-14 09:44 am

The current behavior comes directly from CodeRay iirc, so we would have to either change its behavior or write our own formatter / post filter.

The approach used by Pygments is to have a table with two columns and one row. Both columns contain <pre>-tags, such that no unintentional line break can occur. the left column then holds the line numbers, one per line, the right column contains the actual source code.

When you now select text, only the code is selected since you never leave the table cell containing the code. The downside is that you can't get the interleaved line-numbers.,

Alternatively, we could implement the model used by GitHub. They use one table row per line of source code. This would give us more flexibility but would probably be a bit harder to implement. Currently, I don't know if they use javascript magic to prevent the selection of full lines or if this is default behavior.

Updated by Eric Thomas at 2011-02-14 11:07 am

There is a related issue at http://www.redmine.org/issues/3382 and a somewhat working patch that probably needs some tweaking to have a smooth merge.

Updated by Holger Just at 2011-02-14 11:15 am

Thanks Eric. Your last screenshot looks really promising. Would you care to update your patch to the Chili master and/or summarize the current issues it has so that we could incorporate it/work on it.

  • (deleted custom field) set to http://www.redmine.org/issues/3382

Updated by Felix Schäfer at 2011-02-14 12:35 pm

Holger Just wrote:

The current behavior comes directly from CodeRay iirc

I know, and I had somewhere in the back of my mind that it had already been discussed on redmine.org and that there was a possible solution with CodeRay, I didn't have a good enough connection to dig them out though :-)

Updated by Eric Thomas at 2011-02-15 03:56 am

Pull request here: https://github.com/chiliproject/chiliproject/pull/8

I was having a little bit of trouble making it work with a minimal amount of CSS changes.
The biggest problem with this is that it has to override so many higher up classes so there's a lot of padding: 0; margin: 0, etc..

Screenshot attached that shows text wrapped in a pre tag and code wrapped in pre/code tags.

  • File Screenshot.png added
  • Status changed from Open to Ready for review

Updated by Felix Schäfer at 2011-02-15 01:52 pm

Eric T: I patched my local instance with your pull request and noticed 2 things:

  • There's an unmatched < /code > (spaces added for it to show) after the table,
  • when previewing stuff with code in it, the part with the line numbers expands horizontally to fill what I think the browser assumes is the max width of a page or something like that.

All that tested on an uptodate Safari/OS X.

Updated by Eric Thomas at 2011-02-17 04:38 pm

Felix,

Thank you for taking the time to review it. I see what you are saying about the first point and I've got a pretty good idea on how to fix that.
Could you post a screenshot for the the second point? I'm not sure if I'm following quite what you are saying.

Updated by Felix Schäfer at 2011-02-17 04:43 pm

Eric Thomas wrote:

Could you post a screenshot for the the second point? I'm not sure if I'm following quite what you are saying.

I'm not sure I have that branch still around. Could you just try to put code on a wiki page or an issue and preview it instead of saving it? Maybe with a webkit browser if you have one. The error is pretty obvious, if you don't see if by just doing that, I'll post a pagegrab :-)

Updated by Eric Thomas at 2011-02-17 04:49 pm

I tried doing a preview on my browser (Firefox 3 on Fedora) and wasn't getting any issues. If webkit is Apple specific, then I don't have one. A screenshot would be helpful.

Updated by Felix Schäfer at 2011-02-17 04:55 pm

Eric Thomas wrote:

If webkit is Apple specific, then I don't have one.

Nope, Chrome is webkit too, and different KDE and Gnome browsers as well. If this is brittle to the point of browser specific problems, I'd like to have it tried on Firefox 3, IE8 or earlier, Safari, Chrome and Opera. I can test on Safari, and I think we have IE and Opera somewhere here in the office, could you test Chrome in addition to Firefox?

A screenshot would be helpful.

I'll post one later.

Updated by Felix Schäfer at 2011-02-18 07:18 am

This is what it looks like in Safari when trying to preview a new issue with a code block:

The problem doesn't appear once it's saved.

  • File code_highlighter_in_preview.png added
  • Status changed from Ready for review to Needs more information

Updated by Felix Schäfer at 2011-02-18 07:19 am

(Notice the scroll bar at the bottom, that should give you an indication of how large this blue part is…)

Updated by Felix Schäfer at 2011-02-18 09:41 am

Felix Schäfer wrote:

This is what it looks like in Safari when trying to preview a new issue with a code block:

This happens on Chrome/Linux too, so I guess it's a webkit thing you could test with either Chrome or whatever webkit browser on Linux.

Updated by Eric Thomas at 2011-02-19 04:50 pm

Felix,

Thanks for your feedback. I could not get this to work since having a <table> inside a < code > block seemed to always screw things up. So my approach was to replace < code > with <div>, see here. However, little did I realize that I only had access to the first < code > tag, but not the closing one, so that's why the <div> was not closed.

I have a fixed version that works in redcloth 4 (see #210),but the monkey patching involved is completely different, so I'd rather wait to see if ChiliProject can get upgraded.

Updated by Felix Schäfer at 2011-02-20 05:22 pm

Eric Thomas wrote:

I have a fixed version that works in redcloth 4 (see #210),but the monkey patching involved is completely different, so I'd rather wait to see if ChiliProject can get upgraded.

I don't think it will be before 2.0.0. Anyway, IIRC CodeRay 1.0 should make that particular point easier too, unless anyone needs this quickly, I'd prioritize it to low for 2.0.0.

Updated by Ian Freeman at 2011-02-21 10:25 pm

It is a not-so-trivial annoyance for me personally, plus I just don't understand why coderay would have designed inline line numbers to begin with.

Updated by Ian Freeman at 2011-02-26 10:58 am

Eric,

I've installed your four changes from your pull request, and I'm noticing extra linebreaks before and after the text in the code blocks, but only when the language is not set.

But, I'm not seeing any problems with the WebKit browser I happened to have installed on my system (Epiphany 2.30.2).

Also, when no language is specified no line numbers are displayed. Is this behavior intended? I think this should at least be user-specified.

Updated by Eric Thomas at 2011-02-26 05:38 pm

Ian, thanks for testing the patch. Since this patch would be rewritten by #210, this should be put off until 2.0.0.

Updated by Kornelius Kalnbach at 2011-06-05 03:46 pm

Sorry, I didn't read the discussion. Did you consider using user-select? I use it in CodeRay 1.0.

Updated by Felix Schäfer at 2011-06-06 08:58 am

Kornelius Kalnbach wrote:

Sorry, I didn't read the discussion. Did you consider using user-select? I use it in CodeRay 1.0.

Well, if CodeRay 1.0 provides everything needed for it, we won't need to do it ourselves ;-) Is 1.0 "near enough" that we can wait for it, or should we implement it ourselves until 1.0 is ready?

Also available in: Atom PDF