dm3 / clojure.java-time

Java 8 Date-Time API for Clojure
MIT License
461 stars 45 forks source link

docstrings of java-time.api contain literal \n #111

Open devurandom opened 1 month ago

devurandom commented 1 month ago

The docstrings in java-time.api contain literal \n instead of newlines, which makes them hard to read in code. Cursive does not display them nicely either, but shows the documentation with the literal \n.

devurandom commented 3 weeks ago

I looked at https://github.com/dm3/clojure.java-time/blob/cd06539014adc9b5d99f68820b371b52be6a5657/test/java_time/dev/gen.clj#L193-L217 and after some experimentation on the REPL I believe this might work:

(deftype DocString [value])

(defmethod print-method DocString
 [^DocString this ^Writer w]
 (.write w (str "\"" (.-value this) "\"")))

With this, the following code (modelled after java-time.dev.gen/print-form):

(with-bindings {#'*print-meta* true}
 (println (pr-str (with-meta {:value "X"} {:doc (DocString. "multi\nline\nstring")}))))

prints:

^{:doc "multi
line
string"} {:value "X"}