11diff --git a/cpp/md4c/md4c.c b/cpp/md4c/md4c.c
22--- a/cpp/md4c/md4c.c
33+++ b/cpp/md4c/md4c.c
4- @@ -3909,7 +3909,7 @@ md_analyze_permissive_autolink(MD_CTX* ctx, int mark_index)
4+ @@ -3908,10 +3908,10 @@
5+ int min_components;
56 const MD_CHAR optional_end_char;
67 } URL_MAP[] = {
7- { _T('\0'), _T('.'), _T(".-_"), 2, _T('\0') }, /* host, mandatory */
8+ - { _T('\0'), _T('.'), _T(".-_"), 2, _T('\0') }, /* host, mandatory */
89- { _T('/'), _T('/'), _T("/.-_"), 0, _T('/') }, /* path */
9- + { _T('/'), _T('/'), _T("/.-_()"), 0, _T('/') }, /* path */
10- { _T('?'), _T('&'), _T("&.-+_=()"), 1, _T('\0') }, /* query */
11- { _T('#'), _T('\0'), _T(".-+_") , 1, _T('\0') } /* fragment */
10+ - { _T('?'), _T('&'), _T("&.-+_=()"), 1, _T('\0') }, /* query */
11+ - { _T('#'), _T('\0'), _T(".-+_") , 1, _T('\0') } /* fragment */
12+ + { _T('\0'), _T('.'), _T(".-_"), 2, _T('\0') }, /* host, mandatory */
13+ + { _T('/'), _T('/'), _T("/.-_():~%+@&!,;"), 0, _T('/') }, /* path */
14+ + { _T('?'), _T('&'), _T("&.-+_=().:!~%,;@"), 1, _T('\0') }, /* query */
15+ + { _T('#'), _T('\0'), _T(".-+_:%~") , 1, _T('\0') } /* fragment */
1216 };
13- @@ -4006,9 +4006,20 @@ md_analyze_permissive_autolink(MD_CTX* ctx, int mark_index)
17+
18+ MD_MARK* opener = &ctx->marks[mark_index];
19+ @@ -3981,8 +3981,11 @@
20+ } else if(end < line_end &&
21+ ISANYOF(end, URL_MAP[i].allowed_nonalnum_chars) &&
22+ md_scan_right_for_resolved_mark(ctx, right_cursor, end, &right_cursor) == NULL &&
23+ - ((end > line_beg && (ISALNUM(end-1) || CH(end-1) == _T(')'))) || CH(end) == _T('(')) &&
24+ - ((end+1 < line_end && (ISALNUM(end+1) || CH(end+1) == _T('('))) || CH(end) == _T(')')))
25+ + /* Scheme URLs keep '...' and ':' in the path and query.
26+ + * Host, e-mail, and www labels stay flanked by alphanumerics. */
27+ + ((opener->ch == _T(':') && i > 0) ||
28+ + (((end > line_beg && (ISALNUM(end-1) || CH(end-1) == _T(')'))) || CH(end) == _T('(')) &&
29+ + ((end+1 < line_end && (ISALNUM(end+1) || CH(end+1) == _T('('))) || CH(end) == _T(')')))))
30+ {
31+ if(CH(end) == URL_MAP[i].delim_char)
32+ n_components++;
33+ @@ -4006,16 +4009,35 @@
1434 CH(end) == URL_MAP[i].optional_end_char)
1535 end++;
1636
@@ -31,4 +51,20 @@ diff --git a/cpp/md4c/md4c.c b/cpp/md4c/md4c.c
3151+
3252 if(opener->ch == '@') /* E-mail autolinks wants only the host. */
3353 break;
54+ + }
55+ +
56+ + /* GFM leaves a trailing run of punctuation outside the link, including
57+ + * the sentence dots in "https://example.com/a...". */
58+ + if(opener->ch == _T(':')) {
59+ + while(end > opener->end && ISANYOF(end - 1, _T("?!.,:*_~")))
60+ + end--;
3461 }
62+
63+ /* Verify there's line boundary, whitespace, allowed punctuation or
64+ * resolved emphasis mark just after the suspected autolink. */
65+ - if(end == line_end || ISUNICODEWHITESPACE(end) || ISANYOF(end, _T(")}].!?,;"))) {
66+ + if(end == line_end || ISUNICODEWHITESPACE(end) ||
67+ + ISANYOF(end, opener->ch == _T(':') ? _T(")}].!?,;:*_~'\"`<>") : _T(")}].!?,;"))) {
68+ right_boundary_ok = TRUE;
69+ } else {
70+ MD_MARK* right_mark;
0 commit comments