@@ -1516,6 +1516,7 @@ static int parse_inline(cmark_parser *parser, subject *subj, cmark_node *parent,
1516
1516
cmark_chunk contents ;
1517
1517
unsigned char c ;
1518
1518
bufsize_t startpos , endpos ;
1519
+ bufsize_t initpos = subj -> pos ;
1519
1520
c = peek_char (subj );
1520
1521
if (c == 0 ) {
1521
1522
return 0 ;
@@ -1563,43 +1564,49 @@ static int parse_inline(cmark_parser *parser, subject *subj, cmark_node *parent,
1563
1564
new_inl = handle_close_bracket (parser , subj );
1564
1565
break ;
1565
1566
case '!' :
1566
- advance ( subj );
1567
- if ( peek_char ( subj ) == '[' && peek_char_n (subj , 1 ) != '^' ) {
1567
+ if ( peek_char_n ( subj , 1 ) == '[' && peek_char_n ( subj , 2 ) != '^' ) {
1568
+ advance (subj );
1568
1569
advance (subj );
1569
1570
new_inl = make_str (subj , subj -> pos - 2 , subj -> pos - 1 , cmark_chunk_literal ("![" ));
1570
1571
push_bracket (subj , IMAGE , new_inl );
1571
- } else {
1572
- new_inl = make_str (subj , subj -> pos - 1 , subj -> pos - 1 , cmark_chunk_literal ("!" ));
1573
1572
}
1574
1573
break ;
1575
1574
case '^' :
1576
- advance (subj );
1577
1575
// TODO: Support a name between ^ and [
1578
- if (peek_char (subj ) == '[' ) {
1576
+ if (peek_char_n (subj , 1 ) == '[' ) {
1577
+ advance (subj );
1579
1578
advance (subj );
1580
1579
new_inl = make_str (subj , subj -> pos - 2 , subj -> pos - 1 , cmark_chunk_literal ("^[" ));
1581
1580
push_bracket (subj , ATTRIBUTE , new_inl );
1582
- } else {
1583
- new_inl = make_str (subj , subj -> pos - 1 , subj -> pos - 1 , cmark_chunk_literal ("^" ));
1584
1581
}
1585
1582
break ;
1586
- default :
1587
- new_inl = try_extensions (parser , parent , c , subj );
1588
- if (new_inl != NULL )
1589
- break ;
1583
+ }
1590
1584
1591
- endpos = subject_find_special_char (parser , subj , options );
1592
- contents = cmark_chunk_dup (& subj -> input , subj -> pos , endpos - subj -> pos );
1593
- startpos = subj -> pos ;
1594
- subj -> pos = endpos ;
1585
+ if (subj -> pos == initpos ) {
1586
+ if (!new_inl )
1587
+ new_inl = try_extensions (parser , parent , c , subj );
1595
1588
1596
- // if we're at a newline, strip trailing spaces.
1597
- if ((options & CMARK_OPT_PRESERVE_WHITESPACE ) == 0 && S_is_line_end_char (peek_char (subj ))) {
1598
- cmark_chunk_rtrim (& contents );
1599
- }
1589
+ if (!new_inl ) {
1590
+ if (c == '^' || c == '!' ) {
1591
+ advance (subj );
1592
+ new_inl = make_str (subj , subj -> pos - 1 , subj -> pos - 1 , cmark_chunk_dup (& subj -> input , subj -> pos - 1 , 1 ));
1593
+ } else {
1594
+ endpos = subject_find_special_char (parser , subj , options );
1595
+ contents = cmark_chunk_dup (& subj -> input , subj -> pos , endpos - subj -> pos );
1596
+ startpos = subj -> pos ;
1597
+ subj -> pos = endpos ;
1598
+
1599
+ // if we're at a newline, strip trailing spaces.
1600
+ if ((options & CMARK_OPT_PRESERVE_WHITESPACE ) == 0 && S_is_line_end_char (peek_char (subj ))) {
1601
+ cmark_chunk_rtrim (& contents );
1602
+ }
1600
1603
1601
- new_inl = make_str (subj , startpos , endpos - 1 , contents );
1604
+ if (endpos > startpos )
1605
+ new_inl = make_str (subj , startpos , endpos - 1 , contents );
1606
+ }
1607
+ }
1602
1608
}
1609
+
1603
1610
if (new_inl != NULL ) {
1604
1611
cmark_node_append_child (parent , new_inl );
1605
1612
}
0 commit comments