Copying from Code Block Inserts Extraneous EOL Characters

Issue #63 new
Mark Symons created an issue

When using the syntax highlighter plugin to render code, I have found that if I copy XML code directly from JIRA, then when I paste it elsewhere, then it has picked up extra EOL characters. (I have not tested with anything but XML).

See screenshot. Note that this is copying when viewing the issue… if I EDIT the field and copy from that then there’s no problem... but not everyone has edit permissions, and the edit might accidentally get "saved", resulting in possible unintended changes to the field contents - plus unwanted notifications.

Aside: If I am pasting the copied XML into SoapUI then I can use Alt-F (format XML) in order to tidy things up… but often the pasting is into an email, a text file, etc.

Extra-EOL-2.png

Comments (43)

  1. arm atlassian

    Hi

    Looks like we are seeing the same.

    Could you please let us know if there are any plans to fix this?

    Regards, Areg

  2. Holger Schimanski repo owner

    I can reproduce the problem and would like to fix this issue. But sorry, I don't have any idea, where this is coming from. It looks like this is not coming from bad HTML code generated by the plugin. I have remove all (!) linefeeds in HTML code. No effect... Maybe it has something to do with \r\n handled as duplicate linefeeds? Or is it because I have <td> and <pre> in each line, which are two block elements with two linefeeds?

    Any HTML or CSS specialist in your environment who can have a look at this problem?

    Best regards, Holger

  3. Mark Symons reporter

    Based on observing that when the macro is configured for "collapse" then you provide a nice little "show all" link, would it be possible to have a link for "copy all"?

    That might help you control what is actually copied.

    If nothing else, it might address the separate problem that exists currently... how to copy code and NOT also copy the line numbering provided by the macro (when the macro uses "linenumbers").

  4. Brian Johnson

    A previous version of the plugin didn't have this issue. Is the wrapping of each line in a distinct PRE tag new?

  5. Sergei Golubchik

    This is because of PRE. One way to fix it is to remove PRE tags and merge their style with the parent TD style (and add white-space:pre). Like this: Was:

    <td style=" line-height: 1.4em !important; padding: 0em; vertical-align: top;">
      <pre style="font-size: 1em; margin: 0 10px;  margin-top: 10px;   width: auto; padding: 0;"><span style="color: black; font-family: 'Consolas', 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace !important;">commit 4d0e52189ca945c94146035c2733d85c9c6fd18d</span></pre>
    </td>
    

    Now:

    <td style=" line-height: 1.4em !important; padding: 0em; vertical-align: top; white-space: pre; font-size: 1em; margin: 0 10px;  margin-top: 10px;   width: auto; padding: 0;"><span style="color: black; font-family: 'Consolas', 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace !important;">commit 4d0e52189ca945c94146035c2733d85c9c6fd18d</span></td>
    
  6. Holger Schimanski repo owner

    Thank you very much for the tip! I need to check, if this works also in email layout of Outlook etc.

  7. Holger Schimanski repo owner

    Great! That is really how open source works. Many thanks for your contribution!

    While testing layout for different browsers is easy these days, but it is very hard for emails send out by JIRA.

    Would it be possible, that you do some testing of layout in Outlook (whatever version) for emails sent out by JIRA on issue create of issue comment?

  8. Mark Symons reporter

    I can do some testing if there is a new version of the plugin. Currently using v2.2.0,

    I have Outlook client in the office (which has built-in rendering which I guess is based on IE) and I can also use Office365 over the internet and use Chrome or Firefox.

  9. Holger Schimanski repo owner

    Sorry guys, that pull request is incomplete. <pre> in line numbers are still there and therefor no proper layout with line numbers. Also padding layout is not as before.

    Bildschirmfoto 2016-03-09 um 21.02.55.png

  10. Sergei Golubchik

    Yes, I didn't remove PRE from line numbers, because one cannot correctly copy a code snippet with line numbers anyway. So I thought that PRE doesn't matter. But it adds extra padding, I should've thought of that. Sorry for this.

    As a fix you can add a bit of padding to TD elements or remove PRE from line numbers. I don't want to risk another pull request, I think it'll be less work for you just to fix padding instead of merging a pull request.

    But if you want a pull request that fixes it — of course, just tell me.

  11. Mark Symons reporter

    After updating to v2.2.1 plugin, the rendering in JIRA itself seemed great. Testing with Firefox v45.0, I was able to copy and paste and have no extraneous EOL.

    Emails seem problematic... see screenshot. This was in Microsoft Outlook

    syntax-highlighter-221-outlook_email.png

    The obfuscation edits that I did to the screenshot are rather messy - but you can clearly see that there are huge vertical gaps.. about 7 lines each

  12. Holger Schimanski repo owner

    Creating CSS style for emails is really tricky because of limited CSS features implemented by Outlook. * What version of Outlook did you test with? * How about Outlook 365? * Can you identify if it is a problem with extra lines or padding / lineheight or the code?

  13. Holger Schimanski repo owner

    Not sure what to do with layout problems in Outlook. Do you see ideas, where this is extra gaps are coming from CSS?

  14. Sergei Golubchik

    Unfortunately, I don't use Outlook (I'm on Linux) so I cannot really test it. I don't even know anyone who does.

  15. Holger Schimanski repo owner

    I cannot release because this change fixing additional linefeeds with the current CSS approach breaks layout in emails sent by JIRA.

  16. Sergei Golubchik

    Okay, thanks. I'll see if I can do anything about this layout break. It's only Outlook issue that stops the release right? Or is there anything else?

  17. jbick

    So..

    1. It seems white-space: pre; forces Outlook (2010 here) to add line breaks. Remove it.
    2. The font-family needs to be 'Consolas', 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace; (without !important).
    3. Leading white-spaces are missing then. To add them use &nbsp; (inside of a span with the given font-family).

    It's dirty but it works: sh.jpg I did not change the plugins code. I played with the html produced by it and used the send test email function to test it.

  18. Holger Schimanski repo owner

    Great! Thank you very much for looking at it. Did you use 2.2.1 (attached to this issue) or 2.2.0 as base for your modification?

  19. Holger Schimanski repo owner

    Style white-space: pre is used so that sequences of whitespace will not collapse into a single whitespace. http://www.w3schools.com/cssref/pr_text_white-space.asp (I think that is what you mean with 3. that you need to replace any whitespace char by a nbsp?)

    Can you double check white-space influence?

    And would white-space: pre-wrap help instead of removing white-space: pre?

  20. jbick

    I'm sure about the influence of white-space: pre;. Removing it has definitely fixed the issue with extra lines (but it created the problem with indentation etc. - no need to replace all whitespaces, only multiple whitespaces collapse). I'll validate it again tomorrow and I'll change it to white-space: pre-wrap;.

  21. jbick

    white-space: pre-wrap; without &nbsp;s: no indentation.

    pre-wrap.JPG

    white-space: pre; without &nbsp;s: indentation exactly as much as in the source code (original problem, source code see below). No idea where the line breaks come from.

    pre.JPG

    This is a block for a single code line:

                                                            <tr id="syntaxplugin_code_and_gutter"> 
                                                                <td style=" line-height: 1.4em !important; padding: 8px 0px; vertical-align: top;  white-space: pre-wrap;  font-size: 1em; margin: 0 10px;  padding-top: 0px;   padding-bottom: 0px;  padding-left: 10px; padding-right: 10px;; padding: 0px; border-collapse: collapse">
                                                                    <span style="color: black; font-family: 'Consolas', 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace;">{</span>
                                                                </td> 
                                                            </tr> 
    

    And this is the corresponding line in the mail: (same amount of spaces left of <span> (as expected because of the white space handling))

                                                                    {
    

    I should add that we use JIRA 6.4.13.

  22. Holger Schimanski repo owner

    Maybe it has something to do with line-height: 1.4em !important; I once read somewhere, that Outlook sometimes creates extra space because it set its Word-typical heigh which has something to do with page layout (Outlook uses the Word HTML Rendering Engine).

    Instead for line-height maybe we can use 20px instead of 1.4em or completely remove it? Can you play around with it? I don't have Outlook (Windows) in my personal environment, that's why it is extra tricky for me to check.

  23. jbick

    Hi Holger,

    the extra space is extra lines as you can see in this screenshot:

    line-height.png

    I've found white-space: pre; to be the origin of this because I've removed every single CSS attribute from the code one by one until it worked.

    Please note the indentation in the HTML that I've sent earlier. There are 56 spaces in front of the <tr> tag and even more in front of its children. Therefore you can't achive correct indentation only with the CSS attributes of <td> (as long as this source code indentation stays the same).

    What's wrong with replacing <space><space> with &nbsp;&nbsp; as a workaround?

  24. Holger Schimanski repo owner

    I would like to stick with white-space: pre, because otherwise it is not only about <space> to   but also about tabs to convert.

    I have played arround with CSS styling moving white-space: pre from <td> one level down to <span> and then invested 5 $ for using HTML email preview capabilities of Campaing Monitor. The results http://holgerschimanski.createsend.com/screens/t/43C38F1A26653DB8 look promissing (don't be confused by the title of the webpage; I just forgot to change the version name before running the test).

    So, I have created a new beta release 2.3.0-b1 and attached it to this issue. Could you @jbick, @vuvova, @msymons pick it up and test it in your environment? You testing would be much appriciated!

  25. jbick

    Hi @hski,

    unfortunately indentation does not work in my version of Outlook.

    Firefox (4 / 8 spaces):

    indentation-ff.JPG

    Outlook (1 / 1 space):

    indentation-outlook.JPG

    In the source code it shows only one space in a tag left of the returns.

    The line is:

                                                                    <span style="color: black; white-space: pre; font-family: 'Consolas', 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace;"> </span><span style="color: #006699; font-weight: bold; white-space: pre; font-family: 'Consolas', 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace;">return</span><span style="color: black; white-space: pre; font-family: 'Consolas', 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace;"> foo;</span>
    

    The line should be:

                                                                    <span style="color: black; white-space: pre; font-family: 'Consolas', 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace;">    </span><span style="color: #006699; font-weight: bold; white-space: pre; font-family: 'Consolas', 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace;">return</span><span style="color: black; white-space: pre; font-family: 'Consolas', 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace;"> foo;</span>
    
  26. Holger Schimanski repo owner

    Thank you very much for testing! At least no extra lines are introduced by Outlook anymore. But looks like Outlook merges multiple space into one even with white-space:pre. (The Plugin renders content for email and browser in the same way. If something is shown differently, then this is because of differences in rendering engines of various versions of email and webbrowsers.) What version of Outlook are you using? Can you check behaviour when using tabs in getFoo()?

  27. Rudy Holtkamp

    Hi, we also saw this issue when copying text which was between {noformat} tags from a Firefox browser to a text editor. Note that with Chrome the issue has not been seen.

  28. jbick

    Hi Holger, we're using Outlook 2010. It does not merge spaces for every mail. I double checked by using the "send a test email" function of JIRA that I mentioned before (/secure/admin/OutgoingMailServers.jspa) with a corrected source code (see last comment). Spaces are not merged. Therefore there must be a difference either in the way the plugin produces HTML or how JIRA processes mails (notifications vs. test mail - function) as Outlook is capable of displaying multiple spaces.

  29. Log in to comment