Skip to content

Add Copy markdown to copy citation #13387

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 23 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 11 commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
b9ab287
fix:Added copy Markdown to copy citation #12552.
tushar-panto Jun 21, 2025
9de6531
Merge branch 'main' into fix-for-issue-12552
tushar-2320 Jun 21, 2025
ad09503
Merge branch 'main' into fix-for-issue-12552
tushar-2320 Jun 21, 2025
84a1dd1
Merge branch 'main' into fix-for-issue-12552
tushar-2320 Jun 22, 2025
8bed13b
Merge branch 'main' into fix-for-issue-12552
tushar-2320 Jun 22, 2025
fae3c18
Merge branch 'main' into fix-for-issue-12552
tushar-2320 Jun 23, 2025
49b035b
fix:Added copy Markdown to copy citation #12552.
tushar-panto Jun 23, 2025
8654adc
Merge branch 'main' into fix-for-issue-12552
tushar-2320 Jun 24, 2025
d582566
fix:Added copy Markdown to copy citation #12552.
tushar-panto Jun 24, 2025
9c32813
Merge remote-tracking branch 'origin/fix-for-issue-12552' into fix-fo…
tushar-panto Jun 24, 2025
508b93d
fix:Added @visibleForTesting in method processMarkdown #12552.
tushar-panto Jun 27, 2025
d131b92
Merge branch 'main' into fix-for-issue-12552
koppor Jul 7, 2025
0553179
Merge branch 'main' into fix-for-issue-12552
tushar-2320 Jul 19, 2025
529c9f0
Merge remote-tracking branch 'origin/fix-for-issue-12552' into fix-fo…
tushar-panto Jul 19, 2025
e805e7e
fix:submodule removal
tushar-panto Jul 19, 2025
7b3fbf7
fix:Added @visibleForTesting in method processMarkdown #12552.
tushar-panto Jul 19, 2025
b3eb93c
Revert submodule changes to match main
tushar-panto Jul 19, 2025
b1811e2
Reset submodule pointers to match main branch
tushar-panto Jul 19, 2025
34b387f
Merge branch 'main' into fix-for-issue-12552
calixtus Jul 20, 2025
756efcf
Merge branch 'main' into fix-for-issue-12552
tushar-2320 Jul 21, 2025
f6b4131
refactor:removed unecessary debugging statements and whitespace strip…
tushar-panto Jul 21, 2025
85dce83
refactor:used List.of instead of Array.asList
tushar-panto Jul 21, 2025
76eae89
Merge branch 'main' into fix-for-issue-12552
tushar-2320 Jul 23, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions jabgui/src/main/java/module-info.java
Original file line number Diff line number Diff line change
Expand Up @@ -188,5 +188,7 @@
requires org.antlr.antlr4.runtime;
requires org.libreoffice.uno;
requires com.dlsc.pdfviewfx;
// requires flexmark;
// requires flexmark.util.ast;
// endregion
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ public enum StandardActions implements Action {
COPY_KEY_AND_LINK(Localization.lang("Copy citation key and link"), KeyBinding.COPY_CITATION_KEY_AND_LINK),
COPY_CITATION_HTML(Localization.lang("Copy citation (html)"), KeyBinding.COPY_PREVIEW),
COPY_CITATION_TEXT(Localization.lang("Copy citation (text)")),
COPY_CITATION_MARKDOWN(Localization.lang("Copy citation (markdown)")),
COPY_CITATION_PREVIEW(Localization.lang("Copy preview"), KeyBinding.COPY_PREVIEW),
EXPORT_TO_CLIPBOARD(Localization.lang("Export to clipboard"), IconTheme.JabRefIcons.EXPORT_TO_CLIPBOARD),
EXPORT_SELECTED_TO_CLIPBOARD(Localization.lang("Export selected entries to clipboard"), IconTheme.JabRefIcons.EXPORT_TO_CLIPBOARD),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,8 @@ private static Menu createCopySubMenu(ActionFactory factory,
if (previewPreferences.getSelectedPreviewLayout() instanceof CitationStylePreviewLayout) {
copySpecialMenu.getItems().addAll(
factory.createMenuItem(StandardActions.COPY_CITATION_HTML, new CopyCitationAction(CitationStyleOutputFormat.HTML, dialogService, stateManager, clipBoardManager, taskExecutor, preferences, abbreviationRepository)),
factory.createMenuItem(StandardActions.COPY_CITATION_TEXT, new CopyCitationAction(CitationStyleOutputFormat.TEXT, dialogService, stateManager, clipBoardManager, taskExecutor, preferences, abbreviationRepository)));
factory.createMenuItem(StandardActions.COPY_CITATION_TEXT, new CopyCitationAction(CitationStyleOutputFormat.TEXT, dialogService, stateManager, clipBoardManager, taskExecutor, preferences, abbreviationRepository)),
factory.createMenuItem(StandardActions.COPY_CITATION_MARKDOWN, new CopyCitationAction(CitationStyleOutputFormat.MARKDOWN, dialogService, stateManager, clipBoardManager, taskExecutor, preferences, abbreviationRepository)));
} else {
copySpecialMenu.getItems().add(factory.createMenuItem(StandardActions.COPY_CITATION_PREVIEW, new CopyCitationAction(CitationStyleOutputFormat.HTML, dialogService, stateManager, clipBoardManager, taskExecutor, preferences, abbreviationRepository)));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@

import com.airhacks.afterburner.injection.Injector;
import com.google.common.annotations.VisibleForTesting;
import com.vladsch.flexmark.html2md.converter.FlexmarkHtmlConverter;

public class ClipboardContentGenerator {

Expand All @@ -45,6 +46,7 @@ public ClipboardContent generate(List<BibEntry> selectedEntries, CitationStyleOu
return switch (outputFormat) {
case HTML -> processHtml(citations);
case TEXT -> processText(citations);
case MARKDOWN -> processMarkdown(citations);
};
} else {
// if it is not a citation style take care of the preview
Expand Down Expand Up @@ -120,6 +122,32 @@ static ClipboardContent processHtml(List<String> citations) {
return content;
}

/**
* Insert each citation into HTML.
* convert HTML to markdown using flexmark.
*/
Comment on lines +125 to +128
Copy link

Choose a reason for hiding this comment

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

The comment is trivial and simply restates what the code does without providing additional information about the reasoning or important details about the implementation.

@VisibleForTesting
static ClipboardContent processMarkdown(List<String> citations) {
Copy link

Choose a reason for hiding this comment

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

The method uses string concatenation for multiline HTML template instead of Java text blocks ("""). This makes the code less readable and maintainable.

String result = "<!DOCTYPE html>" + OS.NEWLINE +
"<html>" + OS.NEWLINE +
" <head>" + OS.NEWLINE +
" <meta charset=\"utf-8\">" + OS.NEWLINE +
" </head>" + OS.NEWLINE +
" <body>" + OS.NEWLINE + OS.NEWLINE;

result += String.join(CitationStyleOutputFormat.HTML.getLineSeparator(), citations);
result += OS.NEWLINE +
" </body>" + OS.NEWLINE +
"</html>" + OS.NEWLINE;

FlexmarkHtmlConverter converter = FlexmarkHtmlConverter.builder().build();
String markdown = converter.convert(result);

ClipboardContent content = new ClipboardContent();
content.putString(markdown);
return content;
}

private List<String> generateTextBasedPreviewLayoutCitations(List<BibEntry> selectedEntries, BibDatabaseContext bibDatabaseContext) throws IOException {
TextBasedPreviewLayout customPreviewLayout = previewPreferences.getCustomPreviewLayout();
Reader customLayoutReader = Reader.of(customPreviewLayout.getText().replace("__NEWLINE__", "\n"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
public enum CitationStyleOutputFormat {

HTML("html", OS.NEWLINE + "<br>" + OS.NEWLINE),
TEXT("text", "");
TEXT("text", ""),
MARKDOWN("markdown", "");

private final String format;
private final String lineSeparator;
Expand Down
Loading