-
Notifications
You must be signed in to change notification settings - Fork 313
Replaced markdown library com.commonsware.cwac:anddown with jetbrains' markdown for html conversions
#1738
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
…t 16kb-page-size compatible, with org.jetbrains:markdown:0.7.3 to handle markdown to html conversions - converted NoteMarkdownFragment to Kotlin
Generated by 🚫 Danger |
|
📲 You can test the changes from this Pull Request in Simplenote Android by scanning the QR code below to install the corresponding build.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR replaces an outdated markdown library with JetBrains' markdown parser and converts a Java fragment to Kotlin. The main purpose is to resolve compatibility issues with 16kb-page-size configurations by migrating from com.commonsware.cwac:anddown to org.jetbrains:markdown:0.7.3.
- Replaced the
anddownmarkdown library with JetBrains markdown library for HTML conversion - Converted
NoteMarkdownFragmentfrom Java to Kotlin - Updated the markdown parsing implementation to use the new library's API
Reviewed Changes
Copilot reviewed 3 out of 4 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| NoteMarkdownFragment.kt | New Kotlin implementation replacing the Java version with updated markdown parsing |
| NoteMarkdownFragment.java | Removed the original Java file |
| build.gradle | Updated dependency from anddown to JetBrains markdown library |
Simplenote/src/main/java/com/automattic/simplenote/NoteMarkdownFragment.kt
Outdated
Show resolved
Hide resolved
Simplenote/src/main/java/com/automattic/simplenote/NoteMarkdownFragment.kt
Outdated
Show resolved
Hide resolved
Simplenote/src/main/java/com/automattic/simplenote/NoteMarkdownFragment.kt
Show resolved
Hide resolved
…nFragment.kt Co-authored-by: Copilot <[email protected]>
…nFragment.kt Co-authored-by: Copilot <[email protected]>
ParaskP7
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👋 @mzorz !
I have reviewed and tested this PR as per the instructions, everything works as expected (ish), nicely done replacing com.commonsware.cwac:anddown! 🙌 x 🙌 ^ 🙌
I have left one warning (
| import org.intellij.markdown.parser.MarkdownParser | ||
| import java.lang.ref.SoftReference | ||
|
|
||
| class NoteMarkdownFragment : Fragment(), Bucket.Listener<Note> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- Suggestion (💡): I always recommend to have a Java-to-Kotlin conversion commit first, before making any additional manual change to a file. Otherwise, it can become quite tricky to review. For example, in this case I had to make sure to review both the conversation and the
getMarkdownFormattedContent(...)change, all in one commit, risking missing bits. - Suggestion (💡): This is just future suggestion for such Java-to-Kotlin conversions, that using an extra commit for
.java>.ktrenames helps with preserving the files history and makes it easier to diff the changes, for example:
Before committing the change, you could ☑️ this Extra commit for .java > .kt renames on that IDE commit dialog:
And then, instead of having a change like this below, where the Java file is deleted, and another Kotlin file is created:
You now get this instead:
This above is possible because prior to that an automated Rename .java to .kt is commit for you:
Really hope that this will become handy next time you'll converted a Java file! 🙏
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oh I use the command line for git stuff. I'll remember to do the rename, commit, then convert, commit 👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is awesome @mzorz , I did saw you doing that trick on this other PR and worked fantastically, much much better, thanks so much! 🙇 ❤️
|
|
||
| val flavour = CommonMarkFlavourDescriptor() | ||
| val parsedTree = MarkdownParser(flavour).buildMarkdownTreeFromString(sourceContent) | ||
| var parsedMarkdown = HtmlGenerator(sourceContent, parsedTree, flavour).generateHtml() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Warning (com.commonsware.cwac:anddown Java implementation to this new org.jetbrains:markdown Kotlin implementation, it comparing these 2 versions:
java
If this Java code below, which is using the 'com.commonsware.cwac:anddown' library:
String parsedMarkdown = new AndDown().markdownToHtml(
sourceContent,
AndDown.HOEDOWN_EXT_STRIKETHROUGH | AndDown.HOEDOWN_EXT_FENCED_CODE |
AndDown.HOEDOWN_EXT_QUOTE | AndDown.HOEDOWN_EXT_TABLES,
AndDown.HOEDOWN_HTML_ESCAPE
);
kotlin
val flavour = CommonMarkFlavourDescriptor()
val parsedTree = MarkdownParser(flavour).buildMarkdownTreeFromString(sourceContent)
var parsedMarkdown = HtmlGenerator(sourceContent, parsedTree, flavour).generateHtml()
It came back with this table below:
| Feature | AndDown (Hoedown) | JetBrains Markdown (CommonMarkFlavourDescriptor) |
|---|---|---|
| Strikethrough | Yes (with HOEDOWN_EXT_STRIKETHROUGH) | No (CommonMark); Yes with GFMFlavourDescriptor |
| Fenced code blocks | Yes (with HOEDOWN_EXT_FENCED_CODE) | Yes (supported by default) |
| Block quotes | Yes (with HOEDOWN_EXT_QUOTE) | Yes (supported by default) |
| Tables | Yes (with HOEDOWN_EXT_TABLES) | No (CommonMark); Yes with GFMFlavourDescriptor |
| Task lists | No (unless using custom extensions) | No (CommonMark); Yes with GFMFlavourDescriptor |
I then tested Strikethrough, Tables and Task lists and actually it was right, see below:
PREVIEW (before) -> val flavour = CommonMarkFlavourDescriptor()
PREVIEW (after) -> val flavour = GFMFlavourDescriptor()
This too me looks like AI is right and we should use the GFMFlavourDescriptor in favor of CommonMarkFlavourDescriptor. Yes, for some reason the Strikethrough doesn't look too good (I don't see the actual strikethrough), same with the task lists, but it is nevertheless better than before, right? 🤔
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great catch, I thought I had GFMFlavourDescriptor in one of my branches but no!
I did observe the prod app was not particularly good in the Preview tab so I didn't check one by one, see for example how an empty checkbox looks like on preview on prod:
Will update and perhaps try something about that sneaky strikethrough 👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great catch, I thought I had GFMFlavourDescriptor in one of my branches but no!
Never when you need it, right! 🤣
I did observe the prod app was not particularly good in the Preview tab so I didn't check one by one, see for example how an empty checkbox looks like on preview on prod:
Yea, I know... 🤷
Will update and perhaps try something about that sneaky strikethrough 👍
Thanks so much @mzorz ! 🙇 ❤️
|
Ah, and btw @mzorz, unrelated to this PR, but as I was testing this PR, I found another "bug" related to the screen scrolling behavior as well as the keyboard being on top of the content, without a means to move the content up, above the keyboard, see below:
Notice that I can't scroll the content up to show this 3rd |
|
Great testing there @ParaskP7 ! do you have a video for the screen scrolling behavior? I can't reproduce (testing both this version and the prod version) |
|
Here's a recording for you @mzorz : screen-20250805-181337.mp4Does it help? 🙏 |
|
Wow that recording helps. I can't reproduce it here though 🤔 - could you paste the markdown here? |
|
@ParaskP7 good news, updated the code here 7e2623d and now it supports markdown strikethrough correctly alongside all the other good bits the Turns out the which then was not being parsed correctly by the Android WebView since it would need some css treatment. So I checked the original code which produced this code: The deleted element is supported off the shelf since its basic html. Had to do some digging into how the GFMFlavourDescriptor worked, and was able to override that mapping to produce
|
Will look into this 👍 |
✅ this issue where content couldn't be scrolled and the virtual keyboard was hiding it was fixed in dd575ff in #1737 |
As per my other comment, nicely done @mzorz , I just tested there and it works as expected, thank YOU! 🙇 ❤️ 🚀 |
Awesome, I am checking
Hmmm, thanks for the explanation on all that, not sure why too... 🤷
Indeed it does, tested! 🎉 |
|
Thanks a ton @ParaskP7 ! 🙌 I'll wait until the base PR is reviewed before merging, to help ease the review there 👍 |



Fix
com.commonsware.cwac:anddownwhich was not 16kb-page-size compatible, withorg.jetbrains:markdown:0.7.3to handle markdown to html conversionsNoteMarkdownFragmentto KotlinTest
Review
cc @ParaskP7
Release