X-Git-Url: http://git.scottworley.com/tablify/blobdiff_plain/de408c29be1f465f08fc0ba4114704d3ef8bdcef..76638ea1debd36a19c5702d22cc50b1e79f44570:/src/lib.rs
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))