Skip to content

Add Markdown rendering to AI Chat #13194

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

Open
wants to merge 15 commits into
base: main
Choose a base branch
from
Open

Conversation

Yubo-Cao
Copy link
Contributor

Closes #12234

See this: https://drive.google.com/file/d/1VOvWBLP5E9I_sLXd7RpShfXoP0ttg0JZ/view?usp=sharing for a quick demo. Ctrl+C is supported as a part of this PR as well.

Mandatory checks

  • I own the copyright of the code submitted and I license it under the MIT license
  • Change in CHANGELOG.md described in a way that is understandable for the average user (if change is visible to the user)
  • Tests created for changes (if applicable) (not applicable)
  • Manually tested changed features in running JabRef (always required)
  • Screenshots added in PR description (if change is visible to the user)
  • Checked developer's documentation: Is the information available and up to date? If not, I outlined it in this pull request.
  • Checked documentation: Is the information available and up to date? If not, I created an issue at https://github.com/JabRef/user-documentation/issues or, even better, I submitted a pull request to the documentation repository.

subhramit
subhramit previously approved these changes May 30, 2025
Copy link
Member

@subhramit subhramit left a comment

Choose a reason for hiding this comment

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

Code reads really good.
Did not try out, but demo is attached to the description, so green from me.
Thanks @Yubo-Cao!

@koppor
Copy link
Member

koppor commented May 31, 2025

See this: drive.google.com/file/d/1VOvWBLP5E9I_sLXd7RpShfXoP0ttg0JZ/view?usp=sharing for a quick demo.

Looks very nice.

Side track: "Summary" is a very different AI function, therefore @InAnYan put another tab for "Summary". -- For instance, for large PDFs, JabRef splits into chuncks and summarizes chunks.

Copy link
Member

@koppor koppor left a comment

Choose a reason for hiding this comment

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

Only a small comment.

Are spaces correctly handled for the getTextFlowContent()?

I assume, adding test cases is too hard here?

@ThiloteE

This comment was marked as resolved.

@InAnYan
Copy link
Member

InAnYan commented May 31, 2025

This is wonderful, Yubo!

image

I can copy text! And you also solved a very very naughty problem, when you could click on past messages and chat scrolled down! That problem make me feel desperate about JavaFX.

I could approve this PR without reviewing code 😄

Though, I remembered I have one small addition

Copy link
Member

@InAnYan InAnYan left a comment

Choose a reason for hiding this comment

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

Unfortunately, I had to request one small change

/**
* A TextFlow that allows text selection and copying.
*/
public class SelectableTextFlow extends TextFlow {
Copy link
Member

Choose a reason for hiding this comment

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

OMG, Yubo, is it possible to submit this code to some library? GemsFX maybe? This is a very useful piece of code

Copy link
Member

Choose a reason for hiding this comment

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

+1 for GemsFX. If the maintainer Dirk doesn't want it, then ControlsFX

@Yubo-Cao
Copy link
Contributor Author

Yubo-Cao commented Jun 1, 2025

Only a small comment.

Are spaces correctly handled for the getTextFlowContent()?

I assume, adding test cases is too hard here?

So after actually switch to Arch Linux and run testcases over there (of course that was not needed at all to come up with this conclusion looking at how I butchered the Markdown AST), is that we currently don't handle whitespace perfectly, if at all.

  1. White space inside a single markdown node is always preserved, so *italic with space* that kind of thing is OK
  2. White space between nodes is always not preserved.
  3. Bulleted indentation always get destroyed (if you nest).
  4. Original markdown style marker would always disappear (think * and all those special characters)

I think my new attempt would be trying to keep track a bit more metadata in MarkdownTextflow and basically override getTextFlowContent.

@subhramit
Copy link
Member

@Yubo-Cao Please resolve conversations after you push the commits resolving them, not before

@Yubo-Cao Yubo-Cao requested a review from InAnYan June 2, 2025 22:10
@subhramit
Copy link
Member

If things get too convoluted, git merge upstream/main, git reset upstream/main and then make a fresh commit. you may have to force push.

Note: gitk --all to have the commit ids ready in gitk in case something goes wrong. Your local changes should not be lost, but it is always a good idea to have a trace/backup.

@subhramit
Copy link
Member

If things get too convoluted, git merge upstream/main, git reset upstream/main and then make a fresh commit. you may have to force push.

Note: gitk --all to have the commit ids ready in gitk in case something goes wrong. Your local changes should not be lost, but it is always a good idea to have a trace/backup.

Another handy resource: https://ohshitgit.com/

@koppor
Copy link
Member

koppor commented Jun 2, 2025

If things get too convoluted, git merge upstream/main, git reset upstream/main and then make a fresh commit. you may have to force push.

However, JabRef mainatinaers don't like force pushes - only in rare emergency cases ^^

I always direct to https://lostechies.com/joshuaflanagan/2010/09/03/use-gitk-to-understand-git/ -- then, the git commands should be more understandable.

@Yubo-Cao
Copy link
Contributor Author

Yubo-Cao commented Jun 2, 2025

Before all, thank you so much for y'all's assistance in correcting me about proper usage of Resolve Conversation and Git. Apologies for any inconvenience or potential offense that may have caused. I really appreciated your understanding and patience.

In this update, the following features were added

  1. HTML and Markdown copy of Markdown textflow.
  2. Better white space handling in regard of paragraphs, bullets, etc.
  3. Block quote and code block as fall back rendering method.

A demo can be found here: https://drive.google.com/file/d/16zosXoTq0dgksYshqLzKkAGXudKaCv3b/view?usp=drive_link

@InAnYan
Copy link
Member

InAnYan commented Jun 4, 2025

I'm still getting that error with getScene() is null.

And BTW I'm on Arch too, and I didn't spot any major problems with Markdown rendering

});
NumberBinding maxUsableWidth = Bindings.createDoubleBinding(
() -> getScene() == null ? 600 : getScene().getWidth() - 20, sceneProperty(),
getScene() == null ? widthProperty() : getScene().widthProperty()
Copy link
Member

Choose a reason for hiding this comment

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

Is it possible to add a comment in which cases Scene is null?

Or is it "magically" null and we don't know - then maybe also comment that it is unclar, but we need to check

Reason null is an indicaton that there is some bug in the code. In this case, it seems to be life-cycle related.

--> Could help to create an MWE and mayb file a JavaFX issue - its not always on our side that something is wrong - see e.g., JabRef#713

Copy link
Member

@InAnYan InAnYan Jun 5, 2025

Choose a reason for hiding this comment

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

When I proposed my fix, I used this answer of StackOverflow (warning: non-English):

link

I think the author gives a good, if you let me say this, "idiom" of handling this

Copy link

trag-bot bot commented Jun 6, 2025

@trag-bot didn't find any issues in the code! ✅✨

@JabRef JabRef deleted a comment from trag-bot bot Jun 6, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Use Markdown in AI chat messages
6 participants