From 76638ea1debd36a19c5702d22cc50b1e79f44570 Mon Sep 17 00:00:00 2001 From: Scott Worley Date: Mon, 19 Aug 2024 13:46:51 -0700 Subject: [PATCH 1/1] Render column headers --- src/lib.rs | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/lib.rs b/src/lib.rs index 9504c7f..5de1c12 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -32,7 +32,8 @@ const HEADER: &str = " - "; + +"; const FOOTER: &str = "
@@ -186,6 +187,16 @@ fn render_row(columns: &[String], row: &RowInput) -> String { ) } +fn render_column_headers(columns: &[String]) -> String { + // TODO: Escape HTML special characters + String::from("") + + &columns + .iter() + .map(|c| format!("{c}")) + .collect::() + + "\n" +} + /// # Errors /// /// Will return `Err` if @@ -196,6 +207,7 @@ pub fn tablify(input: impl std::io::Read) -> Result { let rows = read_rows(input).collect::, _>>()?; let columns = column_order(&rows); Ok(String::from(HEADER) + + &render_column_headers(&columns) + &rows .into_iter() .map(|r| render_row(&columns, &r)) -- 2.44.1