Leading and trailing white spaces in code blocks

Looking back at this thread, I think the cleanest option would be:

  1. Collapse one initial space if the next non-space character is a backtick.
  2. Collapse one final space if the preceeding non-space character is a backtick.
  3. Do not collapse interior spaces.
  4. Treat an interior newline as a space unless it’s adjacent to a space, in which case ignore it.

But 1 and 2 might lead to backwards compatibility issues, so it’s probably better to do something like this:

  1. Collapse one initial and one final space, but only if there is both initial and final space. So, for example BACKTICK + SPACE + A + BACKTICK gives you a code span with SPACE + A, while BACKTICK + SPACE + A + SPACE + BACKTICK gives you one with just A.
  2. Do not collapse interior spaces.
  3. Treat an interior newline as a space unless it’s adjacent to a space, in which case ignore it.
5 Likes