From: Scott Worley Date: Mon, 19 Aug 2024 20:46:51 +0000 (-0700) Subject: Render column headers X-Git-Tag: v0.2.0~5 X-Git-Url: http://git.scottworley.com/tablify/commitdiff_plain/76638ea1debd36a19c5702d22cc50b1e79f44570 Render column headers --- 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))