yogthos / markdown-clj

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

Enable usage of keyword arguments from JS #198

Closed rutchkiwi closed 6 months ago

rutchkiwi commented 7 months ago

In javascript, there are no keywords, so we simply convert string to keywords first. This feature is added to the clojure version as well, mostly because I don't know how to run a make a test only for the JS version.

Fixes https://github.com/yogthos/markdown-clj/issues/197

rutchkiwi commented 7 months ago

I haven't manage to test the new actual JS file from my browser - where/how do you actually find that JS file? Is it in the .jar file?

yogthos commented 7 months ago

You'd have to compile the js using something like shadow-cljs. Typically, the library would be used as cljs dependency from within a cljs based project. It's worth noting that making a js artifact will pull in a lot of cljs core, so it will be relatively large. This is why cljs libs are typically not used as standalone dependencies in js projects.

rutchkiwi commented 7 months ago

You'd have to compile the js using something like shadow-cljs. Typically, the library would be used as cljs dependency from within a cljs based project. It's worth noting that making a js artifact will pull in a lot of cljs core, so it will be relatively large. This is why cljs libs are typically not used as standalone dependencies in js projects.

Hmm okay, do you have any tips for doing the shadown-cljs compiling? Is there a build step for it? I think I got the JS version from the demo page, so it'd have to go in there I guess?

In regards to the .js artefact being big, it is not really a problem for me, as my use case is that I've got a user-facing website that renders the markdown using normal JVM clojure. But then I've got a back office system for editing content, and that is where the .js version does it. (also it's only 50kb compressed!)

yogthos commented 7 months ago

Ah I see, I've added a build option in project.clj for creating the Js artifact. If you rebase your branch to the latest you can run lein with-profile js cljsbuild once to make a standalone markdown.js file. If you can confirm your changes work then we can merge the PR. And also if you can revert the change in clj version. :)

rutchkiwi commented 7 months ago

Thanks, I've done that and verified that the JS works now.

Regarding the removal of the stuff from the cli version - doing so breaks the tests. Is there a way to add a a test only for the cljs?

yogthos commented 7 months ago

Oh yeah, you just have to wrap the test as follows

#?(:cljs
    (is (=
         "<h3 id=\"foo_bar_baz\">foo bar BAz</h3><p>some text</p>"
        ; Also testing that keywords args can be passed as strings, for javascript compatibility
         (entry-function "###foo bar BAz##\nsome text" "heading-anchors" true))))
rutchkiwi commented 6 months ago

Ah nice, thanks. All sorted now.

yogthos commented 6 months ago

Awesome, glad to hear everything's working. :)