@@ -411,7 +411,7 @@ static int scan_delims(cmark_parser *parser, subject *subj, unsigned char c,
411411 before_char = 10 ;
412412 } else {
413413 before_char_pos = subj -> pos - 1 ;
414-
414+
415415 // walk back to the beginning of the UTF_8 sequence:
416416 while ((peek_at (subj , before_char_pos ) >> 6 == 2 || parser -> skip_chars [peek_at (subj , before_char_pos )]) && before_char_pos > 0 ) {
417417 before_char_pos -= 1 ;
@@ -437,7 +437,7 @@ static int scan_delims(cmark_parser *parser, subject *subj, unsigned char c,
437437 after_char = 10 ;
438438 } else {
439439 after_char_pos = subj -> pos ;
440-
440+
441441 while (parser -> skip_chars [peek_at (subj , after_char_pos )] && after_char_pos < subj -> input .len ) {
442442 after_char_pos += 1 ;
443443 }
@@ -944,7 +944,7 @@ static int link_label(subject *subj, cmark_chunk *raw_label, bool parse_attribut
944944 bufsize_t startpos = subj -> pos ;
945945 int length = 0 ;
946946 unsigned char c ;
947-
947+
948948 // If we are parsing attribute label, advance past ^
949949 if (parse_attribute_label ) {
950950 if (peek_char (subj ) == '^' ) {
@@ -1130,14 +1130,14 @@ static cmark_node *handle_close_bracket_attribute(cmark_parser *parser, subject
11301130 }
11311131 }
11321132 }
1133-
1133+
11341134 // If we can't match direct link, look for [link label] that matches in refmap
11351135 raw_label = cmark_chunk_literal ("" );
11361136 found_label = link_label (subj , & raw_label , false);
11371137 if (found_label ) {
11381138 ref = (cmark_reference * )cmark_map_lookup (subj -> refmap , & raw_label );
11391139 cmark_chunk_free (subj -> mem , & raw_label );
1140-
1140+
11411141 if (ref && ref -> is_attributes_reference ) {
11421142 isAttributesNode = true;
11431143 attributes = chunk_clone (subj -> mem , & ref -> attributes );
@@ -1149,7 +1149,7 @@ static cmark_node *handle_close_bracket_attribute(cmark_parser *parser, subject
11491149 pop_bracket (subj );
11501150 return make_str (subj , subj -> pos - 1 , subj -> pos - 1 , cmark_chunk_literal ("]" ));
11511151 }
1152-
1152+
11531153 inl = make_simple (subj -> mem , CMARK_NODE_ATTRIBUTE );
11541154 inl -> as .attribute .attributes = attributes ;
11551155 inl -> start_line = inl -> end_line = subj -> line ;
@@ -1564,6 +1564,7 @@ static int parse_inline(cmark_parser *parser, subject *subj, cmark_node *parent,
15641564 new_inl = handle_close_bracket (parser , subj );
15651565 break ;
15661566 case '!' :
1567+ // specifically check for '![' not followed by '^'
15671568 if (peek_char_n (subj , 1 ) == '[' && peek_char_n (subj , 2 ) != '^' ) {
15681569 advance (subj );
15691570 advance (subj );
@@ -1573,6 +1574,7 @@ static int parse_inline(cmark_parser *parser, subject *subj, cmark_node *parent,
15731574 break ;
15741575 case '^' :
15751576 // TODO: Support a name between ^ and [
1577+ // specifically check for '^['
15761578 if (peek_char_n (subj , 1 ) == '[' ) {
15771579 advance (subj );
15781580 advance (subj );
@@ -1587,11 +1589,11 @@ static int parse_inline(cmark_parser *parser, subject *subj, cmark_node *parent,
15871589 new_inl = try_extensions (parser , parent , c , subj );
15881590
15891591 if (!new_inl ) {
1590- if (c == '^' || c == '!' ) {
1592+ endpos = subject_find_special_char (parser , subj , options );
1593+ if (endpos == subj -> pos ) {
15911594 advance (subj );
15921595 new_inl = make_str (subj , subj -> pos - 1 , subj -> pos - 1 , cmark_chunk_dup (& subj -> input , subj -> pos - 1 , 1 ));
15931596 } else {
1594- endpos = subject_find_special_char (parser , subj , options );
15951597 contents = cmark_chunk_dup (& subj -> input , subj -> pos , endpos - subj -> pos );
15961598 startpos = subj -> pos ;
15971599 subj -> pos = endpos ;
@@ -1601,8 +1603,7 @@ static int parse_inline(cmark_parser *parser, subject *subj, cmark_node *parent,
16011603 cmark_chunk_rtrim (& contents );
16021604 }
16031605
1604- if (endpos > startpos )
1605- new_inl = make_str (subj , startpos , endpos - 1 , contents );
1606+ new_inl = make_str (subj , startpos , endpos - 1 , contents );
16061607 }
16071608 }
16081609 }
@@ -1715,27 +1716,27 @@ bufsize_t cmark_parse_reference_inline(cmark_mem *mem, cmark_chunk *input,
17151716bufsize_t cmark_parse_reference_attributes_inline (cmark_mem * mem , cmark_chunk * input ,
17161717 cmark_map * refmap ) {
17171718 subject subj ;
1718-
1719+
17191720 cmark_chunk lab ;
17201721 cmark_chunk attributes ;
1721-
1722+
17221723 bufsize_t matchlen = 0 ;
17231724 unsigned char c ;
1724-
1725+
17251726 subject_from_buf (mem , -1 , 0 , & subj , input , NULL );
1726-
1727+
17271728 // parse attribute label:
17281729 if (!link_label (& subj , & lab , true) || lab .len == 0 ) {
17291730 return 0 ;
17301731 }
1731-
1732+
17321733 // Colon:
17331734 if (peek_char (& subj ) == ':' ) {
17341735 advance (& subj );
17351736 } else {
17361737 return 0 ;
17371738 }
1738-
1739+
17391740 // parse attributes
17401741 spnl (& subj );
17411742 // read until next newline
@@ -1744,19 +1745,19 @@ bufsize_t cmark_parse_reference_attributes_inline(cmark_mem *mem, cmark_chunk *i
17441745 advance (& subj );
17451746 matchlen ++ ;
17461747 }
1747-
1748+
17481749 if (matchlen == 0 ) {
17491750 return 0 ;
17501751 }
1751-
1752+
17521753 attributes = cmark_chunk_dup (& subj .input , startpos , matchlen );
1753-
1754+
17541755 // parse final spaces and newline:
17551756 skip_spaces (& subj );
17561757 if (!skip_line_end (& subj )) {
17571758 return 0 ;
17581759 }
1759-
1760+
17601761 // insert reference into refmap
17611762 cmark_reference_create_attributes (refmap , & lab , & attributes );
17621763 return subj .pos ;
0 commit comments