JetBrains / markdown

Markdown parser written in kotlin
Apache License 2.0
682 stars 75 forks source link

Support for Kotlin multiplatform #36

Closed saket closed 3 years ago

saket commented 5 years ago

Hey @valich, have you considered converting this to a pure Kotlin library and adding support for multiplatform? I skimmed through some files and it looks like the usage of classes from Java are fairly low. It would be great to be able to use a single markdown parser on multiple platforms and not just Java or JS.

valich commented 4 years ago

Hi @saket, sorry I lost your question :(

There is a feature branch kotlin-js-clean which is a kind of working multiplatform (jvm+js) implementation. "A kind of" means that there are little differences between JVM and JS versions (and, hence, failing tests) which do not allow to merge it into master, however we use it internally a little and it's working pretty well.

Please share your feedback if you decide to try it 🙏

saket commented 4 years ago

I lost track of this question as well :)

I'm working on a cross platform wysiwyg app for Android and macOS. The markdown right now is a bunch of expect/actual definitions, but I'd love to use a single parser for both the platforms.

Looking at the kotlin-js-clean branch, it looks like the code is already mostly Java-free and native platform targets can be added without a lot of effort. Do you think that's correct? Are there any other challenges?

saket commented 4 years ago

Small update: I tried adding a native target but quickly ran into build issues. I noticed that this project uses an unusual project structure. Instead of having one gradle module with different platform source sets, we have separate gradle modules linked to each other using expectedBy. Was this intentional? If yes, could you help me setup a native platform and I can pick up from there? Otherwise, would you be interested in moving all platforms to one module?Resources for KMP is already scarce. Following an uncommon style makes it difficult for devs with less-than-stellar gradle skills (like me!)

Additionally, the kotlin version used in this library is quite old. Projects that are on the latest version of kotlin will find it impossible to depend on it, until Kotlin/Native gains ABI stability. Thoughts on updating the version?

valich commented 4 years ago

To be honest, I am not sure what the correct MPP gradle structure should have been so I've made it that way at some point of time. I can try to rearrange it to a single-module and see how it goes.

Looking at the kotlin-js-clean branch, it looks like the code is already mostly Java-free and native platform targets can be added without a lot of effort. Do you think that's correct? Are there any other challenges?

This branch is used as a "source dependency" in JB for MPP project, so it works for multiplatform, but gradle structure might be incorrect, as it's unused externally.

saket commented 4 years ago

Hey @valich, any updates here? I'd love to contribute if the initial setup becomes a bit easier.

valich commented 3 years ago

I've made substantial progress towards making MPP structure correct and, hence, merging MPP branch into master in https://github.com/valich/intellij-markdown/commits/kotlin-js-clean. I need to set up the deployment and fix a couple of url resolution tests and it'll be good to go. I think I will be able to finish that tomorrow.

saket commented 3 years ago

This is huge. Looking forward!

valich commented 3 years ago

OK I've merged multiplatform conversion to master, you can try it, version is 0.2.0.pre-49. There is a couple of (hopefully, little) problems, my main concern is about published artifacts format.

  1. I wanted to preserve jvm artifact name, but the published files/dirs have a different name. It seems, however, that gradle is fine with that, adding the new artifact as a dependency for jvm works fine.
  2. How do you plan to add this ilb as a dependency for multiplatform? While tinkering with deployment, I saw there is a special kotlinMultiplatform gradle publication, but I could not make sense of it.
saket commented 3 years ago

🎉

I'm unfortunately not familiar with publishing of multiplatform artifacts. The new kotlinMultiplatform publication is great for consumers to add a single maven coordinate in their commonMain, but if that doesn't work then adding each artifact to its respective platform is also alright.

valich commented 3 years ago

OK, so Kotlin guys told me that the multiplatform artifact should resolve to jvm in pure-jvm projects using gradle >= 5.4 so I've changed layout to the default one

markdown for multiplatform markdown-jvm for jvm markdown-js for js markdown-metadata for metadata.

Hope this works well for you. I haven't dug into native part so please contribute if you need it :)