# Converting 'line ending' to 'space' in code span makes inconvenience (CommonMark v0.29)

**URL:** <https://talk.commonmark.org/t/converting-line-ending-to-space-in-code-span-makes-inconvenience-commonmark-v0-29/3148>\
**Category:** Spec\
**Created:** [April 28, 2019, 7:22am UTC](https://talk.commonmark.org/t/converting-line-ending-to-space-in-code-span-makes-inconvenience-commonmark-v0-29/3148 "2019-04-28T07:22:53Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![vanou](https://cdn.commonmark.org/user_avatar/talk.commonmark.org/vanou/32/1558_2.png) [@vanou](https://talk.commonmark.org/u/vanou)\
**Post date:** [April 28, 2019, 7:22am UTC](https://talk.commonmark.org/t/converting-line-ending-to-space-in-code-span-makes-inconvenience-commonmark-v0-29/3148/1 "2019-04-28T07:22:53Z")

</div>

# Problem

From 0.29, code span normalizes content in following ways

> - First, **line endings** are converted to **spaces**.
> - If the resulting string both begins _and_ ends with a space  
> character, but does not consist entirely of space  
> characters, a single space character is removed from the  
> front and back. This allows you to include code that begins  
> or ends with backtick characters, which must be separated by  
> whitespace from the opening or closing backtick strings.

But, when you need to hard-wrap very long text (e.g. sha256 hash) in code span, this adds unnecessary space.

This CommonMark text

```auto
There is a chance to hard-wrap very long text (e.g. `sha256:e3b0c44298fc
1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855`).

```

will become

There is a chance to hard-wrap very long text (e.g. `sha256:e3b0c44298fc 1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855`).

When you copy&paste this sha256 hash, you see a space between `44298fc` and `1c149af`.

* * *

# Suggestion

Is following sufficient?

> In code span normalization
> 
> - First, **line endings are removed**.
> - If the resulting string both begins _and_ ends with a space  
> character, but does not consist entirely of space  
> characters, a single space character is removed from the  
> front and back. This allows you to include code that begins  
> or ends with backtick characters, which must be separated by  
> whitespace from the opening or closing backtick strings.

* * *

Sorry. I overlooked description of ‘you should use discource instead of github issues for questions’ at GitHub and made [issue](https://github.com/commonmark/commonmark-spec/issues/580) on github.

> <https://github.com/commonmark/commonmark-spec/issues/580>
>
> \# Problem
> 
> From 0.29, code span normalizes content in following ways
> 
> \> - Fi…rst, \*\*line endings\*\* are converted to \*\*spaces\*\*.
> \> - If the resulting string both begins \*and\* ends with a space
> \> character, but does not consist entirely of space
> \> characters, a single space character is removed from the
> \> front and back. This allows you to include code that begins
> \> or ends with backtick characters, which must be separated by
> \> whitespace from the opening or closing backtick strings.
> 
> But, when you need to hard-wrap very long text (e.g. sha256 hash) in code span, this adds unnecessary space.
> 
> This CommonMark text
> \`\`\`
> There is a chance to hard-wrap very long text (e.g. \`sha256:e3b0c44298fc
> 1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855\`).
> \`\`\`
> will become
> \> There is a chance to hard-wrap very long text (e.g. \`sha256:e3b0c44298fc
> \> 1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855\`).
> 
> When you copy&paste this sha256 hash, you see a space between \`44298fc\` and \`1c149af\`.
> 
> \---
> 
> \# Suggestion
> 
> Is following sufficient?
> 
> \> In code span normalization 
> \> - First, \*\*line endings are removed\*\*.
> \> - If the resulting string both begins \*and\* ends with a space
> \> character, but does not consist entirely of space
> \> characters, a single space character is removed from the
> \> front and back. This allows you to include code that begins
> \> or ends with backtick characters, which must be separated by
> \> whitespace from the opening or closing backtick strings.

---

<div class="post-metadata">

**Author:** ![Brian\_Lalonde](https://cdn.commonmark.org/user_avatar/talk.commonmark.org/brian_lalonde/32/1565_2.png) [@Brian\_Lalonde](https://talk.commonmark.org/u/Brian_Lalonde)\
**Post date:** [April 30, 2019, 1:43pm UTC](https://talk.commonmark.org/t/converting-line-ending-to-space-in-code-span-makes-inconvenience-commonmark-v0-29/3148/2 "2019-04-30T13:43:36Z")

</div>

Are you using [code spans](https://spec.commonmark.org/0.29/#code-spans) rather than [indented code blocks](https://spec.commonmark.org/0.29/#indented-code-blocks) or [fenced code blocks](https://spec.commonmark.org/0.29/#fenced-code-blocks)? Those may work better for you.

---

<div class="post-metadata">

**Author:** ![Crissov](https://cdn.commonmark.org/user_avatar/talk.commonmark.org/crissov/32/1455_2.png) [@Crissov](https://talk.commonmark.org/u/Crissov)\
**Post date:** [April 30, 2019, 4:06pm UTC](https://talk.commonmark.org/t/converting-line-ending-to-space-in-code-span-makes-inconvenience-commonmark-v0-29/3148/3 "2019-04-30T16:06:31Z")

</div>

Would escaping line breaks work? (It does not currently.)

```markdown
foo ``sha256:e3b0c44298fc1c149afbf4c8996fb924\
27ae41e4649b934ca495991b7852b855`` bar

```

---

<div class="post-metadata">

**Author:** ![vanou](https://cdn.commonmark.org/user_avatar/talk.commonmark.org/vanou/32/1558_2.png) [@vanou](https://talk.commonmark.org/u/vanou)\
**Post date:** [May 1, 2019, 12:09am UTC](https://talk.commonmark.org/t/converting-line-ending-to-space-in-code-span-makes-inconvenience-commonmark-v0-29/3148/4 "2019-05-01T00:09:25Z")

</div>

@Brian_Lalonde

Yes, I do.  
Because I would like to embed long string (e.g. sha256 hash) into paragraph.

indented code blocks & fenced code blocks cannot do this, can they?

---

<div class="post-metadata">

**Author:** ![Brian\_Lalonde](https://cdn.commonmark.org/user_avatar/talk.commonmark.org/brian_lalonde/32/1565_2.png) [@Brian\_Lalonde](https://talk.commonmark.org/u/Brian_Lalonde)\
**Post date:** [May 1, 2019, 1:13am UTC](https://talk.commonmark.org/t/converting-line-ending-to-space-in-code-span-makes-inconvenience-commonmark-v0-29/3148/5 "2019-05-01T01:13:02Z")

</div>

They’ll wrap if you show them where (depending on available width):

```auto
foo `sha256:e3b0c44298fc1c149afbf4c8996fb924`
`27ae41e4649b934ca495991b7852b855` bar

```

Otherwise, CommonMark doesn’t currently have the level of sophistication to preserve line breaks in a block within a block that doesn’t preserve line breaks (this simplicity is why it’s so popular). However, you can use a little HTML:

```auto
foo `sha256:e3b0c44298fc1c149afbf4c8996fb924`<br/>
`27ae41e4649b934ca495991b7852b855` bar

```

Or else, if you find that you frequently, absolutely require a level of formatting sophistication beyond what CommonMark can provide, there are formats that may work better for you: HTML or AsciiDoc or [many others](https://en.wikipedia.org/wiki/Lightweight_markup_language).

I’m not sure how much impact changing the line-ending behavior in code spans would have. If it’s not too big, and there are important use cases, it could be worth pursuing further here.

---

<div class="post-metadata">

**Author:** ![vanou](https://cdn.commonmark.org/user_avatar/talk.commonmark.org/vanou/32/1558_2.png) [@vanou](https://talk.commonmark.org/u/vanou)\
**Post date:** [May 1, 2019, 6:15am UTC](https://talk.commonmark.org/t/converting-line-ending-to-space-in-code-span-makes-inconvenience-commonmark-v0-29/3148/6 "2019-05-01T06:15:10Z")

</div>

> [@Crissov](#):
>
> Would escaping line breaks work? (It does not currently.)
> 
> ```auto
> foo ``sha256:e3b0c44298fc1c149afbf4c8996fb924\
> 27ae41e4649b934ca495991b7852b855`` bar
> 
> ```

You mean this?

> (This isn’t what current spec is, but as an idea)
> 
> In code span, if and only if backslash comes at the end of line, it escapes line ending and no space will be added in place of line ending. And other backslashes which aren’t at the end of line will be treated literally.

If so, it looks nice for me.

---

<div class="post-metadata">

**Author:** ![vanou](https://cdn.commonmark.org/user_avatar/talk.commonmark.org/vanou/32/1558_2.png) [@vanou](https://talk.commonmark.org/u/vanou)\
**Post date:** [May 1, 2019, 6:52am UTC](https://talk.commonmark.org/t/converting-line-ending-to-space-in-code-span-makes-inconvenience-commonmark-v0-29/3148/7 "2019-05-01T06:52:31Z")

</div>

@Brian_Lalonde

> [@Brian\_Lalonde](#):
>
> Otherwise, CommonMark doesn’t currently have the level of sophistication to preserve line breaks in a block within a block

No. What I expect isn’t to preserve line break.

What I expect is this

```auto
<p>foo <code>sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855</code> bar</p>

```

But when I hard wrap it in code span like this

```auto
foo ``sha256:e3b0c44298fc1c149afbf4c8996fb924
27ae41e4649b934ca495991b7852b855`` bar

```

it’ll become

```auto
<p>foo <code>sha256:e3b0c44298fc1c149afbf4c8996fb924 27ae41e4649b934ca495991b7852b855</code> bar</p>

```

* * *

> [@Brian\_Lalonde](#):
>
> if you find that you frequently, absolutely require a level of formatting sophistication beyond what CommonMark can provide, there are formats that may work better for you

Yeah. To use another tool can be one approach.

---

<div class="post-metadata">

**Author:** ![Crissov](https://cdn.commonmark.org/user_avatar/talk.commonmark.org/crissov/32/1455_2.png) [@Crissov](https://talk.commonmark.org/u/Crissov)\
**Post date:** [May 1, 2019, 9:39am UTC](https://talk.commonmark.org/t/converting-line-ending-to-space-in-code-span-makes-inconvenience-commonmark-v0-29/3148/8 "2019-05-01T09:39:00Z")

</div>

In HTML, hard-wrapping can have the same result, though.

```auto
<p>foo <code>sha256:e3b0c44298fc1c149afbf4c8996fb92427
ae41e4649b934ca495991b7852b855</code> bar</p>

```

---

<div class="post-metadata">

**Author:** ![vanou](https://cdn.commonmark.org/user_avatar/talk.commonmark.org/vanou/32/1558_2.png) [@vanou](https://talk.commonmark.org/u/vanou)\
**Post date:** [May 1, 2019, 12:16pm UTC](https://talk.commonmark.org/t/converting-line-ending-to-space-in-code-span-makes-inconvenience-commonmark-v0-29/3148/9 "2019-05-01T12:16:11Z")

</div>

I get a space between `92427` and `ae41e` when browsing this file

```auto
<!DOCTYPE html>
<html>
 <body>
  <p>foo <code>sha256:e3b0c44298fc1c149afbf4c8996fb92427
  ae41e4649b934ca495991b7852b855</code> bar</p>
 </body>
</html>

```

What is wrong? Could you tell me the point?

---

<div class="post-metadata">

**Author:** ![cben](https://cdn.commonmark.org/user_avatar/talk.commonmark.org/cben/32/407_2.png) [@cben](https://talk.commonmark.org/u/cben)\
**Post date:** [May 28, 2019, 12:59pm UTC](https://talk.commonmark.org/t/converting-line-ending-to-space-in-code-span-makes-inconvenience-commonmark-v0-29/3148/10 "2019-05-28T12:59:30Z")

</div>

vanou, IIUC you want the hash to remain a single unbroken string in the output — `sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855` — right?

Neither HTML nor markdown support hard-wrapping _inside a word_. All talk of “hard-wrapping” markdown is about liberty (in many though not all places) to break a “logical line” into multiple “physical lines” by using a newline _between words_.  
But the newline in middle of a word will _always_ split it into 2 words (in a few cases by a line break in the output, in others simple by a space).

Markdown has no hard goal of allowing the input to always fit a fixed width, say 80 columns. If you want to say a single 200-character word, you must write at least that word unbroken.
