When I try to use
`hi another text`
it returns me hi another text
- spaces are breaked.
The fact that non-breaking spaces render in html as separate characters rather than a single character is a side-effect of what
is really about: line breaks. The non-breaking space is considered significant white space (as opposed to normal insignificant whitespace) for the purpose of preventing text from wrapping to a new line at that location. It has nothing to do with showing wider gaps/multiple spaces between words, and the fact that it often does so is a mere accident or side effect of the significant whitespace designation.
Once you realize this, rendering spaces from inline code blocks using
makes absolutely no sense. It might be a good idea to do something else to make this white-space significant rather than insignificant, but a non-breaking space is not the way to go.
A better option would be to use U+2002 (en space) or U+2003 (em space):  
or  
(or  
/  
).
Like most things that aren't needed often enough to be in the Markdown syntax, you can achieve this using HTML.
<code>hi another text</code>.
The result is hi another text
.
You can also use the unicode non-breaking space character U+00A0
inside backticks. You can copy them from the character map (or from this post).
`hi another text`
^^^^^
non-breaking spaces
The result is hi another text
.
You don't actually want non-breaking spaces; the results aren't pretty (this styling is meant to allow inline code, which depending on its position in the text may well need to be broken across multiple lines - spaces are a pretty good place to do this). You simply want the spaces to be preserved in the output, which the Markdown renderer does, but your browser does not. Adding the style,
white-space: pre-wrap;
...to the code
tag would correct this. As hammar notes, you can work around the current lack of such styling by manually inserting
into a <code>
span... However, to avoid ugly breaking, I suggest altering spaces and non-breaking spaces:
<code>hi another text</code>
You can see the difference here: after some text to push the code toward the end of the line hi another text
. Vs. some other text to put the code with alternate non-breaking spaces hi another text
(note the wasted space at the end of the first line as the entire line of code was wrapped).
pre-wrap
is used on the mobile sites, to allow for wrapping the <pre>
blocks. Anyone who doesn't know it: click the mobile link in the footer to see how that wrapping works, while still preserving the whitespace.
​
) in instead. Then, you'll always see the exact number of spaces that you want, even when the line breaks in the middle of them.
Another solution is to type Alt + (Keypad 0 Keypad 1 Keypad 6 Keypad 0) which also allows you to write hi another text
.
{ }
button in the markdown editor. It preserves multiple spaces.<code>
tags (which are generated by the backticks), multiple spaces are collapsed into one by your browser.