md_analyze_permissive_autolink: Check left boundary asap.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48
diff --git a/src/md4c.c b/src/md4c.c
index d4cb364..98cdd8f 100644
--- a/src/md4c.c
+++ b/src/md4c.c
@@ -3937,6 +3937,20 @@ md_analyze_permissive_autolink(MD_CTX* ctx, int mark_index)
return;
}
+ /* Verify there's line boundary, whitespace, allowed punctuation or
+ * resolved emphasis mark just before the suspected autolink. */
+ if(beg == line_beg || ISUNICODEWHITESPACEBEFORE(beg) || ISANYOF(beg-1, _T("({["))) {
+ left_boundary_ok = TRUE;
+ } else if(ISANYOF(beg-1, _T("*_~"))) {
+ MD_MARK* left_mark;
+
+ left_mark = md_scan_left_for_resolved_mark(ctx, left_cursor, beg-1, &left_cursor);
+ if(left_mark != NULL && (left_mark->flags & MD_MARK_OPENER))
+ left_boundary_ok = TRUE;
+ }
+ if(!left_boundary_ok)
+ return;
+
for(i = 0; i < SIZEOF_ARRAY(URL_MAP); i++) {
int n_components = 0;
int n_open_brackets = 0;
@@ -3989,20 +4003,8 @@ md_analyze_permissive_autolink(MD_CTX* ctx, int mark_index)
break;
}
- /* Verify there's line boundary, whitespace or resolved emphasis mark just
- * before and after the suspected autolink. */
- if(beg == line_beg || ISUNICODEWHITESPACEBEFORE(beg) || ISANYOF(beg-1, _T("({["))) {
- left_boundary_ok = TRUE;
- } else if(ISANYOF(beg-1, _T("*_~"))) {
- MD_MARK* left_mark;
-
- left_mark = md_scan_left_for_resolved_mark(ctx, left_cursor, beg-1, &left_cursor);
- if(left_mark != NULL && (left_mark->flags & MD_MARK_OPENER))
- left_boundary_ok = TRUE;
- }
- if(!left_boundary_ok)
- return;
-
+ /* Verify there's line boundary, whitespace, allowed punctuation or
+ * resolved emphasis mark just after the suspected autolink. */
if(end == line_end || ISUNICODEWHITESPACE(end) || ISANYOF(end, _T(")}].!?,;"))) {
right_boundary_ok = TRUE;
} else {