clojure.java-time icon indicating copy to clipboard operation
clojure.java-time copied to clipboard

docstrings of java-time.api contain literal \n

Open devurandom opened this issue 1 year ago • 3 comments
trafficstars

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 avatar May 31 '24 14:05 devurandom

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"}

devurandom avatar Jun 12 '24 15:06 devurandom

Could you submit a PR we can collaborate on please?

frenchy64 avatar Aug 01 '24 21:08 frenchy64

Could you submit a PR we can collaborate on please?

https://github.com/dm3/clojure.java-time/pull/113

devurandom avatar Aug 02 '24 10:08 devurandom