+ fn finish(mut self) -> String {
+ if !self.code_block_buffer.is_empty() {
+ // There is a code block that is not properly enclosed by backticks.
+ // We will leave them untouched.
+ self.result.push_str(&self.comment_line_separator);
+ self.result.push_str(&Self::join_block(
+ &trim_custom_comment_prefix(&self.code_block_buffer),
+ &self.comment_line_separator,
+ ));
+ }
+
+ if let Some(ref ib) = self.item_block {
+ // the last few lines are part of an itemized block
+ self.fmt.shape = Shape::legacy(self.max_width, self.fmt_indent);
+ let item_fmt = ib.create_string_format(&self.fmt);
+ self.result.push_str(&self.comment_line_separator);
+ self.result.push_str(&ib.opener);
+ match rewrite_string(
+ &ib.trimmed_block_as_string(),
+ &item_fmt,
+ self.max_width.saturating_sub(ib.indent),
+ ) {
+ Some(s) => self.result.push_str(&Self::join_block(
+ &s,
+ &format!("{}{}", self.comment_line_separator, ib.line_start),
+ )),
+ None => self.result.push_str(&Self::join_block(
+ &ib.original_block_as_string(),
+ &self.comment_line_separator,
+ )),
+ };
+ }
+
+ self.result.push_str(&self.closer);
+ if self.result.ends_with(&self.opener) && self.opener.ends_with(' ') {
+ // Trailing space.
+ self.result.pop();
+ }
+
+ self.result
+ }
+
+ fn handle_line(
+ &mut self,
+ orig: &'a str,
+ i: usize,
+ line: &'a str,
+ has_leading_whitespace: bool,
+ ) -> bool {