Leading and trailing white spaces in code blocks

Babelmark 3 report

Implementations that strip all leading and trailing spaces inside backtick spans and collapse internal runs of spaces (i.e. behavior currently specified by Commonmark):

  • commonmark.js
  • GitHub Flavored Markdown
  • league/commonmark
  • markdig
  • markdown-it

Implementations that strip all leading and trailing spaces inside backtick spans and keep internal runs of spaces:

  • blackfriday
  • cheapskate
  • DFM
  • earmark
  • markdown101
  • markdown102
  • MD4C
  • multimarkdown
  • pandoc
  • parsedown
  • php-markdown-extra
  • php-markdown
  • python-markdown
  • redcarpet
  • s9e/TextFormatter

Implementations that keep all leading and trailing spaces inside backtick spans and keep internal runs of spaces:

  • Cebe
  • Gambas
  • kramdown
  • Maruku

Implementations that trim one leading or trailing space inside backtick spans and keep internal runs of spaces (i.e. closest to desired behavior):

  • lunamark
  • rdiscount
1 Like

If the intention is to enable easy pasting of source code into backtick spans, then it would be good to think about how tabs should be dealt with too, as Go source code is indented with tab characters by all the standard tools.

Current behavior seems to be to pass them through verbatim?

Also, the tools use internal runs of spaces to vertically align code, so it would be good not to strip internal space runs.

Haha, I just ran into this again, googled the issue, and found Iā€™d already posted in this thread a year ago. Leading and trailing spaces in code spans still isnā€™t at all possible, is it?

Hereā€™s hoping for some movement on this issue soon, so leading and trailing spaces become possible to illustrate using code spans.

obskyr noreply@talk.commonmark.org writes:

Haha, I just ran into this again, googled the issue, and found Iā€™d already posted in this thread a year ago. Leading and trailing spaces in code spans still isnā€™t at all possible, is it?

The dev version can now handle leading and
trailing space (as well as consecutive interior
spaces). However, this hasnā€™t yet made it to
a released version.

See Don't collapse interior spaces in code spans Ā· Issue #532 Ā· commonmark/commonmark-spec Ā· GitHub

1 Like