@@ -194,21 +194,22 @@ impl<'a> PageRenderer<'a> {
194
194
// We don't have the max length. Just print the entire line then.
195
195
return Cow :: Borrowed ( s) ;
196
196
} ;
197
+
197
198
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;
198
205
199
- if len_indent + s. width ( ) <= max_len {
206
+ if base_width + s. width ( ) <= max_len {
200
207
// The line is shorter than the max length. There is nothing to do.
201
208
return Cow :: Borrowed ( s) ;
202
209
}
203
210
204
211
let words = s. split ( ' ' ) ;
205
212
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;
212
213
let mut cur_width = base_width;
213
214
// current_len + base_width * amount of added newlines
214
215
let mut buf = String :: with_capacity ( len_s + base_width * ( len_s / max_len) ) ;
@@ -402,17 +403,16 @@ impl<'a> PageRenderer<'a> {
402
403
/// Write the current line to the page buffer as a bullet point.
403
404
fn add_bullet ( & mut self ) -> Result < ( ) > {
404
405
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 ) ;
413
408
414
409
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}" ) ?;
416
416
417
417
Ok ( ( ) )
418
418
}
0 commit comments