3

It happened to me recently that I needed to ask a question that included a long string of characters such as the following one: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.

Now as you can see, there was an automatic line break between the colon and the string itself (I only typed in a regular space). Also note that in the middle of the string is yet another automatic line break, and that this one will adapt to the zoom factor of your monitor to make the display nice and fluid. Call this a "clever break".

Why start a new line if you can make a clever break as soon as you need to? In the example above, the string would be cut into two pieces with or without the line break, and the reading would be more fluid without, especially in the case where there is no grammatical reason to make a break there...

I get it that some people may find it convenient to emphasize such an unusual string, but what I'm asking is how to prevent it.

In my question I had to insert a space in the middle of the string to prevent the line break, but then the string cut doesn't adapt to your monitor, what I get is an "unclever" break.


EDIT (trying @rene's first idea which was now deleted)

It happened to me recently that I needed to ask a question that included a long string of characters such as the following one:

aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.

This is not what I want:

  • The string is severely emphasized
  • You lose the clever break in the middle of the string.

I want to emphasize the string as little as possible. I want it to be treated like a normal word, starting after the previous word and ending before the next one, with as many clever breaks as necessary.


EDIT #2 (trying another idea from @user36296)

It happened to me recently that I needed to ask a question that included a long string of characters such as the following one: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa. Trying now to include more words to see how the string behaves in a longer paragraph. It seems to me that it does quite ok!

Awesome. This does the job. It's a little bit cumbersome, but I'll take it.

  • @rene I've tried your idea, but it's not what I want. I've tried to make it clearer, see edit. – Arnaud Mortier Aug 22 at 11:53
  • 1
    You could replace all the spaces where you don't want possible linebreaks with  , however this will probably result in even worse line breaks for people who use the responsive design. – samcarter Aug 22 at 12:08
  • @user36296 Thanks! It does work, although I got an awkwardly split word in the edit form, that I tried to fix with an mbox - not only the mbox isn't resolved, but the split word isn't split any more after the edit. Weird. – Arnaud Mortier Aug 22 at 12:47
  • @user36296 I can confirm that this doesn't cause a worse result using responsive mode. – Luuklag Aug 22 at 14:14
  • good question and great answer but i think this question should stay in stackoverflow.com – simon Aug 22 at 15:03
  • Deleted answer by Rene? Resubmitted? – Peter Mortensen Aug 22 at 21:23
  • @PeterMortensen It was a comment. – Arnaud Mortier Aug 22 at 22:24
4

You can currently only achieve that by adding an Zero-width space ​ after each char of the string of chars that doesn't have any whitespace character.

To achieve this result:

It happened to me recently that I needed to ask a question that included a long string of characters such as the following one: a​a​a​a​a​a​a​a​a​a​a​a​a​a​a​a​a​a​a​a​a​a​a​a​a​a​a​a​a​a​a​a​a​a​a​a​a​a​a​a​a​a​a​a​a​a​a​a​a​a​a​a​a​a​a​a​a​a​a​a​a​a​a​a​a​a​a​a​a​a​a​a​a​a​a​a​a​a​a​a​a​a​a​a​a​a​a​a​a​a​a​a​a​.

You need to put this in the markdown:

It happened to me recently that I needed to ask a question that included a long string of characters such as the following one: a​a​a​a​a​a​a​a​a​a​a​a​a​a​a​a​a​a​a​a​a​a​a​a​a​a​a​a​a​a​a​a​a​a​a​a​a​a​a​a​a​a​a​a​a​a​a​a​a​a​a​a​a​a​a​a​a​a​a​a​a​a​a​a​a​a​a​a​a​a​a​a​a​a​a​a​a​a​a​a​a​a​a​a​a​a​a​a​a​a​a​a​a​.

But that does have all kind of side-effects, for example on copying that string from the post. The zero-width stuff is copied along.

Ideally this could be fixed if a CSS rule word-break: break-all; was added but before that is done it would need proper evaluation if that doesn't break lots of other things:

.all {
    word-break: break-all;
}

.word
{
    word-wrap: break-word;
}
<p>with a word-break:break-all<p>
<p class="all">
It happened to me recently that I needed to ask a question that included a long string of characters such as the following one: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.
</p>

<p>with a word-wrap:break-word<p>
<p class="word">
It happened to me recently that I needed to ask a question that included a long string of characters such as the following one: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.
</p>

  • That's doing the job as far as the display is concerned. Thanks. Indeed, it would be better if the string could be copy-pasted without side-effects, which I believe is the case when you use @user36296's idea (I'm currently editing the question to include a sample of what he said). – Arnaud Mortier Aug 22 at 12:38
  • 1
    @ArnaudMortier adding &nbsp; only moves your problem along that paragraph. It is not going to fly. I already tried that. – rene Aug 22 at 12:45
  • I noticed this as I was making the edit, now I could get around it by adding &nbsp; instead of every space preceding the string in the paragraph. It is definitely cumbersome but it works (without copy-pasting issues). If my understanding is correct, your solution could be implemented in the design of SE, so that would make it a better one. Someone who really wants a line break can easily include one, you do this every day without thinking. – Arnaud Mortier Aug 22 at 15:12
1

In normal context, the style that will do what you want is:

… a long string of characters such as the following one:
<span style="word-break: break-all">aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa</span>.

How to get that style to have effect in a markdown context is a different problem.

1

One hack that might work in certain situations is to replace the space with &nbsp; to prevent a line break

It happened to me recently that I needed to ask a question that included a long string of characters such as the following one: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.

(No guarantee that this will not cause undesirable linebreaks somewhere else, as shown in the example above)

  • I noticed this effect in my edit of the question following your comment, and could get around it by adding &nbsp; instead of every space preceding the string in the paragraph. It is definitely cumbersome but it works (without copy-pasting issues). Thanks! – Arnaud Mortier Aug 22 at 15:13
  • @ArnaudMortier That's not really a good idea, this might result in line breaks within words – samcarter Aug 22 at 15:16
  • It actually did happen in the question form that a word got split awkwardly, but it wasn't anymore after the edit was committed. In any case, I think that you could get around that using \mbox. – Arnaud Mortier Aug 22 at 15:19

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .