Name: HMA FAN 2008-11-22 0:20
(defn bb [tag string]
"Applies a tag to a given string, generating VALID BBCODE."
(str "[" tag "]" string "[/" tag "]"))
;; Not included: "br", "#", "rem"
(def tags '("b" "s" "sup" "sub" "aa" "m" "code" "u" "o" "spoiler"))
(defn random-bb [str]
"Applies a randomly chosen BBCode transformation to the given string"
(bb (nth tags (rand-int (count tags))) str))
(defn tokenize-str [str]
"Turns a string into a list of words. Keeps the newlines etc. but not spaces. Shitty but it works."
(re-seq #"[\\r\\t\\n,\\S]+" str))
(defn random-bbize [odds string]
"Applies random BBCode to every word in a text.
Will fuck up the format somewhat, but you don't care."
(apply str (interleave (map random-bb (tokenize-str string)) (repeat " "))))I made a basic shit GUI with NetBeans, so it's also a demo of calls going from Java to Clojure. Dead easy.
random-bbize could be made to use a BBCode Intensity Factor but I haven't been assed to it yet.