Consecutive spaces in inline code get collapsed

Consecutive spaces in inline code get collapsed. Here’s an example.

Markdown:

 - `o     o` no connection
 - `o --> o` unidirectional connection
 - `o <-> o` bidirectional connection

Rendering:

  • o o no connection
  • o --> o unidirectional connection
  • o <-> o bidirectional connection

Screenshot of rendering:

image

It’s unclear to me whether this is intentional or a bug, but if it’s intentional, I do not really see the point. As you can see above, it can be counterproductive. If one does not want extra spaces, it is easy to delete them manually. The point of code blocks (whether inline or separate) is to include verbatim text with a fixed-width font.

5 Likes

Hi Szabolcs!

Thanks for the report. I understand the issue, and it’s not strictly a Discourse bug. Discourse uses markdown-it, and this is its standard behavior.

You can see the same behavior on the official demo: https://markdown-it.github.io.


If you need spaces not to be collapsed between backticks, you can add this CSS to your forum:

code {
    white-space: pre-wrap;
}
3 Likes

Looks like it this isn’t compliant with CommonMark. Not that it has to be, but maybe they could be convinced to change to match?

https://spec.commonmark.org/0.30/#code-spans

Depending on purpose that can be even worse, because it can cause copy / paste confusion.

3 Likes

You’re right, I didn’t think about that, I’ve removed this tricky advice :+1:

1 Like

I’m not familiar with this kind of stuff, but I guess this is the part you’re talking about?

Note that browsers will typically collapse consecutive spaces when rendering <code> elements, so it is recommended that the following CSS be used:

code{white-space: pre-wrap;}

For what it’s worth, it appears that Non-Breaking Space is not collapsed (o o), so if you must use a weird one, that’s probably the best choice.

Edit: see below for sad news!

The line above that one: “Interior spaces are not collapsed".

1 Like

Non-regular spaces can appear non-collapsed in the composer preview, but are when the post is processed.

1 Like

Welllllll that’s unfortunate.

Thank you for the tip!

Do you happen to know if setting custom CSS is available for sites hosted on discourse.group? I wasn’t able to find the setting immediately.

Discourse pricing | Discourse - Civilized Discussion tells that Custom themes and components is enabled only starting from the standard plan.

Thank you. I finally found the setting and it works perfectly well :slight_smile:

We use the free hosting offered for open source projects, https://free.discourse.group/

3 Likes

I am moving this to ux, this is working as designed there was a deliberate decision by the design team to collapse the spaces in the ui, the markdown itself is correct.

1 Like