Skip to content
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

Fix Markdown rendering issues #458

Merged
merged 5 commits into from
Jul 19, 2024
Merged

Fix Markdown rendering issues #458

merged 5 commits into from
Jul 19, 2024

Conversation

rock3r
Copy link
Collaborator

@rock3r rock3r commented Jul 19, 2024

This PR changes a number of things in the Markdown rendering pipeline:

1. We will not optimise for edits by default anymore

The vast majority of Markdown usages are in UI text, which will never change. Having optimise for edits enabled by default added an enormous overhead since the same processor instance was shared across all usages, and we were doing pointless work every time some UI text was shown. All strings in this case are different, and they don't change often (or at all).

The flag is now off by default. Users who want to implement an editor preview will need to provide their own processor instance with the flag set (see standalone sample).

2. Models implement equals and hashCode

Using value classes had a small rendering performance and memory improvement, but it meant that we relied on CommonMark's models for equality checking and hashcode calculation. CommonMark's models do not implement these methods, so we were stuck with reference checks, which even if the content was identical would result in a recomposition.

This PR gets rid of the value classes and switches to normal classes, backed by Poko autogenerated equals/hashCode/toString. Inline Markdown is not passed through as a string anymore, to be rendered into inline models during UI rendering. Now the rendering phase only needs to visit our models, making it significantly faster.

Also, models don't contain business logic anymore; it's the processor's job to know how to translate CommonMark models to our own.

A huge amount of changes in this PR are needed to adapt tests accordingly. Feel free to ignore the changes in MarkdownProcessorDocumentParsingTest, they're all mechanical changes but functionally equivalent.

3. Inline extensions are now (tentatively) supported

There is a new extension API for custom inline node processing and rendering. We have not tested it yet, nor we have used it yet. However, it should make possible to implement #325 properly in a separate module, instead of dumping it in markdown-core.

I expect the inline rendering API might need some more work before being fully functional; we'll see as we start using it.

4. Code cleanup

rock3r added 5 commits July 19, 2024 11:24
The vast majority of Markdown use cases will be displaying static text,
so trying to optimise for an editor-like scenario is counter-productive.
This PR sets the flag to false by default.

This commit also cleans up the MarkdownProcessor code and kdocs.
The value classes we used to use would rely on the CommonMark models for
this, but none of the CommonMark models actually implement equals() and
hashCode(), leading to issues in tests and in Compose.
Now links point to GitHub, so the app doesn't crash when you click them.
Tests have been updated to match the new behaviour, that's closer to the
CommonMark one. Now we don't carry unparsed inline Markdown anymore, but
rather we fully parse it in advance, so rendering it later is easier and
doesn't require running parsing in the UI anymore.

This is a tradeoff in memory usage for speed of rendering, and it makes
sense in the context of most Markdown text being static and only parsed
once, then kept on screen.

Inline extensions are now possible, but not tested. This makes #325
possible, since the extension now can be moved to its own module.

Note: please don't look too much at the test changes. They're _verbose_,
and are only there to ensure CommonMark specs compliance.
This is not tested, and not used yet, so it may or may not need tweaks
down the line. We'll find out when we implement the first extension.
@rock3r rock3r added the markdown This issue impacts the Markdown rendering subsystem label Jul 19, 2024
@rock3r rock3r requested review from hamen and obask July 19, 2024 09:35
@rock3r rock3r self-assigned this Jul 19, 2024
@rock3r rock3r enabled auto-merge (squash) July 19, 2024 09:38
@@ -130,7 +130,7 @@ The standalone theme can be used in any Compose for Desktop app. You use it as a
to your heart's content. By default, it matches the official Int UI specs.

For an example on how to set up a standalone app, you can refer to
the [`standalone` sample](samples/standalone/build.gradle.kts).
the [`standalone` sample](https://github.com/JetBrains/jewel/blob/main/samples/standalone/build.gradle.kts).
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought about doing this when I worked on links 👍🏻

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
markdown This issue impacts the Markdown rendering subsystem
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants