Skip to content

Commit c11f4d9

Browse files
authored
Merge pull request #375 from ClojureCivitas/babqua-v0.1.1
updated babqua version
2 parents 68b5e81 + 11fbfc9 commit c11f4d9

2 files changed

Lines changed: 18 additions & 10 deletions

File tree

site/_extensions/scicloj/bb/babqua.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -340,7 +340,7 @@ end
340340

341341
local function emit_mermaid(blocks, source, width, height)
342342
local div_id = next_div_id()
343-
local html = '<div id="' .. div_id .. '"' .. dim_style(width, height) .. '></div>'
343+
local html = '<div id="' .. div_id .. '" class="mermaid"' .. dim_style(width, height) .. '></div>'
344344
.. script_tag("mermaid")
345345
.. '<script>'
346346
.. 'mermaid.initialize({ startOnLoad: false });'

site/_extensions/scicloj/bb/runtime.bb

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,16 @@
4848
[v]
4949
(str/replace (json/generate-string v) "<" "\\u003c"))
5050

51-
(defn- render-table-html
52-
"Render tabular data as a plain HTML table.
51+
(defn- escape-cell
52+
"Escape a value for use inside a Pandoc pipe-table cell."
53+
[v]
54+
(-> (str v)
55+
(str/replace "|" "\\|")
56+
(str/replace "\n" "<br>")))
57+
58+
(defn- render-table-md
59+
"Render tabular data as a Pandoc pipe-table markdown string.
60+
Targets markdown so Quarto's table styling applies natively.
5361
5462
Accepts two shapes:
5563
{:column-names [...] :row-vectors [[...] ...]} (Tablecloth-ish)
@@ -65,11 +73,11 @@
6573
(let [ks (vec (distinct (mapcat keys v)))]
6674
(cons ks (map (fn [m] (mapv #(get m %) ks)) v))))]
6775
(when rows
68-
(str (hiccup/html
69-
[:table
70-
[:thead [:tr (for [c (first rows)] [:th (str c)])]]
71-
[:tbody (for [r (rest rows)]
72-
[:tr (for [c r] [:td (str c)])])]])))))
76+
(let [row-md (fn [r] (str "| " (str/join " | " (map escape-cell r)) " |"))
77+
sep (str "|" (str/join "|" (repeat (count (first rows)) "---")) "|")]
78+
(str/join "\n"
79+
(concat [(row-md (first rows)) sep]
80+
(map row-md (rest rows))))))))
7381

7482
(defn render-by-kind
7583
"Pick a Lua-side rendering format for `v` based on `kind`.
@@ -125,8 +133,8 @@
125133
{:format "chart" :lib "highcharts" :rendered (script-safe-json v)}
126134

127135
:kind/table
128-
(if-let [html (render-table-html v)]
129-
{:format "raw-html" :rendered html}
136+
(if-let [md (render-table-md v)]
137+
{:format "markdown" :rendered md}
130138
{:error (str ":kind/table: value is not recognized as table data. "
131139
"Expected {:column-names [...] :row-vectors [[...] ...]} "
132140
"or a sequence of maps. Got: " (pr-str v))})

0 commit comments

Comments
 (0)