7

I was trying to put a small line of code in a comment, but I noticed that the multiple spaces in the comment enclosed in backticks(`) were replaced with single ones.

To make it clear, I wrote this as raw data in the comment:

replace("       ", " ")

Note: ^ This is code indented with four spaces


And when I added the comment, it was appearing as this:

Enter image description here

The Formatting Page says:

_italic_ and **bold** text,
inline `code in backticks`,
and [basic links](http://example.com).

But when the multiple spaces are replaced with single ones, then perhaps, it won't help for code.

  • Due to the white-space: normal; CSS applied to .comment-text code tags. Without it, displays fine (inspecting the HTML shows that spaces are there, just not shown. – muru Aug 26 '19 at 8:21
2

Comments have a different markdown from answers, which serves to make things more difficult to learn and remember. If you want to show multiple spaces it can be difficult for the reader to count them, because they are different widths when different fonts are used.

One solution is to replace multiple spaces with the blank (␣ or ␣) character.

When writing an answer where backticks are not used the same result occurs as when writing a comment with backticks, that is inconsistent.

replace(" ", " ")    - That was written as: replace(" ", " ")

When backticks are used in answers we get what we would hope to see in comments, when the backticks are not used multiple spaces are rendered as one, either way it's difficult to count the number of them.

replace(" ", " ")
replace(" ", " ")

Replacing the spaces (" " or  ) with blanks ("␣" or ␣) makes counting the number of them easy.

Example: replace("1234567", " ")

replace(" ", " ")
replace("␣␣␣␣␣␣␣", " ")

replace("       ", " ")    - Variable width fonts make those seven spaces unexpectedly narrow.
replace("␣␣␣␣␣␣␣", " ")

The solution to all difficulties, where you want to show an exact number of spaces and have the number understood, is to use a visible replacement; such as a blank.

You must log in to answer this question.

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