From 1c780b9985e533257cfd105035168f8ace002db2 Mon Sep 17 00:00:00 2001 From: kythyria Date: Tue, 29 Nov 2016 14:59:29 +0000 Subject: [PATCH 1/3] Fix the regexes for thematic breaks Commonmark and GFM both agree that -_- is literal characters, not
, as all three characters must be the same. Also change the test harness to only look for .text and .html files since it was choking on vim's swapfiles. And add some tests to catch what this fixes. --- lib/marked.js | 4 ++-- test/index.js | 2 +- test/original/horizontal_rules.html | 14 ++++++++++++++ test/original/horizontal_rules.md | 27 +++++++++++++++++++++++++++ 4 files changed, 44 insertions(+), 3 deletions(-) diff --git a/lib/marked.js b/lib/marked.js index 63d45eb3af..f3243b53d1 100644 --- a/lib/marked.js +++ b/lib/marked.js @@ -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|$))+/, @@ -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 + ')') (); diff --git a/test/index.js b/test/index.js index 491ae6b9c0..e3741069f5 100644 --- a/test/index.js +++ b/test/index.js @@ -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(); diff --git a/test/original/horizontal_rules.html b/test/original/horizontal_rules.html index 2dc2ab6565..b84ba925f6 100644 --- a/test/original/horizontal_rules.html +++ b/test/original/horizontal_rules.html @@ -69,3 +69,17 @@
_ _ _
 
+ +

Not horizontal rules:

+

--*

+

-*-

+

*--

+

-_-

+

__-

+

-__

+
_-_
+
+

Long rules:

+
+
+
diff --git a/test/original/horizontal_rules.md b/test/original/horizontal_rules.md index 1594bda27b..49bbcfad4d 100644 --- a/test/original/horizontal_rules.md +++ b/test/original/horizontal_rules.md @@ -65,3 +65,30 @@ _ _ _ _ _ _ _ _ _ + + + +Not horizontal rules: + +--* + +-*- + +*-- + + -_- + + __- + + -__ + + _-_ + + +Long rules: + +----------- + +___________ + +*********** From 2ea539ad67ab7255c068b58db1d65741a62345d4 Mon Sep 17 00:00:00 2001 From: Federico Soave Date: Thu, 25 Jan 2018 16:48:33 +0100 Subject: [PATCH 2/3] add commonmark test for thematic breaks --- test/new/cm_thematic_breaks.html | 106 +++++++++++++++++++++++++++++++ test/new/cm_thematic_breaks.md | 98 ++++++++++++++++++++++++++++ 2 files changed, 204 insertions(+) create mode 100644 test/new/cm_thematic_breaks.html create mode 100644 test/new/cm_thematic_breaks.md diff --git a/test/new/cm_thematic_breaks.html b/test/new/cm_thematic_breaks.html new file mode 100644 index 0000000000..ec3f9f7462 --- /dev/null +++ b/test/new/cm_thematic_breaks.html @@ -0,0 +1,106 @@ +

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

+ + +
+ + +

Example 28

+ +

Foo

+
+

bar

+ +

Example 29

+ +

Foo

+

bar

+ +

Example 30

+ + +
+ + +

Example 31

+ + \ No newline at end of file diff --git a/test/new/cm_thematic_breaks.md b/test/new/cm_thematic_breaks.md new file mode 100644 index 0000000000..af28f8dd73 --- /dev/null +++ b/test/new/cm_thematic_breaks.md @@ -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 +- * * * From b8437b0742ca2cb525686401eb9e15bd34639259 Mon Sep 17 00:00:00 2001 From: Federico Soave Date: Thu, 25 Jan 2018 05:49:48 +0100 Subject: [PATCH 3/3] fix underscore emphasis (apply commonmark flanking rule and rule 12) --- lib/marked.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/marked.js b/lib/marked.js index f3243b53d1..e5c275141a 100644 --- a/lib/marked.js +++ b/lib/marked.js @@ -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]+?(?=[\\