Skip to content

Commit 0088d0d

Browse files
committed
simplify
1 parent 202ff79 commit 0088d0d

File tree

4 files changed

+12
-84
lines changed

4 files changed

+12
-84
lines changed

jabgui/src/main/java/org/jabref/gui/preview/ClipboardContentGenerator.java

Lines changed: 9 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,10 @@
2323

2424
import com.airhacks.afterburner.injection.Injector;
2525
import com.google.common.annotations.VisibleForTesting;
26-
import com.vladsch.flexmark.html2md.converter.FlexmarkHtmlConverter;
2726

2827
public class ClipboardContentGenerator {
2928

30-
private PreviewPreferences previewPreferences;
29+
private final PreviewPreferences previewPreferences;
3130
private final LayoutFormatterPreferences layoutFormatterPreferences;
3231
private final JournalAbbreviationRepository abbreviationRepository;
3332

@@ -46,7 +45,7 @@ public ClipboardContent generate(List<BibEntry> selectedEntries, CitationStyleOu
4645
return switch (outputFormat) {
4746
case HTML -> processHtml(citations);
4847
case TEXT -> processText(citations);
49-
case MARKDOWN -> processMarkdown(citations, true);
48+
case MARKDOWN -> processMarkdown(citations);
5049
};
5150
} else {
5251
// if it is not a citation style take care of the preview
@@ -123,55 +122,17 @@ static ClipboardContent processHtml(List<String> citations) {
123122
}
124123

125124
/**
126-
* Converts a list of citations to Markdown.
125+
* Joins each citation using the platform-specific newline into a single Markdown string (from citeproc) and copies it to the clipboard.
126+
* <p>
127+
* A trailing newline is appended if missing to keep the behavior consistent with other output formats
128+
* and to satisfy tests expecting a newline-terminated string.
127129
*
128-
* Behavior:
129-
* - If the citations appear to be HTML (e.g., CSL HTML output), convert via Flexmark (HTML -> Markdown).
130-
* - Otherwise, assume the citations are already Markdown (e.g., CSL Markdown output) and just join them.
130+
* @param citations the list of already-formatted citation strings to be combined as Markdown
131+
* @return clipboard content containing the Markdown representation in its plain string flavor
131132
*/
132133
@VisibleForTesting
133134
static ClipboardContent processMarkdown(List<String> citations) {
134-
// Default behavior (non-CSL-aware): detect HTML vs Markdown by content
135-
return processMarkdown(citations, false);
136-
}
137-
138-
/**
139-
* Converts a list of citations to Markdown.
140-
*
141-
* If fromCitationStyle is true, we assume the list items are already Markdown (produced by citeproc-java with
142-
* output format MARKDOWN) and simply join them with new lines. Otherwise, we fall back to HTML detection and
143-
* Flexmark-based conversion when needed.
144-
*/
145-
@VisibleForTesting
146-
static ClipboardContent processMarkdown(List<String> citations, boolean fromCitationStyle) {
147-
String markdown;
148-
if (fromCitationStyle) {
149-
markdown = String.join(OS.NEWLINE, citations);
150-
} else {
151-
boolean looksLikeHtml = citations.stream().anyMatch(s -> (s != null) && s.contains("<") && s.contains(">"));
152-
153-
if (looksLikeHtml) {
154-
// Existing behavior: wrap HTML and use Flexmark to convert to Markdown
155-
String result = "<!DOCTYPE html>" + OS.NEWLINE +
156-
"<html>" + OS.NEWLINE +
157-
" <head>" + OS.NEWLINE +
158-
" <meta charset=\"utf-8\">" + OS.NEWLINE +
159-
" </head>" + OS.NEWLINE +
160-
" <body>" + OS.NEWLINE + OS.NEWLINE;
161-
162-
result += String.join(CitationStyleOutputFormat.HTML.getLineSeparator(), citations);
163-
result += OS.NEWLINE +
164-
" </body>" + OS.NEWLINE +
165-
"</html>" + OS.NEWLINE;
166-
167-
FlexmarkHtmlConverter converter = FlexmarkHtmlConverter.builder().build();
168-
markdown = converter.convert(result);
169-
} else {
170-
// Assume already Markdown (e.g., citeproc-java's "markdown" output)
171-
// Join entries with a single newline between them
172-
markdown = String.join(OS.NEWLINE, citations);
173-
}
174-
}
135+
String markdown = String.join(OS.NEWLINE, citations);
175136

176137
// Ensure trailing newline at end for consistency with other output formats/tests
177138
if (!markdown.endsWith(OS.NEWLINE)) {

jabgui/src/test/java/org/jabref/gui/preview/ClipboardContentGeneratorTest.java

Lines changed: 2 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -19,16 +19,14 @@ void processPreviewText() {
1919
"Smith, B.; Jones, B. &amp; Williams, J." + OS.NEWLINE +
2020
"Taylor, P. (Ed.)" + OS.NEWLINE +
2121
"Title of the test entry " + OS.NEWLINE +
22-
"BibTeX Journal, JabRef Publishing, 2016, 34, 45-67 " + OS.NEWLINE +
23-
"" + OS.NEWLINE +
22+
"BibTeX Journal, JabRef Publishing, 2016, 34, 45-67 " + OS.NEWLINE + OS.NEWLINE +
2423
"Abstract: This entry describes a test scenario which may be useful in JabRef. By providing a test entry it is possible to see how certain things will look in this graphical BIB-file mananger. " + OS.NEWLINE +
2524
"<br>" + OS.NEWLINE +
2625
"Article (Smith2016)" + OS.NEWLINE +
2726
"Smith, B.; Jones, B. &amp; Williams, J." + OS.NEWLINE +
2827
"Taylor, P. (Ed.)" + OS.NEWLINE +
2928
"Title of the test entry " + OS.NEWLINE +
30-
"BibTeX Journal, JabRef Publishing, 2016, 34, 45-67 " + OS.NEWLINE +
31-
"" + OS.NEWLINE +
29+
"BibTeX Journal, JabRef Publishing, 2016, 34, 45-67 " + OS.NEWLINE + OS.NEWLINE +
3230
"Abstract: This entry describes a test scenario which may be useful in JabRef. By providing a test entry it is possible to see how certain things will look in this graphical BIB-file mananger. ";
3331

3432
String citation = "Article (Smith2016)" + OS.NEWLINE +
@@ -139,26 +137,8 @@ void processHtmlAsHtml() {
139137
assertEquals(expected, actual);
140138
}
141139

142-
@Test
143-
void processMarkdownAsMarkdown() {
144-
String expected = "\\[1\\] \n" +
145-
"B. Smith, B. Jones, and J. Williams, \"Title of the test entry,\" *BibTeX Journal*, vol. 34, no. 3, pp. 45--67, Jul. 2016.\n" +
146-
"\n" +
147-
"\\[1\\] \n" +
148-
"B. Smith, B. Jones, and J. Williams, \"Title of the test entry,\" *BibTeX Journal*, vol. 34, no. 3, pp. 45--67, Jul. 2016.\n";
149-
150-
String citation = " <div class=\"csl-entry\">" + OS.NEWLINE +
151-
" <div class=\"csl-left-margin\">[1]</div><div class=\"csl-right-inline\">B. Smith, B. Jones, and J. Williams, “Title of the test entry,” <i>BibTeX Journal</i>, vol. 34, no. 3, pp. 45–67, Jul. 2016.</div>" + OS.NEWLINE +
152-
" </div>" + OS.NEWLINE;
153-
154-
ClipboardContent markdown = ClipboardContentGenerator.processMarkdown(List.of(citation, citation));
155-
String actual = markdown.getString();
156-
assertEquals(expected, actual);
157-
}
158-
159140
@Test
160141
void processCslMarkdownAsMarkdown() {
161-
// This test documents the native citeproc-java Markdown output compared to Flexmark conversion
162142
String citationMd = "[1] " + OS.NEWLINE +
163143
"B. Smith, B. Jones, and J. Williams, \"Title of the test entry,\" *BibTeX Journal*, vol. 34, no. 3, pp. 45--67, Jul. 2016.";
164144

jablib/src/main/java/org/jabref/logic/citationstyle/CSLAdapter.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,5 +78,6 @@ private void initialize(String newStyle, CitationStyleOutputFormat newFormat) th
7878
cslInstance.setOutputFormat(newFormat.getFormat());
7979
format = newFormat;
8080
}
81+
cslInstance.setConvertLinks(true);
8182
}
8283
}

jablib/src/main/java/org/jabref/logic/citationstyle/CitationStyleGenerator.java

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -51,14 +51,6 @@ protected static String generateBibliography(List<BibEntry> bibEntries, String s
5151
return generateBibliography(bibEntries, style, CitationStyleOutputFormat.HTML, context, entryTypesManager).getFirst();
5252
}
5353

54-
/**
55-
* Generates a bibliography list in Markdown format based on a given list of entries and .csl style source content with a default {@link BibDatabaseContext}.
56-
*/
57-
protected static String generateBibliographyMarkdown(List<BibEntry> bibEntries, String style, BibEntryTypesManager entryTypesManager) {
58-
BibDatabaseContext context = new BibDatabaseContext(new BibDatabase(bibEntries));
59-
context.setMode(BibDatabaseMode.BIBLATEX);
60-
return generateBibliography(bibEntries, style, CitationStyleOutputFormat.MARKDOWN, context, entryTypesManager).getFirst();
61-
}
6254

6355
/**
6456
* Generates a bibliography list based on a given list of entries, .csl style source content and output format with a given {@link BibDatabaseContext}.
@@ -85,10 +77,4 @@ public static List<String> generateBibliography(List<BibEntry> bibEntries, Strin
8577
}
8678
}
8779

88-
/**
89-
* Generates a bibliography list in Markdown format based on a given list of entries, .csl style source content and a given {@link BibDatabaseContext}.
90-
*/
91-
public static List<String> generateBibliographyMarkdown(List<BibEntry> bibEntries, String style, BibDatabaseContext databaseContext, BibEntryTypesManager entryTypesManager) {
92-
return generateBibliography(bibEntries, style, CitationStyleOutputFormat.MARKDOWN, databaseContext, entryTypesManager);
93-
}
9480
}

0 commit comments

Comments
 (0)