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

Fixed https://github.com/chjj/marked/issues/465 #974

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions lib/marked.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,6 @@ block.list = replace(block.list)
('def', '\\n+(?=' + block.def.source + ')')
();

block.blockquote = replace(block.blockquote)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is plain wrong, cannot remove this without changing the block.blockquote regex

('def', block.def)
();

block._tag = '(?!(?:'
+ 'a|em|strong|small|s|cite|q|dfn|abbr|data|time|code'
+ '|var|samp|kbd|sub|sup|i|b|u|mark|ruby|rt|rp|bdi|bdo'
Expand Down
4 changes: 3 additions & 1 deletion test/tests/def_blocks.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
<hr>

<blockquote>
<p>hello</p>
<p>hello
[2]: hello</p>
Copy link
Contributor

@Feder1co5oave Feder1co5oave Jan 8, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

from def_blocks.text:

> hello
[2]: hello

I'm not sure this should/should not be parsed as a link definition. It is outside a blockquote.

Copy link
Contributor Author

@KostyaTretyak KostyaTretyak Jan 8, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As we now know, this edit was correct because we have rule A link reference definition cannot interrupt a paragraph.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

http://spec.commonmark.org/0.28/#example-210
Ok, because of the laziness rule, '[2]: hello' is part of the blockquote, too, and of the same paragraph of the previous line. So it is not a link def. This is correct then!

</blockquote>


Expand All @@ -24,5 +25,6 @@
<blockquote>
<p>foo
bar
[1]: foo
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's a problem in https://github.com/KostyaTretyak/marked/blob/98ac7a43958014832788b9d01580f394c84bfb27/test/tests/def_blocks.text :
The [1] at line 2 is interpreted as a shortcut link to link definition at line 20, so it can be confusing. However, I think it (line 2) should be parsed as a link def itself, because it follows the correct syntax, event if it is inside a blockquote, because it is allowed by the commonmark spec.

Copy link
Contributor Author

@KostyaTretyak KostyaTretyak Jan 8, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As we now know, this edit was correct because we have rule A link reference definition cannot interrupt a paragraph.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is no broad consensus on this one:
http://johnmacfarlane.net/babelmark2/?normalize=1&text=%3E+foo%0A%3E+bar%0A%5B1%5D%3A+foo%0A%3E+bar

However, commonmark.js parses it as you wrote.

bar</p>
</blockquote>
30 changes: 15 additions & 15 deletions test/tests/toplevel_paragraphs.gfm.html
Original file line number Diff line number Diff line change
@@ -1,30 +1,30 @@
<p>hello world
how are you
how are you</p>
text after spaces
text after spaces</p>

<p>hello world</p>
<pre><code>how are you</code></pre>
<p>paragraph before code</p>
<pre><code>text inside block code</code></pre>

<p>hello world</p>
<p>paragraph before hr</p>
<hr>

<p>hello world</p>
<p>paragraph before head with hash</p>
<h1 id="how-are-you">how are you</h1>

<p>hello world</p>
<p>paragraph before head with equals</p>
<h1 id="how-are-you">how are you</h1>

<p>hello world</p>
<blockquote><p>how are you</p></blockquote>
<p>paragraph before blockquote</p>
<blockquote><p>text for blockquote</p></blockquote>

<p>hello world</p>
<ul><li>how are you</li></ul>
<p>paragraph before list</p>
<ul><li>text inside list</li></ul>

<p>hello world</p>
<div>how are you</div>
<p>paragraph before div</p>
<div>text inside div</div>

<p>hello world
<span>how are you</span></p>
<p>paragraph with span
<span>text inside span</span></p>

<p>hello <a href="/are/you">world</a>
</p>
Expand Down
31 changes: 16 additions & 15 deletions test/tests/toplevel_paragraphs.gfm.text
Original file line number Diff line number Diff line change
@@ -1,35 +1,36 @@
hello world
how are you
how are you
text after spaces
text after spaces

hello world
paragraph before code
```
how are you
text inside block code
```

hello world
paragraph before hr
* * *

hello world
paragraph before head with hash
# how are you

hello world
paragraph before head with equals
how are you
===========

hello world
> how are you
paragraph before blockquote
> text for blockquote

hello world
* how are you
paragraph before list
* text inside list

hello world
<div>how are you</div>
paragraph before div
<div>text inside div</div>

hello world
<span>how are you</span>
paragraph with span
<span>text inside span</span>

hello [world][how]

[how]: /are/you

<div>hello</div>
Expand Down