Looking back at this thread, I think the cleanest option would be:
- Collapse one initial space if the next non-space character is a backtick.
- Collapse one final space if the preceeding non-space character is a backtick.
- Do not collapse interior spaces.
- 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:
- 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.
- Do not collapse interior spaces.
- Treat an interior newline as a space unless it’s adjacent to a space, in which case ignore it.