@@ -57,6 +57,7 @@ typedef struct subject{
57
57
bracket * last_bracket ;
58
58
bufsize_t backticks [MAXBACKTICKS + 1 ];
59
59
bool scanned_for_backticks ;
60
+ bool no_link_openers ;
60
61
} subject ;
61
62
62
63
// Extensions may populate this.
@@ -174,6 +175,7 @@ static void subject_from_buf(cmark_mem *mem, int line_number, int block_offset,
174
175
e -> backticks [i ] = 0 ;
175
176
}
176
177
e -> scanned_for_backticks = false;
178
+ e -> no_link_openers = true;
177
179
}
178
180
179
181
static CMARK_INLINE int isbacktick (int c ) { return (c == '`' ); }
@@ -534,6 +536,9 @@ static void push_bracket(subject *subj, bool image, cmark_node *inl_text) {
534
536
b -> in_bracket_image0 = true;
535
537
}
536
538
subj -> last_bracket = b ;
539
+ if (!image ) {
540
+ subj -> no_link_openers = false;
541
+ }
537
542
}
538
543
539
544
// Assumes the subject has a c at the current position.
@@ -1065,16 +1070,16 @@ static cmark_node *handle_close_bracket(cmark_parser *parser, subject *subj) {
1065
1070
return make_str (subj , subj -> pos - 1 , subj -> pos - 1 , cmark_chunk_literal ("]" ));
1066
1071
}
1067
1072
1068
- if (!opener -> active ) {
1073
+ // If we got here, we matched a potential link/image text.
1074
+ // Now we check to see if it's a link/image.
1075
+ is_image = opener -> image ;
1076
+
1077
+ if (!is_image && subj -> no_link_openers ) {
1069
1078
// take delimiter off stack
1070
1079
pop_bracket (subj );
1071
1080
return make_str (subj , subj -> pos - 1 , subj -> pos - 1 , cmark_chunk_literal ("]" ));
1072
1081
}
1073
1082
1074
- // If we got here, we matched a potential link/image text.
1075
- // Now we check to see if it's a link/image.
1076
- is_image = opener -> image ;
1077
-
1078
1083
after_link_text_pos = subj -> pos ;
1079
1084
1080
1085
// First, look for an inline link.
@@ -1248,32 +1253,11 @@ static cmark_node *handle_close_bracket(cmark_parser *parser, subject *subj) {
1248
1253
process_emphasis (parser , subj , opener -> previous_delimiter );
1249
1254
pop_bracket (subj );
1250
1255
1251
- // Now, if we have a link, we also want to deactivate earlier link
1252
- // delimiters . (This code can be removed if we decide to allow links
1256
+ // Now, if we have a link, we also want to deactivate links until
1257
+ // we get a new opener . (This code can be removed if we decide to allow links
1253
1258
// inside links.)
1254
1259
if (!is_image ) {
1255
- opener = subj -> last_bracket ;
1256
- while (opener != NULL ) {
1257
- if (!opener -> image ) {
1258
- if (!opener -> active ) {
1259
- break ;
1260
- } else {
1261
- opener -> active = false;
1262
- }
1263
- }
1264
- opener = opener -> previous ;
1265
- }
1266
- bool in_bracket_image1 = false;
1267
- if (opener ) {
1268
- in_bracket_image1 = opener -> in_bracket_image1 ;
1269
- }
1270
- bracket * opener2 = subj -> last_bracket ;
1271
- while (opener2 != opener ) {
1272
- if (opener2 -> image ) {
1273
- opener2 -> in_bracket_image1 = in_bracket_image1 ;
1274
- }
1275
- opener2 = opener2 -> previous ;
1276
- }
1260
+ subj -> no_link_openers = true;
1277
1261
}
1278
1262
1279
1263
return NULL ;
0 commit comments