@@ -99,6 +99,21 @@ pub struct Delimiter<'a: 'd, 'd> {
9999 next : Cell < Option < & ' d Delimiter < ' a , ' d > > > ,
100100}
101101
102+ impl < ' a : ' d , ' d > std:: fmt:: Debug for Delimiter < ' a , ' d > {
103+ fn fmt ( & self , f : & mut std:: fmt:: Formatter < ' _ > ) -> std:: fmt:: Result {
104+ write ! (
105+ f,
106+ "[pos {}, len {}, delim_char {:?}, open? {} close? {} -- {}]" ,
107+ self . position,
108+ self . length,
109+ self . delim_char,
110+ self . can_open,
111+ self . can_close,
112+ self . inl. data. borrow( ) . sourcepos
113+ )
114+ }
115+ }
116+
102117struct Bracket < ' a > {
103118 inl_text : & ' a AstNode < ' a > ,
104119 position : usize ,
@@ -1136,22 +1151,14 @@ impl<'a, 'r, 'o, 'd, 'i, 'c> Subject<'a, 'r, 'o, 'd, 'i, 'c> {
11361151 self . pos ,
11371152 self . pos ,
11381153 ) ;
1139- {
1140- // if we have `___` or `***` then we need to adjust the sourcepos colums by 1
1141- let triple_adjustment = if opener_num_chars > 0 && use_delims == 2 {
1142- 1
1143- } else {
1144- 0
1145- } ;
11461154
1147- emph. data . borrow_mut ( ) . sourcepos = (
1148- opener. inl . data . borrow ( ) . sourcepos . start . line ,
1149- opener. inl . data . borrow ( ) . sourcepos . start . column + triple_adjustment,
1150- closer. inl . data . borrow ( ) . sourcepos . end . line ,
1151- closer. inl . data . borrow ( ) . sourcepos . end . column - triple_adjustment,
1152- )
1153- . into ( ) ;
1154- }
1155+ emph. data . borrow_mut ( ) . sourcepos = (
1156+ opener. inl . data . borrow ( ) . sourcepos . start . line ,
1157+ opener. inl . data . borrow ( ) . sourcepos . start . column + opener_num_chars,
1158+ closer. inl . data . borrow ( ) . sourcepos . end . line ,
1159+ closer. inl . data . borrow ( ) . sourcepos . end . column - closer_num_chars,
1160+ )
1161+ . into ( ) ;
11551162
11561163 // Drop all the interior AST nodes into the emphasis node
11571164 // and then insert the emphasis node
@@ -1167,18 +1174,21 @@ impl<'a, 'r, 'o, 'd, 'i, 'c> Subject<'a, 'r, 'o, 'd, 'i, 'c> {
11671174 }
11681175 opener. inl . insert_after ( emph) ;
11691176
1170- // Drop the delimiters and return the next closer to process
1171-
1177+ // Drop completely "used up" delimiters, adjust sourcepos of those not,
1178+ // and return the next closest one for processing.
11721179 if opener_num_chars == 0 {
11731180 opener. inl . detach ( ) ;
11741181 self . remove_delimiter ( opener) ;
1182+ } else {
1183+ opener. inl . data . borrow_mut ( ) . sourcepos . end . column -= use_delims;
11751184 }
11761185
11771186 if closer_num_chars == 0 {
11781187 closer. inl . detach ( ) ;
11791188 self . remove_delimiter ( closer) ;
11801189 closer. next . get ( )
11811190 } else {
1191+ closer. inl . data . borrow_mut ( ) . sourcepos . start . column += use_delims;
11821192 Some ( closer)
11831193 }
11841194 }
0 commit comments