@@ -1516,6 +1516,7 @@ static int parse_inline(cmark_parser *parser, subject *subj, cmark_node *parent,
15161516  cmark_chunk  contents ;
15171517  unsigned char   c ;
15181518  bufsize_t  startpos , endpos ;
1519+   bufsize_t  initpos  =  subj -> pos ;
15191520  c  =  peek_char (subj );
15201521  if  (c  ==  0 ) {
15211522    return  0 ;
@@ -1563,43 +1564,49 @@ static int parse_inline(cmark_parser *parser, subject *subj, cmark_node *parent,
15631564    new_inl  =  handle_close_bracket (parser , subj );
15641565    break ;
15651566  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 ); 
15681569      advance (subj );
15691570      new_inl  =  make_str (subj , subj -> pos  -  2 , subj -> pos  -  1 , cmark_chunk_literal ("![" ));
15701571      push_bracket (subj , IMAGE , new_inl );
1571-     } else  {
1572-       new_inl  =  make_str (subj , subj -> pos  -  1 , subj -> pos  -  1 , cmark_chunk_literal ("!" ));
15731572    }
15741573    break ;
15751574  case  '^' :
1576-     advance (subj );
15771575    // TODO: Support a name between ^ and [ 
1578-     if  (peek_char (subj ) ==  '[' ) {
1576+     if  (peek_char_n (subj , 1 ) ==  '[' ) {
1577+       advance (subj );
15791578      advance (subj );
15801579      new_inl  =  make_str (subj , subj -> pos  -  2 , subj -> pos  -  1 , cmark_chunk_literal ("^[" ));
15811580      push_bracket (subj , ATTRIBUTE , new_inl );
1582-     } else  {
1583-       new_inl  =  make_str (subj , subj -> pos  -  1 , subj -> pos  -  1 , cmark_chunk_literal ("^" ));
15841581    }
15851582    break ;
1586-   default :
1587-     new_inl  =  try_extensions (parser , parent , c , subj );
1588-     if  (new_inl  !=  NULL )
1589-       break ;
1583+   }
15901584
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 );
15951588
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+         }
16001603
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+     }
16021608  }
1609+ 
16031610  if  (new_inl  !=  NULL ) {
16041611    cmark_node_append_child (parent , new_inl );
16051612  }
0 commit comments