Skip to content

Commit

Permalink
Make element conversion generic
Browse files Browse the repository at this point in the history
  • Loading branch information
respatialized committed Jul 4, 2024
1 parent 1b07347 commit ba3aad7
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 10 deletions.
21 changes: 12 additions & 9 deletions dev/site/functions.clj
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,20 @@

(def comment-line-pattern #"(?ms)^(?:\s*;+\s*)(.*)\z")

(defn comment->paragraph
[[_tag _attrs _start & contents]]
;; don't worry about linebreaks for now
(->> contents
(mapcat (fn [line]
(let [[_txt trimmed] (re-matches comment-line-pattern line)]
(md-line trimmed))))
(reduce conj [:p {:class "comment-paragraph"}])))


(defn comment->element
([[_tag _attrs _start & contents] elem]
;; don't worry about linebreaks for now
(->> contents
(mapcat (fn [line]
(let [[_txt trimmed] (re-matches comment-line-pattern line)]
(md-line trimmed))))
(reduce conj elem)))
([i] (comment->element i [:span {:class "clj-comment"}])))

(defn process-form
[f]
(if (and (vector? f) (re-find #"comment" (get-in f [1 :class])))
(comment->paragraph f)
(comment->element f)
f))
2 changes: 1 addition & 1 deletion dev/site/functions_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
(t/deftest clojure-parsing
(t/is (= "" (site-fns/md-line "")))
(t/is (= "Here's an example of a comment hiccup form"
(peek (site-fns/comment->paragraph
(peek (site-fns/comment->element
[:span {:class "language-clojure comment"}
[:span {:class "language-clojure comment-start"} ";"]
"; Here's an example of a comment hiccup form\n"])))))

0 comments on commit ba3aad7

Please sign in to comment.