Leading spaces are removed from messages

Hello

It's not the first time this "feature" is annoying me on this forum. I try to write a text which contains a few consecutive spaces, and they are automatically removed

For example I try to write ___1 where _ are spaces, it shows 1.

And without the "inline code box", it's removing all but one space. For example I put 10 spaces between dots, it shows this :
. .

I tried using the non-breaking space characters but no luck.

Is there a workaround or could you disable this feature ?

There is a pretty good answer here:

https://stackoverflow.com/a/50014217/7059512

Here is a more detailed explanation of how whitespace is handled in HTML:

https://developer.mozilla.org/docs/Web/API/Document_Object_Model/Whitespace#html_largely_ignores_whitespace

So if you really need it, use the   HTML character entity:

foo      bar

Renders as:

foo      bar

But I think it would be good to examine exactly why you need this. There might be a much better way. I wrote a lot of content in Markdown over the course of a decade and I can't remember running into a situation where I needed to use   or one of the alternatives to overcome the HTML whitespace behavior..

Thanks :slight_smile:

I use those spaces in some cases when answering to programming questions about strings, for example

In cases where a code block is appropriate, there is no problem:

```arduino
void foo() {
  char bar[] = "baz            qux";
}
```

Renders as:

void foo() {
  char bar[] = "baz            qux";
}

but I see now that in cases where an inline code span is wanted it is indeed a problem:

If you change your string to `"baz            qux"` the robot will start working.

renders as:

If you change your string to "baz qux" the robot will start working.

If you look at the page source, you can see that the forum's Markdown parser is not touching the spaces:

If you change your string to <code>"baz            qux"</code> the robot will start working.

So the whitespace is being collapsed when the HTML is rendered. Interestingly, this doesn't happen when the same HTML is rendered on GitHub.

1 Like

It looks like the inline code span behavior can be changed by making a modification in the forum theme CSS code:

1 Like

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.