@@ -194,21 +194,22 @@ impl<'a> PageRenderer<'a> {
194194 // We don't have the max length. Just print the entire line then.
195195 return Cow :: Borrowed ( s) ;
196196 } ;
197+
197198 let len_indent = indent. len ( ) ;
199+ let prefix_width = if ltype == LineType :: Bullet && self . cfg . output . show_hyphens {
200+ self . cfg . output . example_prefix . width ( )
201+ } else {
202+ 0
203+ } ;
204+ let base_width = len_indent + prefix_width;
198205
199- if len_indent + s. width ( ) <= max_len {
206+ if base_width + s. width ( ) <= max_len {
200207 // The line is shorter than the max length. There is nothing to do.
201208 return Cow :: Borrowed ( s) ;
202209 }
203210
204211 let words = s. split ( ' ' ) ;
205212 let len_s = s. len ( ) ;
206- let prefix_width = if ltype == LineType :: Bullet && self . cfg . output . show_hyphens {
207- self . cfg . output . example_prefix . width ( )
208- } else {
209- 0
210- } ;
211- let base_width = len_indent + prefix_width;
212213 let mut cur_width = base_width;
213214 // current_len + base_width * amount of added newlines
214215 let mut buf = String :: with_capacity ( len_s + base_width * ( len_s / max_len) ) ;
@@ -402,17 +403,16 @@ impl<'a> PageRenderer<'a> {
402403 /// Write the current line to the page buffer as a bullet point.
403404 fn add_bullet ( & mut self ) -> Result < ( ) > {
404405 let indent = " " . repeat ( self . cfg . indent . bullet ) ;
405- let line = if self . cfg . output . show_hyphens {
406- self . current_line
407- . replace_range ( ..2 , & self . cfg . output . example_prefix ) ;
408- self . splitln ( & self . current_line , & indent, LineType :: Bullet )
409- } else {
410- let l = self . current_line . strip_prefix ( BULLET ) . unwrap ( ) ;
411- self . splitln ( l, & indent, LineType :: Bullet )
412- } ;
406+ let line = self . current_line . strip_prefix ( BULLET ) . unwrap ( ) ;
407+ let line = self . splitln ( line, & indent, LineType :: Bullet ) ;
413408
414409 let bullet = self . hl_code ( & self . hl_url ( & line, self . style . bullet ) , self . style . bullet ) ;
415- writeln ! ( self . stdout, "{indent}{bullet}" ) ?;
410+ write ! ( self . stdout, "{indent}" ) ?;
411+ if self . cfg . output . show_hyphens {
412+ let prefix = self . cfg . output . example_prefix . paint ( self . style . bullet ) ;
413+ write ! ( self . stdout, "{prefix}" ) ?;
414+ }
415+ writeln ! ( self . stdout, "{bullet}" ) ?;
416416
417417 Ok ( ( ) )
418418 }
0 commit comments