noties / Markwon

Android markdown library (no WebView)
https://noties.io/Markwon/
Apache License 2.0
2.74k stars 309 forks source link

Provided EditHandlers for MarkwonEditor #314

Open stefan-niedermann opened 3 years ago

stefan-niedermann commented 3 years ago

Hi there :wave:

i'd like to use the MarkwonEditor for the Nextcloud Notes and Nextcloud Deck apps. However i am struggling because the MarkwonEditor seems to be a very basic version and while all punctuation seems to be working finde, one needs to implement EditHandlers for each feature himself.

I tried to copy some of the handlers (like StrikethroughEditHandler) and tried to integrate them. They seem to work well, but

  1. I am wondering why they are only in the samples package and not provided by default like the StrongEmphasisEditHandler?
  2. I have massive issues to implement a HeadlineEditHandler properly

Could you please give me a statement whether more features will be shipped in the future for the MarkwonEditor? Do you think you can find some time to help implement them for the markwon repository (I am willing in helping you if i can)?

Thank you in advance Stefan

noties commented 3 years ago

Hello @stefan-niedermann ,

Ideally an editor would need source positions for each node. Unfortunately commonmark-java, on which Markwon is based, does not provide them. Well, support was added recently for block nodes (it is still unreleased), but not inlines (so, no emphasis, strikethroughs, links, etc). So, I had an idea to use text diffing instead. What editor does is it takes original (source) input and compares it to rendered output. What is different - is markdown syntax. It works quite well. Until you need something more, like a strong indication or a real WYSIWYG editor. Because these would effectively mean parsing markdown again and this time manually.

So I created few edit handlers and put them in sample as a reference, because I was not able to provide full support for all markdown syntax nodes. Hoping to raise some discussion and polish the solution later. Well, no discussion did happen and as I have no active project involving editor, this artifact became a bit stale.

I see your HeadlineEditHandler and think you will need to find the first new line index (or use the text length) in order to close the span. What other problems do you have with it?

I'm definitely looking forward to knowing what editor is capable of. Unfortunately I do not have much time resources to do it alone. So if you are (or anyone else, everyone is welcome!) willing to participate, then let's do it

BTW, not having source positions information attached to nodes was initial motivation behind commonmark-java fork - flexmark-java. Flexmark-java was created to support markdown editor plugin for Intellij

desperateCoder commented 3 years ago

🤔 ok @stefan-niedermann, uhm... Assuming we can harass @noties with a couple of questions, what about getting this actually done? I mean we had quite some results, way not perfect but we at least achieved something, so maybe we should just wiggle around and ask some questions, I think we can make this work for us and all others as well?

@noties I assume PRs are welcome?

noties commented 3 years ago

Definitely @desperateCoder , all questions and PR are welcome

stefan-niedermann commented 3 years ago

@noties for your information: We are working on the headlines right now.

If you allow, i will open a PR once it is finished which moves all EditHandler implementations from the samples to the actual code, so they don't have to be copy&pasted and add our EditHandler implementation for headlines.

stefan-niedermann commented 3 years ago

PR: https://github.com/noties/Markwon/pull/317 (Still a draft :warning: Do not merge yet!)

atulgpt commented 3 years ago

Source info on common-mark library has been released for version https://github.com/commonmark/commonmark-java/releases/tag/commonmark-parent-0.16.1