Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

No line breaks in inline code

by Eily (Parson)
on Mar 24, 2017 at 14:32 UTC ( #1185783=monkdiscuss: print w/replies, xml ) Need Help??

While you can expect codeblocks to preserve the formatting of your code (unless you have codewrapping enabled, but additional line breaks are made explicit by adding a red '+' and not incrementing the line number), I just discovered that this is not the case with inlinecode. The browser can insert a line break wherever a space is present if the line is too long. Most of the time this is not a big issue since there's no difference between a space and a line break outside of string constructs, but I'd still like pieces of code that were meant to be a single line to be displayed on a single line (as a matter of fact, I discovered this on a regex with the /x modifier, so one of the cases where whitespace doesn't matter).

I added this line .inlinecode { white-space:nowrap; } in my CSS, so I don't have the problem anymore. But there might be other monks around who would like the oneliners to always be displayed on one line, and I think this change would make sense as default behaviour.

NB: if you want to try for yourself, here is a one liner that you can break into two lines by resizing your browser's window: perl -lne '(1x$_) !~ /^1?$|^(11+?)\1+$/ && print "$_ is prime"'

Replies are listed 'Best First'.
Re: No line breaks in inline code
by LanX (Bishop) on Mar 24, 2017 at 15:04 UTC
    I think that's one of the defining differences between inline code and multi line.

    IE inline is supposed to easily blend with free flowing text.

    If the author doesn't want automatic line breaks he should insert one by himself.

    IMHO Inserting a long line as inline code is rather bad style, don't you think so?

    Cheers Rolf
    (addicted to the Perl Programming Language and ☆☆☆☆ :)
    Je suis Charlie!

      Inserting a long line as inliner code is rather bad style, don't you think so?
      Yes, but the code doesn't have to be long to end up broken, it just has to be embeded in the text so that it doesn't fit entirely in the current line.

      If the author doesn't want automatic line breaks he should insert one by himself.
      That's a good point and it would work well for oneliners. But there might be cases where you want your code to be inlined, and it ends up being broken although it's very short. Like my @array;,next unless /regex/ or perl -ne. You could use non breakable spaces to prevent breaking, but that's very cumbersome.

      Edit: corrected typos

        The reader just needs to resize his browser.

        I agree that there are cases where a break is unfortunate, but I think the most common cases are well covered.

        Update: Or stated differently: IMHO changing the default will cause more problems and complaints.

        Cheers Rolf
        (addicted to the Perl Programming Language and ☆☆☆☆ :)
        Je suis Charlie!

      Inserting a long line as inline code is rather bad style, don't you think so?

      The inline code doesn't need to be long, it just has to go over the div width boundary, ie. straddle two display lines. The code itself might be only 2 short words.

        My point was that this "problem" mainly shows with long lines.

        > The code itself might be only 2 short words.

        My current mobile browser already breaks inside words.

        Cheers Rolf
        (addicted to the Perl Programming Language and ☆☆☆☆ :)
        Je suis Charlie!

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: monkdiscuss [id://1185783]
Approved by hippo
help
Chatterbox?
[< & >]: in democracies people get the politicians they deserve

How do I use this? | Other CB clients
Other Users?
Others contemplating the Monastery: (7)
As of 2017-12-15 18:45 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    What programming language do you hate the most?




















    Results (442 votes). Check out past polls.

    Notices?