Skip to content

Commit

Permalink
Merge pull request #1035 from Feder1co5oave/fix_hr
Browse files Browse the repository at this point in the history
[commonmark] make thematic breaks (<hr>) compliant
  • Loading branch information
joshbruce committed Jan 25, 2018
2 parents 33b444c + b8437b0 commit 6b0416d
Show file tree
Hide file tree
Showing 6 changed files with 250 additions and 5 deletions.
8 changes: 4 additions & 4 deletions lib/marked.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ var block = {
newline: /^\n+/,
code: /^( {4}[^\n]+\n*)+/,
fences: noop,
hr: /^( *[-*_]){3,} *(?:\n+|$)/,
hr: /^ {0,3}((?:- *){3,}|(?:_ *){3,}|(?:\* *){3,})(?:\n+|$)/,
heading: /^ *(#{1,6}) *([^\n]+?) *#* *(?:\n+|$)/,
nptable: noop,
blockquote: /^( {0,3}> ?(paragraph|[^\n]*)(?:\n|$))+/,
Expand Down Expand Up @@ -43,7 +43,7 @@ block.item = replace(block.item, 'gm')

block.list = replace(block.list)
(/bull/g, block.bullet)
('hr', '\\n+(?=\\1?(?:[-*_] *){3,}(?:\\n+|$))')
('hr', '\\n+(?=\\1?(?:(?:- *){3,}|(?:_ *){3,}|(?:\\* *){3,})(?:\\n+|$))')
('def', '\\n+(?=' + block.def.source + ')')
();

Expand Down Expand Up @@ -467,11 +467,11 @@ var inline = {
reflink: /^!?\[(inside)\]\s*\[([^\]]*)\]/,
nolink: /^!?\[((?:\[[^\]]*\]|\\[\[\]]|[^\[\]])*)\]/,
strong: /^__([\s\S]+?)__(?!_)|^\*\*([\s\S]+?)\*\*(?!\*)/,
em: /^\b_((?:[^_]|__)+?)_\b|^\*((?:\*\*|[\s\S])+?)\*(?!\*)/,
em: /^_([^\s_](?:[^_]|__)+?[^\s_])_\b|^\*((?:\*\*|[^*])+?)\*(?!\*)/,
code: /^(`+)(\s*)([\s\S]*?[^`]?)\2\1(?!`)/,
br: /^ {2,}\n(?!\s*$)/,
del: noop,
text: /^[\s\S]+?(?=[\\<!\[_*`]| {2,}\n|$)/
text: /^[\s\S]+?(?=[\\<!\[`*]|\b_| {2,}\n|$)/
};

inline._scheme = /[a-zA-Z][a-zA-Z0-9+.-]{1,31}/;
Expand Down
2 changes: 1 addition & 1 deletion test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ function load(options) {
list = fs
.readdirSync(dir)
.filter(function(file) {
return path.extname(file) !== '.html';
return path.extname(file) === '.md';
})
.sort();

Expand Down
106 changes: 106 additions & 0 deletions test/new/cm_thematic_breaks.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
<h1 id="thematic-breaks">Thematic breaks</h1>

<h3 id="example-13">Example 13</h3>

<hr>
<hr>
<hr>

<h3 id="example-14">Example 14</h3>

<p>+++</p>

<h3 id="example-15">Example 15</h3>

<p>===</p>

<h3 id="example-16">Example 16</h3>

<p>--
**
__</p>

<h3 id="example-17">Example 17</h3>

<hr>
<hr>
<hr>

<h3 id="example-18">Example 18</h3>

<pre><code>***
</code></pre>

<h3 id="example-19">Example 19</h3>

<p>Foo
***</p>

<h3 id="example-20">Example 20</h3>

<hr>

<h3 id="example-21">Example 21</h3>

<hr>

<h3 id="example-22">Example 22</h3>

<hr>

<h3 id="example-23">Example 23</h3>

<hr>

<h3 id="example-24">Example 24</h3>

<hr>

<h3 id="example-25">Example 25</h3>

<p>_ _ _ _ a</p>
<p>a------</p>
<p>---a---</p>


<h3 id="example-26">Example 26</h3>

<p> <em>-</em></p>

<h3 id="example-27">Example 27</h3>

<ul>
<li>foo</li>
</ul>
<hr>
<ul>
<li>bar</li>
</ul>

<h3 id="example-28">Example 28</h3>

<p>Foo</p>
<hr>
<p>bar</p>

<h3 id="example-29">Example 29</h3>

<h2 id="foo">Foo</h2>
<p>bar</p>

<h3 id="example-30">Example 30</h3>

<ul>
<li>Foo</li>
</ul>
<hr>
<ul>
<li>Bar</li>
</ul>

<h3 id="example-31">Example 31</h3>

<ul>
<li>Foo</li>
<li><hr></li>
</ul>
98 changes: 98 additions & 0 deletions test/new/cm_thematic_breaks.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
Thematic breaks
===================

### Example 13

***
---
___

### Example 14

+++

### Example 15

===

### Example 16

--
**
__

### Example 17

***
***
***

### Example 18

***

### Example 19

Foo
***

### Example 20

_____________________________________

### Example 21

- - -

### Example 22

** * ** * ** * **

### Example 23

- - - -

### Example 24

- - - -

### Example 25

_ _ _ _ a

a------

---a---

### Example 26

*-*

### Example 27

- foo
***
- bar

### Example 28

Foo
***
bar

### Example 29

Foo
---
bar

### Example 30

* Foo
* * *
* Bar

### Example 31

- Foo
- * * *
14 changes: 14 additions & 0 deletions test/original/horizontal_rules.html
Original file line number Diff line number Diff line change
Expand Up @@ -69,3 +69,17 @@

<pre><code>_ _ _
</code></pre>

<p>Not horizontal rules:</p>
<p>--*</p>
<p>-*-</p>
<p>*--</p>
<p>-_-</p>
<p>__-</p>
<p>-__</p>
<pre><code>_-_
</code></pre>
<p>Long rules:</p>
<hr>
<hr>
<hr>
27 changes: 27 additions & 0 deletions test/original/horizontal_rules.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,3 +65,30 @@ _ _ _
_ _ _

_ _ _



Not horizontal rules:

--*

-*-

*--

-_-

__-

-__

_-_


Long rules:

-----------

___________

***********

0 comments on commit 6b0416d

Please sign in to comment.