Skip to content

Conversation

@prathamxx
Copy link
Contributor

@prathamxx prathamxx commented Jun 16, 2025

Closes #13041

Description

This PR provides a proper fix for the HTML citation copy functionality in the entry preview panel. Previously, when clicking “Copy citation (HTML)”, all formatting and highlighting were lost. This was due to the copyPreviewHtmlToClipBoard() method using getTextContent(), which strips away all HTML elements and style data.

Issue:

The copied content lacks formatting, emphasis, or structure — defeating the purpose of copying HTML.

Comparison:

The “Copy preview” functionality in the main table uses the correct mechanism via CopyCitationAction, which leverages ClipboardContentGenerator.generateCitations() and retains proper HTML structure.

Changes

File: src/main/java/org/jabref/gui/preview/PreviewViewer.java

What:

Replaced the incorrect call to getTextContent() with a proper integration of CopyCitationAction, which uses the citation layout generator to produce well-structured HTML and plain-text versions.

How:

Introduced CopyCitationAction usage in copyPreviewHtmlToClipBoard(), aligned with how it is invoked in the main table right-click menu.
130
Now relies on ClipboardContentGenerator.generateCitations() for consistent formatting.

Result:

Correct and consistent HTML structure is now copied.

Highlighting, formatting, and full HTML tags are preserved.

Aligns functionality with main table's citation copy behavior.

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)
  • 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.

@prathamxx prathamxx closed this Jun 16, 2025
@prathamxx prathamxx reopened this Jun 16, 2025
@calixtus
Copy link
Member

About the PR description: Do not put your code changes in there. Put it into the code. This is what the git diff in github is for.
Also mind the description for the checkboxes. Check what is applicable, mark as with / or . what is not applicable. Just checking everything is wrong. You did not change the documentation. You did not add screenshots.

Copy link
Member

@calixtus calixtus left a comment

Choose a reason for hiding this comment

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

Multiple violations of checkstyle rules.
Please set up your workspace correctly!
https://devdocs.jabref.org/getting-into-the-code/guidelines-for-setting-up-a-local-workspace/intellij-13-code-style.html#step-3-set-up-jabrefs-code-style

I don't see that you have applied your proposed fix:
grafik

I only see this:

grafik
grafik
grafik

Document document = previewView.getEngine().getDocument();
ClipboardContent content = ClipboardContentGenerator.processHtml(List.of(document.getElementById("content").getTextContent()));
Document doc = previewView.getEngine().getDocument();
ClipboardContent content = ClipboardContentGenerator.processHtml(Arrays.asList(doc.getElementById("content").getTextContent()));
Copy link
Member

Choose a reason for hiding this comment

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

Avoid abbreviations. Use modern Java factory methods.

@calixtus calixtus changed the title Fix for issue 13041 Copy real HTML from entry preview Jun 16, 2025
@prathamxx prathamxx requested a review from calixtus June 16, 2025 16:05
@prathamxx prathamxx requested a review from calixtus June 16, 2025 16:31
@calixtus calixtus added status: ready-for-review Pull Requests that are ready to be reviewed by the maintainers component: entry-preview labels Jun 17, 2025
@calixtus calixtus enabled auto-merge June 17, 2025 21:43
@prathamxx
Copy link
Contributor Author

What changes are needed kindly guide me.

@prathamxx prathamxx closed this Jun 18, 2025
auto-merge was automatically disabled June 18, 2025 14:56

Pull request was closed

@prathamxx prathamxx reopened this Jun 18, 2025
@trag-bot
Copy link

trag-bot bot commented Jun 18, 2025

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

@Siedlerchr Siedlerchr added this pull request to the merge queue Jun 18, 2025
@Siedlerchr
Copy link
Member

Works! Looks good now.

Merged via the queue into JabRef:main with commit d816b5c Jun 18, 2025
1 check passed
Siedlerchr added a commit to ganesh-vk/jabref that referenced this pull request Jun 18, 2025
* upstream/main: (54 commits)
  Move publishing to maven central to a separate workflow (JabRef#13372)
  Add more guards to workflows not running on forked JabRef repos
  Copy real HTML from entry preview (JabRef#13339)
  Adapt some fetcher tests (JabRef#13370)
  change template issue number (JabRef#13367)
  Refine error message in URLUtil::create (JabRef#13337)
  fix deletion again (JabRef#13369)
  Only prevent failure in publishing from stopping the workflow (JabRef#13368)
  Refactor "enableFileAnnotationsTab" to "smartFileAnnotationsTab" and rewrote shouldShow in FileAnnotationTab as requested in JabRef#13279 (JabRef#13338)
  fix workflow (JabRef#13366)
  Fixamd64linux (JabRef#13365)
  Only delete for arm64 (JabRef#13364)
  New Crowdin updates (JabRef#13363)
  Bump org.junit.jupiter:junit-jupiter-api in /versions (JabRef#13362)
  Bump org.apache.logging.log4j:log4j-to-slf4j in /versions (JabRef#13359)
  Bump com.github.javaparser:javaparser-symbol-solver-core in /versions (JabRef#13361)
  Bump org.junit.platform:junit-platform-launcher in /versions (JabRef#13360)
  Bump com.fasterxml.jackson.datatype:jackson-datatype-jsr310 in /versions (JabRef#13358)
  Gradle build updates (JabRef#13319)
  Add "Disable GitHub actions" (JabRef#13356)
  ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

component: entry-preview status: ready-for-review Pull Requests that are ready to be reviewed by the maintainers

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Copy entry preview should copy real HTML

3 participants