Leading and trailing white spaces in code blocks

release-1.0

#21

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

#22

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.


#23

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.


#24

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 https://github.com/commonmark/commonmark/issues/532