babashka

borkdude 2025-05-30T11:08:34.165709Z

I changed something about babashka tasks which I think is an improvement but could potentially break existing code, although it seems unlikely to me. The changes: • :init is now ran after global task :requires but before specific task :requires (old behavior: after both requires). This lets you e.g. set a System property before specific task namespaces are loaded that reads it • :init is now only ran once. The behavior before was that it ran potentially multiple times if you used run in your code, e.g. (run 'task-b) . I'd appreciate it if you could test out the dev build with: bash <(curl ) --dev-build --dir /tmp to see if your tasks aren't affected by this.

❤️ 1
✅ 2
✍️ 2
lread 2025-05-30T12:03:13.962789Z

This seems sensible and fine to me but will give it a whirl and report back

lread 2025-05-30T12:25:41.094659Z

Oopsies! The king of typos and mal-pasters strikes again! Tx

lread 2025-05-30T12:38:21.985809Z

I tried bb babashka v1.12.201-SNAPSHOT out on various projects with bb.edn that use :init and some that don't. I did not notice any problems at all.

borkdude 2025-05-30T12:38:40.388019Z

good, thanks!

borkdude 2025-05-30T12:49:35.737319Z

I read back some threads from this channel from 2020 and found this comment by @dominicm and the comment by @nate: the idea that bb could talk to several other bb instances with other features (jdbc etc) via a pipe. A month later the pods library was born (which was also heavily inspired by how nREPL works). https://clojurians.slack.com/archives/CLX41ASCS/p1587824080017300?thread_ts=1587810643.473500&cid=CLX41ASCS

7
❤️ 6
🚀 6
borkdude 2025-05-30T12:51:35.202779Z

lread 2025-05-30T13:07:19.547029Z

Cool! Today in bb history!

nate 2025-05-30T15:50:29.170819Z

Fun to see conversations from more than 5 years ago. I think pods have really done well, and the pod-registry makes them super easy to install. Just used the sqlite one for the first time in the last week and it just works.

ericdallo 2025-05-30T12:52:30.866299Z

I feel like I'm missing some function somewhere, but is there a way to list all files in a dir recursive using babashka/fs?

✅ 1
ericdallo 2025-05-30T12:52:47.985609Z

like babashka.fs/list-dir but entering the dirs if any

borkdude 2025-05-30T12:53:23.482029Z

you could just use file-seq for this

ericdallo 2025-05-30T12:53:38.770909Z

ah yeah, I forgot about that facepalm

borkdude 2025-05-30T12:53:45.431689Z

but if you're looking for specific files, you can use fs/glob

borkdude 2025-05-30T12:53:50.271679Z

which is recursive

ericdallo 2025-05-30T12:54:07.021969Z

got it, I want all files indeed

borkdude 2025-05-30T12:54:35.559229Z

you can also use https://github.com/babashka/fs/blob/master/API.md#walk-file-tree which is a visitor for all files in a directory

ericdallo 2025-05-30T12:54:41.541209Z

actually, on a second thought, only clojure related ones

ericdallo 2025-05-30T12:54:54.438489Z

yeah I saw that one but I thought there was a easier one

ericdallo 2025-05-30T12:55:04.450869Z

I have source-paths and wanna convert them to clojurable uris

borkdude 2025-05-30T12:55:35.315339Z

$ bb -e '(map str (fs/glob "." "**.{edn}"))'
("tests.edn" "shadow-cljs.edn" "deps.edn" "resources/clj-kondo.exports/nextjournal/clerk/config.edn" "resources/META-INF/nextjournal/clerk/meta.edn" "render/deps.edn" "ui_tests/nbb.edn" "public/build/index.edn" "public/build/book.edn" "public/build/CHANGELOG.edn" "bb-runtime.edn" "bb.edn" "garden.edn")

ericdallo 2025-05-30T12:55:44.671499Z

awesome, will try this one, thank you!

ericdallo 2025-05-30T12:57:55.344459Z

(map (comp str fs/canonicalize)
     (fs/glob "." "**.{edn,clj,cljs,cljc,bb,cljd,clj_kondo}"))

borkdude 2025-05-30T12:58:00.781199Z

yes

1
borkdude 2025-05-30T13:36:37.128349Z

I'm contemplating adding a markdown library to babashka. The reasons for this are as follows: • Babashka already has built-in (= performant) support for common formats: EDN, JSON, CSV, YAML. Markdown is a common format. Adding this will make bb a good engine to build static blogging frameworks on. • markdown-clj is pretty good and bb-compatible, but it doesn't implement the CommonMark spec to the letter (it parses stuff line by line, which gets you 90% there but it has some quirks). Quickblog is already a bb-compatible blogging framework which uses markdown-clj. A built-in library would provide even better performance and CommonMark compliance (depending on the chosen lib). • Clerk support. As we speak I'm writing notebooks in babashka with clerk (with a locally compiled bb, see comment in #clerk). Clerk needs a markdown library which spits out an intermediate AST before going all the way to HTML. I've tested https://github.com/nextjournal/markdown for this (which is used in clerk) and it only adds 1MB to the binary (from 69MB to 70MB) which may very well be worth it. Any thoughts on this? Any other use cases you would have for a markdown library in bb? Issues reported with markdown-clj that violate the commonmark spec: - https://github.com/yogthos/markdown-clj/issues/97 - https://github.com/yogthos/markdown-clj/issues/100 - https://github.com/yogthos/markdown-clj/issues/114 - https://github.com/yogthos/markdown-clj/issues/146 - https://github.com/yogthos/markdown-clj/issues/156 - https://github.com/yogthos/markdown-clj/issues/170 - https://github.com/yogthos/markdown-clj/issues/180 - https://github.com/yogthos/markdown-clj/issues/181 - https://github.com/yogthos/markdown-clj/issues/190 (Yes, I know there's asciidoctor fans out here too, but limiting this discussion to markdown, sorry ;-)).

👍 14
👍🏼 1
mal 2025-06-05T04:11:16.460079Z

I’ve been using the asciidoc variant of markdown more over time.

lukasz 2025-05-30T13:44:08.279969Z

I'll say this again: binary size doesn't matter as much as it did in 1997 😉

💯 2
borkdude 2025-05-30T13:44:45.750289Z

sure, but adding libs also increases compile time :) nextjournal/markdown + java CommonMark isn't very heavy though

a13 2025-05-30T13:45:08.865499Z

Definitely, but for me, there's still a psychological 2-digit MB limit. 😄

a13 2025-05-30T13:46:10.013429Z

Not that going over that limit would make me give up Babashka...

lukasz 2025-05-30T13:48:11.867089Z

@borkdude that's fair, sounds like a more important consideration, out of curiosity - have you been tracking compile time increase with every major library addition?

borkdude 2025-05-30T13:50:23.872779Z

I have. binary size too. Let me check compile time with and without nextjournal.markdown on CI. current master linux: 3m7 current nextjournal-markdown linux: 3m11

🚀 1
lukasz 2025-05-30T13:57:30.953229Z

shipit

👍 1
nate 2025-05-30T15:14:25.955879Z

There's also the markdown over in the bootleg pod. Haven't used it and don't know if it does AST. As a pod, it would be slower than native.

borkdude 2025-05-30T15:15:05.144859Z

the bootleg pod uses markdown-clj which runs with bb from source since a few years

borkdude 2025-05-30T15:15:52.842409Z

I updated the original message with a list of issues from markdown-clj that violate the commonmark spec

nate 2025-05-30T15:16:37.318859Z

I like the idea of running clerk with bb, and the markdown library from nextjournal looks nice. Biggest things I look for in a markdown parser is the github extensions.

borkdude 2025-05-30T15:17:15.633759Z

What Github extensions in particular? I think a few of them are enabled, but not sure if all the ones you need are. This is the time to discuss!

borkdude 2025-05-30T15:17:22.986319Z

TODO list / checkboxes do work

nate 2025-05-30T15:19:35.391789Z

oh, I thought that fenced code blocks were GFM, but it looks like they're part of the base spec

nate 2025-05-30T15:20:42.557239Z

Looks like tables are an extension

borkdude 2025-05-30T15:24:18.642599Z

@nate looks like nextjournal.markdown supports tables out of the box:

(md/parse "| Name       | Age | Occupation     |
|------------|-----|----------------|
| Alice      | 30  | Engineer       |
| Bob        | 25  | Designer       |
| Charlie    | 35  | Product Manager|")
{:toc {:type :toc}, :footnotes [], :content [{:type :table, :content [{:type :table-head, :content [{:type :table-row, :content [{:type :table-header, :content [{:type :text, :text "Name"}]} {:type :table-header, :content [{:type :text, :text "Age"}]} {:type :table-header, :content [{:type :text, :text "Occupation"}]}]}]} {:type :table-body, :content [{:type :table-row, :content [{:type :table-data, :content [{:type :text, :text "Alice"}]} {:type :table-data, :content [{:type :text, :text "30"}]} {:type :table-data, :content [{:type :text, :text "Engineer"}]}]} {:type :table-row, :content [{:type :table-data, :content [{:type :text, :text "Bob"}]} {:type :table-data, :content [{:type :text, :text "25"}]} {:type :table-data, :content [{:type :text, :text "Designer"}]}]} {:type :table-row, :content [{:type :table-data, :content [{:type :text, :text "Charlie"}]} {:type :table-data, :content [{:type :text, :text "35"}]} {:type :table-data, :content [{:type :text, :text "Product Manager"}]}]}]}]}], :type :doc}

nate 2025-05-30T15:24:41.173289Z

sweet!

nate 2025-05-30T15:25:05.555429Z

nice that it parses to an AST, very Clojure-y

borkdude 2025-05-30T15:25:42.150119Z

yeah and it has one transformer that happens to transform to hiccup so it's very easy to modify the generated HTML too as a post-processing step

➕ 1
lread 2025-05-30T20:19:11.951789Z

I have no opinion on this markdown business simple_smile But another github extension that was not part of the official spec, last time I checked, is https://docs.github.com/en/get-started/writing-on-github/getting-started-with-writing-and-formatting-on-github/basic-writing-and-formatting-syntax#alerts. Fwiw, cljdoc uses https://github.com/vsch/flexmark-java for markdown support. It's very flexible, but also, I think, no longer actively developed/supported.

borkdude 2025-05-30T20:34:13.384659Z

ok yeah for alerts, I think it would be easy enough to traverse the hiccup and modify that if you want it.

[!NOTE] Useful information that users should know, even when skimming content.

or just incercept block_quote before it's turned into hiccup. I think this is doable with nextjournal.markdown in multiple places

borkdude 2025-05-30T20:36:08.562739Z

flexmark-java is a fork of commonmark-java btw. luckily nextjournal.markdown doesn't expose any of this stuff, it's hidden in an .impl namespace so switching the Java lib would still be possible in the future

lread 2025-05-30T20:38:22.110049Z

Yeah, not too tricky. I did not find specific rules for github markdown alert syntax, so I figured out what I could at the time for cljdoc through experimentation: https://github.com/cljdoc/cljdoc/issues/906

borkdude 2025-05-30T20:39:58.611939Z

I'll try to do a POC if I think about this again when I have time to see how easy it would be in nextjournal.markdown to do the same (without writing Java)

👍 2
borkdude 2025-05-30T21:44:37.148359Z

@lee here's the POC. It's a bit unwieldy but compared to writing Java I'd say it's not too bad.

(require '[clojure.pprint :as pprint]
         '[nextjournal.markdown :as md]
         '[nextjournal.markdown.transform :as md.transform])

(def blockquote-renderer (:blockquote md.transform/default-hiccup-renderers))

(clojure.pprint/pprint
 (md/->hiccup
  (assoc md.transform/default-hiccup-renderers
         :blockquote
         (fn [ctx {:keys [content] :as elt}]
           (if (= 1 (count content))
             (let [{:keys [content type]} (first content)]
               (if (and (= :paragraph type)
                        (= "[!NOTE]" (-> content first :text)))
                 [:div {:style {:color "green"}}
                  (blockquote-renderer ctx
                                       (update elt :content
                                               (fn [[paragraph]]
                                                 [(update paragraph :content (fn [text-nodes]
                                                                               (drop 2 text-nodes)))])))]
                 (blockquote-renderer ctx elt)))
             (blockquote-renderer ctx elt))))
  "> [!NOTE]
> Useful information that users should know, even when skimming content.

> Normal blockquote"
))
$ clj -M scratch.clj
[:div
 [:div
  {:style {:color "green"}}
  [:blockquote
   [:p
    "Useful information that users should know, even when skimming content."]]]
 [:blockquote [:p "Normal blockquote"]]]