(ns mrgtst.core
(:require [marginalia.parser :as p]
[clojure.string :as str]))
Create code block from given string s
(defn- code-block
[s]
(str "\n```clojure\n" s "\n```\n\n"))
Save markdown built from clojure source
(defn save-md
[filename]
(let [target (str (second (re-find #"(.*)\.(\w+)$" filename)) ".md")]
(spit target "")
(doseq [{:keys [docstring raw form type] :as all} (p/parse-file filename)]
(spit target
(condp = type
:code (str docstring (code-block raw))
:comment (if (str/starts-with? raw "=>")
(str "Result:" (code-block raw))
(str raw "\n\n")))
:append true))))
Saving md for this file
(save-md "src/mrgtst/core.clj")
Let's define some functions,
Sum two numbers a
and b
(defn sum
[a b]
(+ a b))
let's check the reuslt
(sum 12 -22)
Result:
=> -10
First Header | Second Header |
---|---|
Content from cell 1 | Content from cell 2 |
Content in the first column | Content in the second column |