Marked: GFM hard line breaks don't follow spec

Created on 27 Nov 2018  路  9Comments  路  Source: markedjs/marked

Describe the bug
GFM spec describes the following as a hard line break:

foo路路
bar

and should translate to the following HTML

<p>foo<br />bar</p>

Similarly, the following is a soft line break (note the lack of 2 trailing spaces):

bar

and should translate to the following HTML

<p>foo\nbar</p>

This spec should be followed when gfm and breaks are both enabled, however enabling breaks will always output the first style (hard line breaks), even when the trailing spaces are omitted.

To Reproduce
RunKit example

Expected behavior
When gfm and breaks are enabled, the second example (soft line break) should not output a <br /> tag.

bar

should output

<p>foo\nbar</p>
GFM

Most helpful comment

Looks like the real problem is that our documentation for the "breaks" option is wrong.

All 9 comments

Relevant GFM spec:
Hard line breaks
Soft line breaks

Yes this appears to be a bug.
I'm surprised these are not in our tests.

function testOptions(opts) {
  var md632 = 'foo  \nbaz';
  var md633 = 'foo\\\nbaz';
  var md647 = 'foo\nbaz';
  var md648 = 'foo \n baz';
  console.log(opts);
  console.log(marked(md632, opts));
  console.log(marked(md633, opts));
  console.log(marked(md647, opts));
  console.log(marked(md648, opts));
  console.log('\n');
}

testOptions({gfm: true, breaks: true});
testOptions({gfm: true, breaks: false});

@joshbruce Any idea why gfm.0.2.8.json is missing these tests? How did you acquire this file?

testing
this

Sorry clicked the wrong button...

Apparently GitHub doesn't follow the GFM spec.

If you look at the source of the comment above github does add a <br/> but there were no spaces after "testing"

image

The "breaks" option was added to make the "gfm" option function like github (i.e. add <br> on single \n) https://github.com/markedjs/marked/issues/51

With the "breaks" option off it will follow the spec.

@styfle gfm.0.28.json only has tests for things that are different between GFM 0.28 and CommonMark 0.28

The hard and soft line breaks are the same in both specs (even though github doesn't follow them)

Looks like the real problem is that our documentation for the "breaks" option is wrong.

Agree with @UziTech.
How many of those hard line-breaks test cases do pass?

according to the Common Mark spec tests 100% pass. And just testing manually 100% pass with gfm: true, breaks: false

https://github.com/markedjs/marked/blob/97be813c267b3d60a1bcef6f0b7ffa6014abc230/test/specs/commonmark/commonmark-spec.js#L53-L54

Was this page helpful?
0 / 5 - 0 ratings

Related issues

james4388 picture james4388  路  3Comments

chunhei2008 picture chunhei2008  路  3Comments

gclove picture gclove  路  4Comments

raguay picture raguay  路  4Comments

eGavr picture eGavr  路  4Comments