From ba3aad7294e80b65e0d47376c49c24c4f3adce6c Mon Sep 17 00:00:00 2001 From: Andrew Foltz-Morrison Date: Thu, 4 Jul 2024 14:15:42 -0400 Subject: [PATCH] Make element conversion generic --- dev/site/functions.clj | 21 ++++++++++++--------- dev/site/functions_test.clj | 2 +- 2 files changed, 13 insertions(+), 10 deletions(-) diff --git a/dev/site/functions.clj b/dev/site/functions.clj index 755e00b..8077091 100644 --- a/dev/site/functions.clj +++ b/dev/site/functions.clj @@ -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)) diff --git a/dev/site/functions_test.clj b/dev/site/functions_test.clj index eb04167..0eb34ac 100644 --- a/dev/site/functions_test.clj +++ b/dev/site/functions_test.clj @@ -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"])))))