Skip to content

Commit

Permalink
added comments
Browse files Browse the repository at this point in the history
  • Loading branch information
johnlawrenceaspden committed Aug 12, 2010
1 parent 54ec324 commit 85b8a18
Showing 1 changed file with 19 additions and 28 deletions.
47 changes: 19 additions & 28 deletions clj2html.clj
@@ -1,20 +1,27 @@
;publish clojure code
;;Turns clojure code into html

;;Takes all comments on their own line and converts them to text paragraphs
;;Takes all live code to <div><pre><code class="clojure">...</></></>
;;sections.

(use 'clojure.contrib.str-utils)
(use 'clojure.contrib.seq-utils)
(use 'clojure.contrib.duck-streams)

(def file (slurp (first *command-line-args*)))
;(def file (slurp "/home/john/hobby-code/clj2html.clj"))

(def lines (clojure.contrib.str-utils/re-split #"\n" file))

(defn blank? [line] (every? #(= % \space) line))
;(map blank? '("" " " " " ";" "hello"))
;(map blank? '("" " " " " "; " "hel lo"))

(defn comment? [line] (and (> (count line) 0) (= (nth line 0) \;)))
(defn comment->text [line]
(if (comment? line) (recur (apply str (drop 1 line))) line))
(defn comment? [line] (and (> (count line) 0) (= (first line) \;)))

(defn comment->text "remove leading ;;"
[line]
(if (comment? line) (recur (apply str (drop 1 line)))
line))
;(map comment->text '(";hello" ";" "" "no" ";;;biggie"))

(def analysed-lines (map (fn [line] [(comment? line) line]) lines))
Expand All @@ -23,29 +30,13 @@

(defn transform-group [group]
(if (comment? (first group))
(concat '("<p>") (map comment->text group) '("</p>"))
(concat '("<p>")
(map comment->text group)
'("</p>"))
(if (every? #(blank? %) group)
group
(concat '("<div><pre><code class=\"clojure\">") group '("</div></pre></code>")))))

(doall (map println (mapcat transform-group groups)))

;; (defn parse-lines [lines] (parse lines true '[]))

;; (defn parse [lines in-comment? acc]
;; (if (= (count lines) 0)
;; acc
;; (let
;; [line (first lines)
;; comment-line (comment? line)]
;; (cond (and (not in-comment?) comment-line)
;; (recur (rest lines) true (conj acc (comment->text line)))
;; (and in-comment? comment-line)
;; (recur (rest lines) true (conj acc (comment->text line)))
;; (and (not in-comment?) (not comment-line))
;; (recur (rest lines) false (conj acc line))
;; (and in-comment? (not comment-line))
;; (recur (rest lines) false (conj acc line)))))))
;;
;;(parse-lines lines)
(concat '("<div><pre><code class=\"clojure\">")
group
'("</div></pre></code>")))))

(doall (map println (mapcat transform-group groups)))

0 comments on commit 85b8a18

Please sign in to comment.