 (ns com.hypirion.subtex.hiccup
   (:require [com.hypirion.rexf :as rexf])
-  (:import (java.util ArrayList)))
+  (:import (com.hypirion.rexf ReducerFactory Reducer)
+           (java.util ArrayList)))
 
 (defn vectorize-invoke
   [name vect]

(def sub    (vectorize-invoke "\\textsubscript" :sub))
(def sup    (vectorize-invoke "\\textsuperscript" :sup))

(def common-invokes
  (comp h1 h2 h3 h4 strong em sub sup))


                                     (identical? (first %) :li))
                               (:value input))])
          (rf res input)))))))

(def ^:private text-value
  (rexf/stateless-xf
   (fn [rf]
     (fn
       ([] (rf))
       ([res] (rf res))
       ([res input]
        (cond (identical? :text (:type input)) (rf res (:value input))
              (identical? :para-end (:type input)) res
              :else (rf res input)))))))

(defn paragraphiphy
  [rf]
  (reify ReducerFactory
    (init [_]
      (let [rf' (rexf/init rf)
            reinit-rf (text-value rf)]
        (reify clojure.lang.IFn
          (invoke [_] (rf'))
          (invoke [_ res] (rf' res))
          (invoke [_ res input]
            (cond (identical? :text (:type input)) (rf res [:p (:value input)])
                  (identical? :para-end (:type input)) res
                  :else (rf res input)))
          Reducer
          (reinit [_] (rexf/init reinit-rf)))))))
