Skip to content

Commit f972794

Browse files
committed
Add markdown table formatting
1 parent cf7dca3 commit f972794

File tree

2 files changed

+29
-0
lines changed

2 files changed

+29
-0
lines changed

examples/formatting.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,16 @@ fn main() {
4141
table.printstd();
4242
println!("");
4343

44+
// Print
45+
// | Title 1 | Title 2 |
46+
// |-------------|------------|
47+
// | Value 1 | Value 2 |
48+
// | Value three | Value four |
49+
println!("FORMAT_MARKDOWN :");
50+
table.set_format(*format::consts::FORMAT_MARKDOWN);
51+
table.printstd();
52+
println!("");
53+
4454
// Custom format can be implemented using `prettytable::format::FormatBuilder`
4555
// Example to print
4656
// +-------------+------------+

src/format.rs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -353,6 +353,9 @@ pub mod consts {
353353
use super::{TableFormat, LineSeparator, FormatBuilder, LinePosition};
354354

355355
lazy_static! {
356+
357+
/// A line separator made of `-` and `|`
358+
static ref MINUS_PIPE_SEP: LineSeparator = LineSeparator::new('-', '|', '|', '|');
356359
/// A line separator made of `-` and `+`
357360
static ref MINUS_PLUS_SEP: LineSeparator = LineSeparator::new('-', '+', '+', '+');
358361
/// A line separator made of `=` and `+`
@@ -555,5 +558,21 @@ pub mod consts {
555558
'┘'))
556559
.padding(1, 1)
557560
.build();
561+
562+
/// A markdown table
563+
///
564+
/// # Example
565+
/// ```text
566+
/// | Title 1 | Title 2 |
567+
/// |-------------|------------|
568+
/// | Value 1 | Value 2 |
569+
/// | Value three | Value four |
570+
/// ```
571+
pub static ref FORMAT_MARKDOWN: TableFormat = FormatBuilder::new()
572+
.padding(1, 1)
573+
.borders('|')
574+
.separator(LinePosition::Title, *MINUS_PIPE_SEP)
575+
.column_separator('|')
576+
.build();
558577
}
559578
}

0 commit comments

Comments
 (0)