Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions crates/jp_md/src/format_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1342,6 +1342,22 @@ fn test_thematic_break_line_style_ignores_terminal_width() {
);
}

#[test]
fn test_thematic_break_line_style_fits_inside_a_blockquote() {
// A blockquote's `> ` narrows the text column by two. A rule that ignored
// the prefix would overflow the line and wrap.
let mut formatter = Formatter::with_width(40);
formatter.hr_style = HrStyle::Line;

let actual = formatter
.format_terminal("> above\n>\n> ---\n>\n> below")
.unwrap();
assert!(
actual.contains(&"─".repeat(38)) && !actual.contains(&"─".repeat(39)),
"Expected a 38-char unicode line inside the quote.\nActual: {actual:?}"
);
}

#[test]
fn test_table_is_fitted_to_the_terminal_width() {
// A table is laid out, not wrapped, so it has to fit the terminal on its
Expand Down
7 changes: 5 additions & 2 deletions crates/jp_md/src/render.rs
Original file line number Diff line number Diff line change
Expand Up @@ -503,8 +503,11 @@ impl<'a, 'w> TerminalFormatter<'a, 'w> {
}
HrStyle::Line => {
// A rule spans the text column, not the terminal, so it lines up
// with the wrapped prose above and below it.
let line: String = "─".repeat(self.writer.width.max(1));
// with the wrapped prose above and below it. Inside a
// blockquote or a list item that column is narrowed by the
// prefix each line carries.
let width = self.writer.width.saturating_sub(self.writer.prefix_width());
let line: String = "─".repeat(width.max(1));
self.writer.output(&line, false)?;
}
}
Expand Down
Loading