Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replaces every 1., 2., 3. for 1., 1., 1. in every part of the text #1153

Closed
gonzae opened this issue Mar 22, 2018 · 8 comments · Fixed by #1157
Closed

Replaces every 1., 2., 3. for 1., 1., 1. in every part of the text #1153

gonzae opened this issue Mar 22, 2018 · 8 comments · Fixed by #1157
Labels
category: lists L1 - broken Valid usage causes incorrect output OR a crash AND there is no known workaround for the issue parser: CommonMark

Comments

@gonzae
Copy link

gonzae commented Mar 22, 2018

Marked version: 0.3.16

Expectation

When parsing text to HTML don't assume that every 1., 2., 3. is an ordered list.

Result

Replaces every 1., 2., 3. for 1., 1., 1. in every part of the text

What was attempted

var marked = require("marked")

var text = `Lorem ipsum dolor sit amet, consectetur adipiscing elit. Praesent sagittis accumsan congue. Sed dictum nunc eu eros fringilla tempus. Morbi blandit sapien nunc, id pellentesque lectus pellentesque congue. Proin pulvinar felis et dui commodo, nec venenatis magna pharetra. Nulla facilisi. Sed dictum turpis non libero pharetra rutrum. In egestas pretium dolor a pharetra. Proin id odio a enim ultrices laoreet pellentesque in orci. Duis mattis sapien porttitor, blandit orci ut, molestie metus. Aliquam iaculis ullamcorper massa, a tincidunt leo ullamcorper a. Fusce ante est, vestibulum vitae finibus vitae, convallis at est. Vivamus molestie, felis nec lacinia porttitor, ligula magna mollis erat, dictum luctus turpis neque ut massa. Etiam quis leo sit amet ante rutrum sodales.

1. Lorem ipsum dolor sit amet

Proin mi tortor, consectetur et justo nec, viverra aliquet risus. Nulla tincidunt mi enim, sed aliquam augue vehicula in. Phasellus quis velit gravida, porttitor urna id, ornare arcu. Aliquam eget accumsan est, ac pulvinar tortor. Proin ultrices arcu quis semper dictum. Mauris convallis, libero quis tristique cursus, justo sapien bibendum justo, vestibulum laoreet nisl leo ut magna. Aenean mollis scelerisque libero, elementum eleifend libero varius a. Morbi lacinia finibus elit, at finibus dui bibendum ac. Aliquam consequat lacus eu nisi eleifend aliquet. Nulla malesuada ac elit sed interdum.

2. Lorem ipsum dolor sit amet

Sed a sapien rutrum, blandit arcu quis, efficitur sem. Duis id viverra urna. Proin non tortor condimentum, suscipit tellus et, varius urna. Curabitur vulputate nibh in orci ullamcorper, id efficitur velit efficitur. Suspendisse id facilisis lectus. Nulla in diam faucibus lorem accumsan iaculis id maximus ante. In erat ligula, scelerisque viverra ante sit amet, aliquet efficitur dolor. Cras aliquam felis vitae luctus finibus.

3. Lorem ipsum dolor sit amet

Morbi ut ornare libero. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae; Fusce non tristique nisl. Ut mauris mi, imperdiet sit amet diam vel, ultricies venenatis augue. Fusce a nunc vel turpis mollis dapibus. Vestibulum nec sem sit amet libero consequat pellentesque. Quisque vel metus arcu. Morbi enim purus, eleifend non dolor in, condimentum facilisis dui. Sed dignissim, nisi a convallis bibendum, lorem nisl cursus massa, eu efficitur odio est ac lorem. Nulla bibendum orci quam, vitae fermentum lacus gravida at. Suspendisse potenti.

4. Lorem ipsum dolor sit amet

Sed auctor sem eget consequat rhoncus. Nullam ac erat sagittis, scelerisque urna et, tincidunt nulla. Integer maximus sed quam quis maximus. Maecenas eu metus turpis. Duis ac lacinia arcu. Quisque cursus sapien sit amet egestas mattis. Sed semper leo porttitor risus laoreet mattis. Quisque nec luctus nisl.`;

console.log( marked( text ) );

It outputs:

<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Praesent sagittis accumsan congue. Sed dictum nunc eu eros fringilla tempus. Morbi blandit sapien nunc, id pellentesque lectus pellentesque congue. Proin pulvinar felis et dui commodo, nec venenatis magna pharetra. Nulla facilisi. Sed dictum turpis non libero pharetra rutrum. In egestas pretium dolor a pharetra. Proin id odio a enim ultrices laoreet pellentesque in orci. Duis mattis sapien porttitor, blandit orci ut, molestie metus. Aliquam iaculis ullamcorper massa, a tincidunt leo ullamcorper a. Fusce ante est, vestibulum vitae finibus vitae, convallis at est. Vivamus molestie, felis nec lacinia porttitor, ligula magna mollis erat, dictum luctus turpis neque ut massa. Etiam quis leo sit amet ante rutrum sodales.</p>
<ol>
<li>Lorem ipsum dolor sit amet</li>
</ol>
<p>Proin mi tortor, consectetur et justo nec, viverra aliquet risus. Nulla tincidunt mi enim, sed aliquam augue vehicula in. Phasellus quis velit gravida, porttitor urna id, ornare arcu. Aliquam eget accumsan est, ac pulvinar tortor. Proin ultrices arcu quis semper dictum. Mauris convallis, libero quis tristique cursus, justo sapien bibendum justo, vestibulum laoreet nisl leo ut magna. Aenean mollis scelerisque libero, elementum eleifend libero varius a. Morbi lacinia finibus elit, at finibus dui bibendum ac. Aliquam consequat lacus eu nisi eleifend aliquet. Nulla malesuada ac elit sed interdum.</p>
<ol>
<li>Lorem ipsum dolor sit amet</li>
</ol>
<p>Sed a sapien rutrum, blandit arcu quis, efficitur sem. Duis id viverra urna. Proin non tortor condimentum, suscipit tellus et, varius urna. Curabitur vulputate nibh in orci ullamcorper, id efficitur velit efficitur. Suspendisse id facilisis lectus. Nulla in diam faucibus lorem accumsan iaculis id maximus ante. In erat ligula, scelerisque viverra ante sit amet, aliquet efficitur dolor. Cras aliquam felis vitae luctus finibus.</p>
<ol>
<li>Lorem ipsum dolor sit amet</li>
</ol>
<p>Morbi ut ornare libero. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae; Fusce non tristique nisl. Ut mauris mi, imperdiet sit amet diam vel, ultricies venenatis augue. Fusce a nunc vel turpis mollis dapibus. Vestibulum nec sem sit amet libero consequat pellentesque. Quisque vel metus arcu. Morbi enim purus, eleifend non dolor in, condimentum facilisis dui. Sed dignissim, nisi a convallis bibendum, lorem nisl cursus massa, eu efficitur odio est ac lorem. Nulla bibendum orci quam, vitae fermentum lacus gravida at. Suspendisse potenti.</p>
<ol>

And looks like:

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Praesent sagittis accumsan congue. Sed dictum nunc eu eros fringilla tempus. Morbi blandit sapien nunc, id pellentesque lectus pellentesque congue. Proin pulvinar felis et dui commodo, nec venenatis magna pharetra. Nulla facilisi. Sed dictum turpis non libero pharetra rutrum. In egestas pretium dolor a pharetra. Proin id odio a enim ultrices laoreet pellentesque in orci. Duis mattis sapien porttitor, blandit orci ut, molestie metus. Aliquam iaculis ullamcorper massa, a tincidunt leo ullamcorper a. Fusce ante est, vestibulum vitae finibus vitae, convallis at est. Vivamus molestie, felis nec lacinia porttitor, ligula magna mollis erat, dictum luctus turpis neque ut massa. Etiam quis leo sit amet ante rutrum sodales.

1. Lorem ipsum dolor sit amet
Proin mi tortor, consectetur et justo nec, viverra aliquet risus. Nulla tincidunt mi enim, sed aliquam augue vehicula in. Phasellus quis velit gravida, porttitor urna id, ornare arcu. Aliquam eget accumsan est, ac pulvinar tortor. Proin ultrices arcu quis semper dictum. Mauris convallis, libero quis tristique cursus, justo sapien bibendum justo, vestibulum laoreet nisl leo ut magna. Aenean mollis scelerisque libero, elementum eleifend libero varius a. Morbi lacinia finibus elit, at finibus dui bibendum ac. Aliquam consequat lacus eu nisi eleifend aliquet. Nulla malesuada ac elit sed interdum.

1. Lorem ipsum dolor sit amet
Sed a sapien rutrum, blandit arcu quis, efficitur sem. Duis id viverra urna. Proin non tortor condimentum, suscipit tellus et, varius urna. Curabitur vulputate nibh in orci ullamcorper, id efficitur velit efficitur. Suspendisse id facilisis lectus. Nulla in diam faucibus lorem accumsan iaculis id maximus ante. In erat ligula, scelerisque viverra ante sit amet, aliquet efficitur dolor. Cras aliquam felis vitae luctus finibus.

1. Lorem ipsum dolor sit amet
Morbi ut ornare libero. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae; Fusce non tristique nisl. Ut mauris mi, imperdiet sit amet diam vel, ultricies venenatis augue. Fusce a nunc vel turpis mollis dapibus. Vestibulum nec sem sit amet libero consequat pellentesque. Quisque vel metus arcu. Morbi enim purus, eleifend non dolor in, condimentum facilisis dui. Sed dignissim, nisi a convallis bibendum, lorem nisl cursus massa, eu efficitur odio est ac lorem. Nulla bibendum orci quam, vitae fermentum lacus gravida at. Suspendisse potenti.

1. Lorem ipsum dolor sit amet
Sed auctor sem eget consequat rhoncus. Nullam ac erat sagittis, scelerisque urna et, tincidunt nulla. Integer maximus sed quam quis maximus. Maecenas eu metus turpis. Duis ac lacinia arcu. Quisque cursus sapien sit amet egestas mattis. Sed semper leo porttitor risus laoreet mattis. Quisque nec luctus nisl.
@joshbruce
Copy link
Member

joshbruce commented Mar 22, 2018

@gonzae thank you for posting this. Two things:

  1. Believe the expected behavior is being achieved. See CommonMark spec: http://spec.commonmark.org/0.28/#list-items & http://spec.commonmark.org/0.28/#lists
  2. Update to the 0.3.18 release performed today, as it does have some fixes related to ordered lists.

@gonzae
Copy link
Author

gonzae commented Mar 22, 2018

Hi @joshbruce, thanks for the quick response. In the spects, there is this sentence:

The start number of an ordered list is determined by the list number of its initial list item. The numbers of subsequent list items are disregarded.

So, what I get from that is that the start number should be preserved. I understand that the output should be:

<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Praesent sagittis accumsan congue. Sed dictum nunc eu eros fringilla tempus. Morbi blandit sapien nunc, id pellentesque lectus pellentesque congue. Proin pulvinar felis et dui commodo, nec venenatis magna pharetra. Nulla facilisi. Sed dictum turpis non libero pharetra rutrum. In egestas pretium dolor a pharetra. Proin id odio a enim ultrices laoreet pellentesque in orci. Duis mattis sapien porttitor, blandit orci ut, molestie metus. Aliquam iaculis ullamcorper massa, a tincidunt leo ullamcorper a. Fusce ante est, vestibulum vitae finibus vitae, convallis at est. Vivamus molestie, felis nec lacinia porttitor, ligula magna mollis erat, dictum luctus turpis neque ut massa. Etiam quis leo sit amet ante rutrum sodales.</p>
<ol>
<li>Lorem ipsum dolor sit amet</li>
</ol>
<p>Proin mi tortor, consectetur et justo nec, viverra aliquet risus. Nulla tincidunt mi enim, sed aliquam augue vehicula in. Phasellus quis velit gravida, porttitor urna id, ornare arcu. Aliquam eget accumsan est, ac pulvinar tortor. Proin ultrices arcu quis semper dictum. Mauris convallis, libero quis tristique cursus, justo sapien bibendum justo, vestibulum laoreet nisl leo ut magna. Aenean mollis scelerisque libero, elementum eleifend libero varius a. Morbi lacinia finibus elit, at finibus dui bibendum ac. Aliquam consequat lacus eu nisi eleifend aliquet. Nulla malesuada ac elit sed interdum.</p>
<ol start="2">
<li>Lorem ipsum dolor sit amet</li>
</ol>
<p>Sed a sapien rutrum, blandit arcu quis, efficitur sem. Duis id viverra urna. Proin non tortor condimentum, suscipit tellus et, varius urna. Curabitur vulputate nibh in orci ullamcorper, id efficitur velit efficitur. Suspendisse id facilisis lectus. Nulla in diam faucibus lorem accumsan iaculis id maximus ante. In erat ligula, scelerisque viverra ante sit amet, aliquet efficitur dolor. Cras aliquam felis vitae luctus finibus.</p>
<ol start="3">
<li>Lorem ipsum dolor sit amet</li>
</ol>
<p>Morbi ut ornare libero. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae; Fusce non tristique nisl. Ut mauris mi, imperdiet sit amet diam vel, ultricies venenatis augue. Fusce a nunc vel turpis mollis dapibus. Vestibulum nec sem sit amet libero consequat pellentesque. Quisque vel metus arcu. Morbi enim purus, eleifend non dolor in, condimentum facilisis dui. Sed dignissim, nisi a convallis bibendum, lorem nisl cursus massa, eu efficitur odio est ac lorem. Nulla bibendum orci quam, vitae fermentum lacus gravida at. Suspendisse potenti.</p>
<ol start="4">
<li>Lorem ipsum dolor sit amet</li>
</ol>
<p>Sed auctor sem eget consequat rhoncus. Nullam ac erat sagittis, scelerisque urna et, tincidunt nulla. Integer maximus sed quam quis maximus. Maecenas eu metus turpis. Duis ac lacinia arcu. Quisque cursus sapien sit amet egestas mattis. Sed semper leo porttitor risus laoreet mattis. Quisque nec luctus nisl.</p>

And that's the output I was expecting. Do you agree?
Also, I tried with the version 0.3.18 and behaves as reported.

@joshbruce
Copy link
Member

Just making a quick note: See #1143

@UziTech
Copy link
Member

UziTech commented Mar 23, 2018

@joshbruce I think there might be a problem with the version of marked published to npm.

I ran the following code on https://npm.runkit.com/marked

marked("1. a\n\nb\n\n2. c");

and it outputs:

	1. a

b

	1. c

but when I run the code against the v0.3.18 release

it outputs:

	1. a

b

	2. c

@UziTech
Copy link
Member

UziTech commented Mar 23, 2018

image

@UziTech
Copy link
Member

UziTech commented Mar 23, 2018

Yup looks like the lib/marked.js file published to npm under v0.3.18 is from ec78260 not 5d5fa04

@joshbruce
Copy link
Member

Confirmed. Ran through the following diff checker: https://www.diffchecker.com/diff

  • Clean checkout of master against the GitHub release zip - same.
  • Clean checkout of master against the NPM package - diff.
  • GitHub release zip again the NPM package - diff.

Not sure how that happened. Will need to put together a 0.3.19 release as NPM won't let us publish over a previous submitted (http://blog.npmjs.org/post/77758351673/no-more-npm-publish-f). Not sure how it happened to be honest and will be more careful in the future to see if we can figure out what happened.

@joshbruce joshbruce added the L1 - broken Valid usage causes incorrect output OR a crash AND there is no known workaround for the issue label Mar 23, 2018
@joshbruce
Copy link
Member

@UziTech: Does this also mean that the tests for this weren't run in the #1152 PR??

@joshbruce joshbruce mentioned this issue Mar 23, 2018
12 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
category: lists L1 - broken Valid usage causes incorrect output OR a crash AND there is no known workaround for the issue parser: CommonMark
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants