Skip to content

Commit 30c6630

Browse files
authored
fix: allow escaped newline in link text (#3752)
* fix: allow ecaped newline in link text * use [\s\S]
1 parent 0ccf476 commit 30c6630

File tree

3 files changed

+30
-4
lines changed

3 files changed

+30
-4
lines changed

src/rules.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ const lheadingGfm = edit(lheadingCore)
106106
.getRegex();
107107
const _paragraph = /^([^\n]+(?:\n(?!hr|heading|lheading|blockquote|fences|list|html|table| +\n)[^\n]+)*)/;
108108
const blockText = /^[^\n]+/;
109-
const _blockLabel = /(?!\s*\])(?:\\.|[^\[\]\\])+/;
109+
const _blockLabel = /(?!\s*\])(?:\\[\s\S]|[^\[\]\\])+/;
110110
const def = edit(/^ {0,3}\[(label)\]: *(?:\n[ \t]*)?([^<\s][^\s]*|<.*?>)(?:(?: +(?:\n[ \t]*)?| *\n[ \t]*)(title))? *(?:\n+|$)/)
111111
.replace('label', _blockLabel)
112112
.replace('title', /(?:"(?:\\"?|[^"\\])*"|'[^'\n]*(?:\n[^'\n]+)*\n?'|\([^()]*\))/)
@@ -267,7 +267,7 @@ const _punctuationOrSpaceGfmStrongEm = /(?!~)[\s\p{P}\p{S}]/u;
267267
const _notPunctuationOrSpaceGfmStrongEm = /(?:[^\s\p{P}\p{S}]|~)/u;
268268

269269
// sequences em should skip over [title](link), `code`, <html>
270-
const blockSkip = /\[[^[\]]*?\]\((?:\\.|[^\\\(\)]|\((?:\\.|[^\\\(\)])*\))*\)|`[^`]*?`|<(?! )[^<>]*?>/g;
270+
const blockSkip = /\[[^\[\]]*?\]\((?:\\[\s\S]|[^\\\(\)]|\((?:\\[\s\S]|[^\\\(\)])*\))*\)|`[^`]*?`|<(?! )[^<>]*?>/g;
271271

272272
const emStrongLDelimCore = /^(?:\*+(?:((?!\*)punct)|[^\s*]))|^_+(?:((?!_)punct)|([^\s_]))/;
273273

@@ -336,7 +336,7 @@ const tag = edit(
336336
.replace('attribute', /\s+[a-zA-Z:_][\w.:-]*(?:\s*=\s*"[^"]*"|\s*=\s*'[^']*'|\s*=\s*[^\s"'=<>`]+)?/)
337337
.getRegex();
338338

339-
const _inlineLabel = /(?:\[(?:\\.|[^\[\]\\])*\]|\\.|`[^`]*`|[^\[\]\\`])*?/;
339+
const _inlineLabel = /(?:\[(?:\\[\s\S]|[^\[\]\\])*\]|\\[\s\S]|`[^`]*`|[^\[\]\\`])*?/;
340340

341341
const link = edit(/^!?\[(label)\]\(\s*(href)(?:(?:[ \t]*(?:\n[ \t]*)?)(title))?\s*\)/)
342342
.replace('label', _inlineLabel)
@@ -412,7 +412,7 @@ const inlineGfm: Record<InlineKeys, RegExp> = {
412412
.replace('email', /[A-Za-z0-9._+-]+(@)[a-zA-Z0-9-_]+(?:\.[a-zA-Z0-9-_]*[a-zA-Z0-9])+(?![-_])/)
413413
.getRegex(),
414414
_backpedal: /(?:[^?!.,:;*_'"~()&]+|\([^)]*\)|&(?![a-zA-Z0-9]+;$)|[?!.,:;*_'"~)]+(?!$))+/,
415-
del: /^(~~?)(?=[^\s~])((?:\\.|[^\\])*?(?:\\.|[^\s~\\]))\1(?=[^~]|$)/,
415+
del: /^(~~?)(?=[^\s~])((?:\\[\s\S]|[^\\])*?(?:\\[\s\S]|[^\s~\\]))\1(?=[^~]|$)/,
416416
text: /^([`~]+|[^`~])(?:(?= {2,}\n)|(?=[a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-]+@)|[\s\S]*?(?:(?=[\\<!\[`*~_]|\b_|https?:\/\/|ftp:\/\/|www\.|$)|[^ ](?= {2,}\n)|[^a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-](?=[a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-]+@)))/,
417417
};
418418

test/specs/new/escape_newline.html

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<p>
2+
<a href="https://example.com">foo<br />
3+
bar</a>
4+
</p>
5+
6+
<p>
7+
<a href="https://example2.com">foo2<br />
8+
bar2</a>
9+
</p>
10+
11+
<p>
12+
<a href="https://example.com">foo3<br />
13+
bar3</a>
14+
</p>

test/specs/new/escape_newline.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
[foo\
2+
bar]
3+
4+
[foo\
5+
bar]: https://example.com
6+
7+
[foo2\
8+
bar2](https://example2.com)
9+
10+
[foo3\
11+
bar3][foo\
12+
bar]

0 commit comments

Comments
 (0)