about summary refs log tree commit diff
path: root/kaakaa
diff options
context:
space:
mode:
authorArun Isaac2026-04-10 01:07:42 +0100
committerArun Isaac2026-04-10 01:07:42 +0100
commit1a55558601d4dec073542ff42910413863e939cc (patch)
treeb9fcb24dc98dc35f83746040069665bb6aa71672 /kaakaa
parent70abbe3b69a6474c62c162fa1ca65ef1e95417ff (diff)
downloadkaagum-1a55558601d4dec073542ff42910413863e939cc.tar.gz
kaagum-1a55558601d4dec073542ff42910413863e939cc.tar.lz
kaagum-1a55558601d4dec073542ff42910413863e939cc.zip
Add markdown table builder function.
Diffstat (limited to 'kaakaa')
-rw-r--r--kaakaa/tea.scm17
1 files changed, 17 insertions, 0 deletions
diff --git a/kaakaa/tea.scm b/kaakaa/tea.scm
index a4cf250..b7eaadc 100644
--- a/kaakaa/tea.scm
+++ b/kaakaa/tea.scm
@@ -197,6 +197,23 @@ in @var{state}."
                                                 (focus (state-cwd session-id)
                                                        state)))))))
 
+(define (markdown-table lines)
+  "Return a markdown table built from @var{lines}. Each line is a list of strings,
+each string the contents of a cell. The first line is considered the header of
+the table."
+  (define (cells->line cells)
+    (string-append "| "
+                   (string-join cells " | ")
+                   " |"))
+
+  (match lines
+    ((header other-lines ...)
+     (string-join (cons* (cells->line header)
+                         (cells->line (make-list (length header) "---"))
+                         (map cells->line
+                              other-lines))
+                  "\n"))))
+
 (define %commands
   `(("cwd" . ,%cwd-command)))