Skip to content

Commit

Permalink
fix: no strikethrough on different number of tildes (#1821)
Browse files Browse the repository at this point in the history
Possible Breaking Change: When using the inline.del rule the text is provided in capture group 2 instead of 1.
  • Loading branch information
UziTech authored Nov 15, 2020
1 parent 73f10d3 commit d79f210
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/Tokenizer.js
Original file line number Diff line number Diff line change
Expand Up @@ -585,7 +585,7 @@ module.exports = class Tokenizer {
return {
type: 'del',
raw: cap[0],
text: cap[1]
text: cap[2]
};
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/rules.js
Original file line number Diff line number Diff line change
Expand Up @@ -318,8 +318,8 @@ inline.gfm = merge({}, inline.normal, {
_extended_email: /[A-Za-z0-9._+-]+(@)[a-zA-Z0-9-_]+(?:\.[a-zA-Z0-9-_]*[a-zA-Z0-9])+(?![-_])/,
url: /^((?:ftp|https?):\/\/|www\.)(?:[a-zA-Z0-9\-]+\.?)+[^\s<]*|^email/,
_backpedal: /(?:[^?!.,:;*_~()&]+|\([^)]*\)|&(?![a-zA-Z0-9]+;$)|[?!.,:;*_~)]+(?!$))+/,
del: /^~+(?=\S)([\s\S]*?\S)~+/,
text: /^(`+|[^`])(?:(?= {2,}\n)|[\s\S]*?(?:(?=[\\<!\[`*~]|\b_|https?:\/\/|ftp:\/\/|www\.|$)|[^ ](?= {2,}\n)|[^a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-](?=[a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-]+@))|(?=[a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-]+@))/
del: /^(~~?)(?=[^\s~])([\s\S]*?[^\s~])\1(?=[^~]|$)/,
text: /^([`~]+|[^`~])(?:(?= {2,}\n)|[\s\S]*?(?:(?=[\\<!\[`*~]|\b_|https?:\/\/|ftp:\/\/|www\.|$)|[^ ](?= {2,}\n)|[^a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-](?=[a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-]+@))|(?=[a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-]+@))/
});

inline.gfm.url = edit(inline.gfm.url, 'i')
Expand Down
16 changes: 16 additions & 0 deletions test/specs/new/del_strikethrough.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<p><del>test</del></p>

<p>~~test~</p>

<p>~test~~</p>

<p><del>test</del></p>

<p><del>test
test</del></p>

<p>~~test</p>

<p>test~~</p>

<pre><code class="language-test~~~"></code></pre>
16 changes: 16 additions & 0 deletions test/specs/new/del_strikethrough.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
~~test~~

~~test~

~test~~

~test~

~~test
test~~

~~test

test~~

~~~test~~~

1 comment on commit d79f210

@vercel
Copy link

@vercel vercel bot commented on d79f210 Nov 15, 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.