yogthos / markdown-clj

Markdown parser in Clojure
Eclipse Public License 1.0
540 stars 120 forks source link

Calling with :heading-anchors from js? #197

Closed rutchkiwi closed 6 months ago

rutchkiwi commented 7 months ago

Hi, Thanks a lot for this great library.

Apologies as this is a bit of a n00b question.

I want to add get some heading-anchors on my markdown, and it works as expected from clojure. But how do I do this from JS? markdown.core.mdToHtml('#hello \n there', "headingAnchors", true); does not work.

yogthos commented 7 months ago

Hmm not sure why there would be different when compiling to Js. If you're generating on the frontend, maybe there's some security feature in the browser that's sanitizing the reference link that's generated?

rutchkiwi commented 7 months ago

hmm i'm not sure what you mean, I simply call this from the console after loading in the library with a script tag. It works, but it doesnt include the ids for fragment links. I guess my issue is I don't know how you call clojurescript with keyword args from js - keyword arguments arent a native thing in js. (which isn't really specific to this library, I was just hoping you'd know :)

yogthos commented 7 months ago

Oh I see, I misunderstood originally and thought you were just compiling cljs as opposed to calling in from Js. Looking at the code, I think there might need to be explicit keywordization for the params for Js that's not being done currently here.

(when params (apply (partial assoc {}) params))

should probably be changed to

(some->> params
                 (partition 2) 
                 (reduce (fn [m [k v]] (assoc m (keyword k) v)) {}))

then you'd be able to pass in js strings and objects via mdToHtml.