commonmark / commonmark-spec

CommonMark spec, with reference implementations in C and JavaScript
http://commonmark.org
Other
4.89k stars 317 forks source link

Clarification of soft breaks in image descriptions + request for test case #752

Closed rmartine-ias closed 1 year ago

rmartine-ias commented 1 year ago

Image descriptions can sometimes span multiple lines -- for example, if wrapping at 80 characters. This seems to be allowed by the spec, and works on the dingus.

Example:

![alt text
on two lines](image.png)

I am requesting two things:

  1. Clarification on whether the newline should be included in the rendered HTML, or if whitespace should be collapsed into a single space. Right now it is included:

    <p><img src="image.png" alt="alt text
    on two lines" /></p>
  2. A test case where the image description contains a newline

wooorm commented 1 year ago

Why do you wonder about this?

rmartine-ias commented 1 year ago

A markdown-parsing tool I use panics with a newline in the image description: https://github.com/swsnr/mdcat/issues/194 (inline code so as to not link this issue and start any drama).

I wonder about the desired behavior mostly out of curiosity. I wanted a test so that this, and other tools, have something to reference for this case.

Apologies if this is the wrong forum for this, I haven't engaged with commonmark before.

wooorm commented 1 year ago

So panics are no good of course! But yeah, I'd say line endings are definitely supported. There's nothing that says otherwise. And it's out there in the wild. Ik not opposed to a test case nut I'm more: its the only thing that makes sense, is it really/even needed!

jgm commented 1 year ago

They're definitely allowed, not just by commonmark but by every markdown implementation I've ever seen: Babelmark link.

On whether to collapse the newline to a space in the rendered output: I think we can leave this up to the renderer; in HTML the two options are completely equivalent.

wooorm commented 1 year ago

@jgm that handling isn’t always true anymore, see https://github.com/commonmark/commonmark-spec/issues/744.

That being said, only keeping the line ending, allows the renderer (such as a browser) to choose this. As the render might do things differently. Turning it into a space prevents the renderer (a browser) from doing that.