Skip to content

Commit

Permalink
Merge pull request #1600 from calculuschild/Fix-Example-116
Browse files Browse the repository at this point in the history
Fix GFM Example 116
  • Loading branch information
styfle authored Feb 11, 2020
2 parents 5ebb8fc + 63454d2 commit 1f96816
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 6 deletions.
4 changes: 2 additions & 2 deletions src/rules.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const {
const block = {
newline: /^\n+/,
code: /^( {4}[^\n]+\n*)+/,
fences: /^ {0,3}(`{3,}|~{3,})([^`~\n]*)\n(?:|([\s\S]*?)\n)(?: {0,3}\1[~`]* *(?:\n+|$)|$)/,
fences: /^ {0,3}(`{3,}(?=[^`\n]*\n)|~{3,})([^\n]*)\n(?:|([\s\S]*?)\n)(?: {0,3}\1[~`]* *(?:\n+|$)|$)/,
hr: /^ {0,3}((?:- *){3,}|(?:_ *){3,}|(?:\* *){3,})(?:\n+|$)/,
heading: /^ {0,3}(#{1,6}) +([^\n]*?)(?: +#+)? *(?:\n+|$)/,
blockquote: /^( {0,3}> ?(paragraph|[^\n]*)(?:\n|$))+/,
Expand Down Expand Up @@ -72,7 +72,7 @@ block.paragraph = edit(block._paragraph)
.replace('heading', ' {0,3}#{1,6} +')
.replace('|lheading', '') // setex headings don't interrupt commonmark paragraphs
.replace('blockquote', ' {0,3}>')
.replace('fences', ' {0,3}(?:`{3,}|~{3,})[^`\\n]*\\n')
.replace('fences', ' {0,3}(?:`{3,}(?=[^`\\n]*\\n)|~{3,})[^\\n]*\\n')
.replace('list', ' {0,3}(?:[*+-]|1[.)]) ') // only lists starting from 1 can interrupt
.replace('html', '</?(?:tag)(?: +|\\n|/?>)|<(?:script|pre|style|!--)')
.replace('tag', block._tag) // pars can be interrupted by type (6) html blocks
Expand Down
3 changes: 1 addition & 2 deletions test/specs/commonmark/commonmark.0.29.json
Original file line number Diff line number Diff line change
Expand Up @@ -930,8 +930,7 @@
"example": 116,
"start_line": 1996,
"end_line": 2003,
"section": "Fenced code blocks",
"shouldFail": true
"section": "Fenced code blocks"
},
{
"markdown": "```\n``` aaa\n```\n",
Expand Down
3 changes: 1 addition & 2 deletions test/specs/gfm/commonmark.0.29.json
Original file line number Diff line number Diff line change
Expand Up @@ -930,8 +930,7 @@
"example": 116,
"start_line": 1996,
"end_line": 2003,
"section": "Fenced code blocks",
"shouldFail": true
"section": "Fenced code blocks"
},
{
"markdown": "```\n``` aaa\n```\n",
Expand Down
14 changes: 14 additions & 0 deletions test/specs/new/fences_breaking_paragraphs.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<p>A paragraph</p>
<pre><code class="language-A">Here is code in
backtick fences</code></pre>
<p>B paragraph</p>
<pre><code class="language-B">Here is code in
tilde fences</code></pre>
<p>C paragraph</p>
<pre><code class="language-`C~">Alternative
tilde fences</code></pre>
<p>D paragraph ```~D` Invalid use of backtick fences</p>
<pre><code>
This will be read as
part of a codeblock
that ends with the file</code></pre>
27 changes: 27 additions & 0 deletions test/specs/new/fences_breaking_paragraphs.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
A paragraph
```A
Here is code in
backtick fences
```

B paragraph
~~~B
Here is code in
tilde fences
~~~

C paragraph
~~~`C~
Alternative
tilde fences
~~~

D paragraph
```~D`
Invalid use of
backtick fences
```
This will be read as
part of a codeblock
that ends with the file

1 comment on commit 1f96816

@vercel
Copy link

@vercel vercel bot commented on 1f96816 Feb 11, 2020

Choose a reason for hiding this comment

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

Please sign in to comment.