Code blocks get rendered without line breaks (#122)
This commit is contained in:
@@ -17,6 +17,7 @@ pub struct TextPrinter<'a> {
|
||||
alignment: Alignment,
|
||||
curr_spans: Vec<Span<'a>>,
|
||||
curr_width: usize,
|
||||
literal: bool,
|
||||
}
|
||||
|
||||
impl<'a> TextPrinter<'a> {
|
||||
@@ -30,6 +31,7 @@ impl<'a> TextPrinter<'a> {
|
||||
alignment: Alignment::Left,
|
||||
curr_spans: vec![],
|
||||
curr_width: 0,
|
||||
literal: false,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -38,6 +40,11 @@ impl<'a> TextPrinter<'a> {
|
||||
self
|
||||
}
|
||||
|
||||
pub fn literal(mut self, literal: bool) -> Self {
|
||||
self.literal = literal;
|
||||
self
|
||||
}
|
||||
|
||||
pub fn hide_reply(&self) -> bool {
|
||||
self.hide_reply
|
||||
}
|
||||
@@ -56,6 +63,7 @@ impl<'a> TextPrinter<'a> {
|
||||
alignment: self.alignment,
|
||||
curr_spans: vec![],
|
||||
curr_width: 0,
|
||||
literal: self.literal,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -162,11 +170,16 @@ impl<'a> TextPrinter<'a> {
|
||||
|
||||
for mut word in UnicodeSegmentation::split_word_bounds(s) {
|
||||
if let "\n" | "\r\n" = word {
|
||||
if self.literal {
|
||||
self.commit();
|
||||
continue;
|
||||
}
|
||||
|
||||
// Render embedded newlines as spaces.
|
||||
word = " ";
|
||||
}
|
||||
|
||||
if self.curr_width == 0 && word.chars().all(char::is_whitespace) {
|
||||
if !self.literal && self.curr_width == 0 && word.chars().all(char::is_whitespace) {
|
||||
// Drop leading whitespace.
|
||||
continue;
|
||||
}
|
||||
@@ -182,7 +195,7 @@ impl<'a> TextPrinter<'a> {
|
||||
// Word doesn't fit on this line, so start a new one.
|
||||
self.commit();
|
||||
|
||||
if word.chars().all(char::is_whitespace) {
|
||||
if !self.literal && word.chars().all(char::is_whitespace) {
|
||||
// Drop leading whitespace.
|
||||
continue;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user