Skip to content

Add Markdown rendering to AI Chat#13194

Merged
subhramit merged 27 commits into
JabRef:mainfrom
Yubo-Cao:markdown-ai
Jul 4, 2025
Merged

Add Markdown rendering to AI Chat#13194
subhramit merged 27 commits into
JabRef:mainfrom
Yubo-Cao:markdown-ai

Conversation

@Yubo-Cao

@Yubo-Cao Yubo-Cao commented May 30, 2025

Copy link
Copy Markdown
Collaborator

Closes #12234 (partially)

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.

Before:
image

After:
image
image
image

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.

Comment thread jabgui/src/main/java/org/jabref/gui/util/MarkdownTextFlow.java Outdated
subhramit
subhramit previously approved these changes May 30, 2025

@subhramit subhramit left a comment

Copy link
Copy Markdown
Member

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

koppor commented May 31, 2025

Copy link
Copy Markdown
Member

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.

@koppor koppor left a comment

Copy link
Copy Markdown
Member

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?

Comment thread jabgui/src/main/java/module-info.java Outdated
Comment thread jabgui/src/main/java/org/jabref/gui/util/SelectableTextFlow.java Outdated
@ThiloteE

This comment was marked as resolved.

Comment thread jabgui/src/main/java/org/jabref/gui/util/MarkdownTextFlow.java Outdated
@InAnYan

InAnYan commented May 31, 2025

Copy link
Copy Markdown
Member

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

@InAnYan InAnYan left a comment

Copy link
Copy Markdown
Member

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
Copy Markdown
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
Copy Markdown
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

Comment thread jabgui/src/main/java/module-info.java Outdated
@Yubo-Cao

Yubo-Cao commented Jun 1, 2025

Copy link
Copy Markdown
Collaborator Author

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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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

koppor commented Jun 2, 2025

Copy link
Copy Markdown
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.

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.

Comment thread jabgui/src/main/java/org/jabref/gui/util/SelectableTextFlow.java Outdated
Comment thread jabgui/src/main/java/org/jabref/gui/util/MarkdownTextFlow.java Outdated
@koppor

koppor commented Jun 29, 2025

Copy link
Copy Markdown
Member

The IOB looks like it's coming from Flexmark.
Debug and see what token(s) produce this and then file an issue at their repo

Maybe MWE using a JUnit test...

subhramit
subhramit previously approved these changes Jun 29, 2025

@subhramit subhramit left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Green from me.
To summarize, TODOs:

  1. Submission of useful jfx snippet to GemsFX/ControlsFX
  2. MWE reproduction and reporting to Flexmark
  3. File known issues in JabRef

Current:
Address Ruslan's comment on the changelog entry.

Rest seems good to go, thank you for such wonderful work, Yubo.

@Yubo-Cao Yubo-Cao dismissed stale reviews from subhramit and InAnYan via e3fa14f June 29, 2025 14:22
@Yubo-Cao

Copy link
Copy Markdown
Collaborator Author

I cannot reproduce the errors that Ruslan encountered. However, I added a check for string boundaries to ensure that this won't happen. Regarding the color contrast, I simply derived -jr-theme up a bit, and I think that would be sufficient.

screenshot

W3C Contrast checker

Comment thread jabgui/src/main/java/org/jabref/gui/util/MarkdownTextFlow.java Outdated
Comment thread jabgui/src/main/java/org/jabref/gui/util/MarkdownTextFlow.java
@InAnYan

InAnYan commented Jun 29, 2025

Copy link
Copy Markdown
Member

OMG, maybe it is something wrong with my machine, if Yubo cannot reproduce my issues 🤣

Nice color change

subhramit
subhramit previously approved these changes Jun 29, 2025
@calixtus

Copy link
Copy Markdown
Member

Can you do a screenshot with dark theme too please?

@subhramit subhramit added status: awaiting-second-review For non-trivial changes and removed status: ready-for-review Pull Requests that are ready to be reviewed by the maintainers labels Jun 29, 2025
@Yubo-Cao

Yubo-Cao commented Jul 1, 2025

Copy link
Copy Markdown
Collaborator Author

Can you do a screenshot with dark theme too please?

Thank you so much for the catch! I honestly forget about the dark theme users ...

图片

subhramit
subhramit previously approved these changes Jul 4, 2025

@subhramit subhramit left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Failing tests are related to CSL, so I am queuing this. Nvm there's conflicts and failing build tests too.

@koppor

koppor commented Jul 4, 2025

Copy link
Copy Markdown
Member

Failing tests are related to CSL, so I am queuing this. Nvm there's conflicts and failing build tests too.

I reverted CSL so that the assigned contributor has time to work on it.

@trag-bot

trag-bot Bot commented Jul 4, 2025

Copy link
Copy Markdown

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

@subhramit subhramit added this pull request to the merge queue Jul 4, 2025
@subhramit subhramit removed the status: awaiting-second-review For non-trivial changes label Jul 4, 2025
Merged via the queue into JabRef:main with commit f41f8ab Jul 4, 2025
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Use Markdown in AI chat messages

7 participants