Skip to content

Instantly share code, notes, and snippets.

@otfrom
Created March 9, 2023 15:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save otfrom/3295146a43d03c119da85d51f908a546 to your computer and use it in GitHub Desktop.
Save otfrom/3295146a43d03c119da85d51f908a546 to your computer and use it in GitHub Desktop.
^{:nextjournal.clerk/visibility {:result :hide}}
(defn md-row [v]
(str "| " (apply str (interpose " | " v)) " |\n"))
^{:nextjournal.clerk/visibility {:result :hide}}
(defn md-table [{:keys [columns alignment-spec data]}]
(clerk/md
(apply
str
(into [(md-row columns)
(md-row alignment-spec)]
(comp
(map
(fn [row]
((apply juxt
(map (fn [column] (fn [m] (m column))) columns))
row)))
(map md-row))
(tc/rows data :as-maps)))))
(md-table {:columns ["Foo" "Bar" "Baz"]
:alignment-spec [":---" ":---:" "---:"]
:data (tc/dataset {"Foo" ["foo0" "foo1" "foo2"]
"Bar" ["bar0" "bar1" "bar2"]
"Baz" [12.0 1.00 1.01]})})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment