Created
March 9, 2023 15:38
-
-
Save otfrom/3295146a43d03c119da85d51f908a546 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
^{: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