diff --git a/CHANGELOG.md b/CHANGELOG.md index 08c2e298cda..25aba2bc5a5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,6 +13,8 @@ Note that this project **does not** adhere to [Semantic Versioning](http://semve ### Changed +- The CSL preview styles now also support displaying data from cross references entries that are linked via the `crossref` field [#7378](https://github.com/JabRef/jabref/issues/7378) + ### Fixed - We fixed an issue where an exception could occur when saving the preferences [#7614](https://github.com/JabRef/jabref/issues/7614) diff --git a/src/main/java/org/jabref/gui/maintable/RightClickMenu.java b/src/main/java/org/jabref/gui/maintable/RightClickMenu.java index a8b21da429f..3da675e9272 100644 --- a/src/main/java/org/jabref/gui/maintable/RightClickMenu.java +++ b/src/main/java/org/jabref/gui/maintable/RightClickMenu.java @@ -106,11 +106,8 @@ private static Menu createCopySubMenu(ActionFactory factory, if (previewPreferences.getSelectedPreviewLayout() instanceof CitationStylePreviewLayout) { copySpecialMenu.getItems().add(factory.createMenuItem(StandardActions.COPY_CITATION_HTML, new CopyCitationAction(CitationStyleOutputFormat.HTML, dialogService, stateManager, clipBoardManager, taskExecutor, previewPreferences))); Menu copyCitationMenu = factory.createMenu(StandardActions.COPY_CITATION_MORE); - copyCitationMenu.getItems().addAll( - factory.createMenuItem(StandardActions.COPY_CITATION_TEXT, new CopyCitationAction(CitationStyleOutputFormat.TEXT, dialogService, stateManager, clipBoardManager, taskExecutor, previewPreferences)), - factory.createMenuItem(StandardActions.COPY_CITATION_RTF, new CopyCitationAction(CitationStyleOutputFormat.RTF, dialogService, stateManager, clipBoardManager, taskExecutor, previewPreferences)), - factory.createMenuItem(StandardActions.COPY_CITATION_ASCII_DOC, new CopyCitationAction(CitationStyleOutputFormat.ASCII_DOC, dialogService, stateManager, clipBoardManager, taskExecutor, previewPreferences)), - factory.createMenuItem(StandardActions.COPY_CITATION_XSLFO, new CopyCitationAction(CitationStyleOutputFormat.XSL_FO, dialogService, stateManager, clipBoardManager, taskExecutor, previewPreferences))); + copyCitationMenu.getItems().add( + factory.createMenuItem(StandardActions.COPY_CITATION_TEXT, new CopyCitationAction(CitationStyleOutputFormat.TEXT, dialogService, stateManager, clipBoardManager, taskExecutor, previewPreferences))); copySpecialMenu.getItems().add(copyCitationMenu); } else { copySpecialMenu.getItems().add(factory.createMenuItem(StandardActions.COPY_CITATION_PREVIEW, new CopyCitationAction(CitationStyleOutputFormat.HTML, dialogService, stateManager, clipBoardManager, taskExecutor, previewPreferences))); diff --git a/src/main/java/org/jabref/gui/preview/CopyCitationAction.java b/src/main/java/org/jabref/gui/preview/CopyCitationAction.java index 83c68ba3f18..940f5aca79d 100644 --- a/src/main/java/org/jabref/gui/preview/CopyCitationAction.java +++ b/src/main/java/org/jabref/gui/preview/CopyCitationAction.java @@ -126,46 +126,6 @@ protected static ClipboardContent processText(List citations) { return content; } - /** - * Converts the citations into the RTF format. - */ - protected static ClipboardContent processRtf(List citations) { - String result = "{\\rtf" + OS.NEWLINE + - String.join(CitationStyleOutputFormat.RTF.getLineSeparator(), citations) + - "}"; - ClipboardContent content = new ClipboardContent(); - content.putString(result); - content.putRtf(result); - return content; - } - - /** - * Inserts each citation into a XLSFO body and copies it to the clipboard - */ - protected static ClipboardContent processXslFo(List citations) { - String result = "" + OS.NEWLINE + - "" + OS.NEWLINE + - " " + OS.NEWLINE + - " " + OS.NEWLINE + - " " + OS.NEWLINE + - " " + OS.NEWLINE + - " " + OS.NEWLINE + - " " + OS.NEWLINE + - " " + OS.NEWLINE + OS.NEWLINE; - - result += String.join(CitationStyleOutputFormat.XSL_FO.getLineSeparator(), citations); - - result += OS.NEWLINE + - " " + OS.NEWLINE + - " " + OS.NEWLINE + - "" + OS.NEWLINE; - - ClipboardContent content = new ClipboardContent(); - content.putString(result); - content.put(ClipBoardManager.XML, result); - return content; - } - /** * Inserts each citation into a HTML body and copies it to the clipboard */ @@ -197,9 +157,7 @@ private void setClipBoardContent(List citations) { ClipboardContent content; switch (outputFormat) { case HTML -> content = processHtml(citations); - case RTF -> content = processRtf(citations); - case XSL_FO -> content = processXslFo(citations); - case ASCII_DOC, TEXT -> content = processText(citations); + case TEXT -> content = processText(citations); default -> { LOGGER.warn("unknown output format: '" + outputFormat + "', processing it via the default."); content = processText(citations); diff --git a/src/main/java/org/jabref/logic/citationstyle/CSLAdapter.java b/src/main/java/org/jabref/logic/citationstyle/CSLAdapter.java index aac9a8a024e..bd902237a7e 100644 --- a/src/main/java/org/jabref/logic/citationstyle/CSLAdapter.java +++ b/src/main/java/org/jabref/logic/citationstyle/CSLAdapter.java @@ -101,6 +101,11 @@ private static CSLItemData bibEntryToCSLItemData(BibEntry bibEntry, BibDatabase // Not every field is already generated into latex free fields RemoveNewlinesFormatter removeNewlinesFormatter = new RemoveNewlinesFormatter(); + + // adapted from TexBibEntriesResolver + bibDatabase.getReferencedEntry(bibEntry).ifPresent(refEntry -> + refEntry.getFields().forEach(field -> bibEntry.getFieldMap().putIfAbsent(field, refEntry.getFieldOrAlias(field).orElse("")))); + for (Field key : bibEntry.getFieldMap().keySet()) { bibEntry.getResolvedFieldOrAlias(key, bibDatabase) .map(removeNewlinesFormatter::format) @@ -112,9 +117,6 @@ private static CSLItemData bibEntryToCSLItemData(BibEntry bibEntry, BibDatabase } bibTeXEntry.addField(new Key(key.getName()), new DigitStringValue(value)); - if(StandardField.CROSSREF.equals(key)) { - - } }); } return BIBTEX_CONVERTER.toItemData(bibTeXEntry); diff --git a/src/main/java/org/jabref/logic/citationstyle/CitationStyleOutputFormat.java b/src/main/java/org/jabref/logic/citationstyle/CitationStyleOutputFormat.java index 9596bb140f5..d06763cb2c1 100644 --- a/src/main/java/org/jabref/logic/citationstyle/CitationStyleOutputFormat.java +++ b/src/main/java/org/jabref/logic/citationstyle/CitationStyleOutputFormat.java @@ -4,11 +4,8 @@ public enum CitationStyleOutputFormat { - ASCII_DOC("asciidoc", ""), HTML("html", OS.NEWLINE + "
" + OS.NEWLINE), - RTF("rtf", "\\line" + OS.NEWLINE), - TEXT("text", ""), - XSL_FO("fo", OS.NEWLINE); + TEXT("text", ""); private final String format; private final String lineSeparator; diff --git a/src/test/java/org/jabref/gui/preview/CopyCitationActionTest.java b/src/test/java/org/jabref/gui/preview/CopyCitationActionTest.java index 7dec89193c5..f7ea4a8f145 100644 --- a/src/test/java/org/jabref/gui/preview/CopyCitationActionTest.java +++ b/src/test/java/org/jabref/gui/preview/CopyCitationActionTest.java @@ -4,7 +4,6 @@ import javafx.scene.input.ClipboardContent; -import org.jabref.gui.ClipBoardManager; import org.jabref.logic.util.OS; import org.junit.jupiter.api.Test; @@ -109,93 +108,6 @@ void processText() throws Exception { assertEquals(expected, actual); } - @Test - void processRtf() throws Exception { - String expected = "{\\rtf" + OS.NEWLINE + - "[1]\\tab B. Smith, B. Jones, and J. Williams, \\uc0\\u8220{}Title of the test entry,\\uc0\\u8221{} {\\i{}BibTeX Journal}, vol. 34, no. 3, pp. 45\\uc0\\u8211{}67, Jul. 2016." + OS.NEWLINE + - "\\line" + OS.NEWLINE + - "[1]\\tab B. Smith, B. Jones, and J. Williams, \\uc0\\u8220{}Title of the test entry,\\uc0\\u8221{} {\\i{}BibTeX Journal}, vol. 34, no. 3, pp. 45\\uc0\\u8211{}67, Jul. 2016." + OS.NEWLINE + - "}"; - - String citation = "[1]\\tab B. Smith, B. Jones, and J. Williams, \\uc0\\u8220{}Title of the test entry,\\uc0\\u8221{} {\\i{}BibTeX Journal}, vol. 34, no. 3, pp. 45\\uc0\\u8211{}67, Jul. 2016." + OS.NEWLINE; - ClipboardContent content = CopyCitationAction.processRtf(Arrays.asList(citation, citation)); - - Object actual = content.getRtf(); - assertEquals(expected, actual); - } - - @Test - void processXslFo() throws Exception { - String expected = "" + OS.NEWLINE + - "" + OS.NEWLINE + - " " + OS.NEWLINE + - " " + OS.NEWLINE + - " " + OS.NEWLINE + - " " + OS.NEWLINE + - " " + OS.NEWLINE + - " " + OS.NEWLINE + - " " + OS.NEWLINE + - OS.NEWLINE + - "" + OS.NEWLINE + - " " + OS.NEWLINE + - " " + OS.NEWLINE + - " " + OS.NEWLINE + - " " + OS.NEWLINE + - " " + OS.NEWLINE + - " " + OS.NEWLINE + - " [1]" + OS.NEWLINE + - " " + OS.NEWLINE + - " " + OS.NEWLINE + - " B. Smith, B. Jones, and J. Williams, “Title of the test entry,” BibTeX Journal, vol. 34, no. 3, pp. 45–67, Jul. 2016." + OS.NEWLINE + - " " + OS.NEWLINE + - " " + OS.NEWLINE + - " " + OS.NEWLINE + - " " + OS.NEWLINE + - "" + OS.NEWLINE + - OS.NEWLINE + - "" + OS.NEWLINE + - " " + OS.NEWLINE + - " " + OS.NEWLINE + - " " + OS.NEWLINE + - " " + OS.NEWLINE + - " " + OS.NEWLINE + - " " + OS.NEWLINE + - " [1]" + OS.NEWLINE + - " " + OS.NEWLINE + - " " + OS.NEWLINE + - " B. Smith, B. Jones, and J. Williams, “Title of the test entry,” BibTeX Journal, vol. 34, no. 3, pp. 45–67, Jul. 2016." + OS.NEWLINE + - " " + OS.NEWLINE + - " " + OS.NEWLINE + - " " + OS.NEWLINE + - " " + OS.NEWLINE + - "" + OS.NEWLINE + - OS.NEWLINE + - " " + OS.NEWLINE + - " " + OS.NEWLINE + - "" + OS.NEWLINE; - - String citation = "" + OS.NEWLINE + - " " + OS.NEWLINE + - " " + OS.NEWLINE + - " " + OS.NEWLINE + - " " + OS.NEWLINE + - " " + OS.NEWLINE + - " " + OS.NEWLINE + - " [1]" + OS.NEWLINE + - " " + OS.NEWLINE + - " " + OS.NEWLINE + - " B. Smith, B. Jones, and J. Williams, “Title of the test entry,” BibTeX Journal, vol. 34, no. 3, pp. 45–67, Jul. 2016." + OS.NEWLINE + - " " + OS.NEWLINE + - " " + OS.NEWLINE + - " " + OS.NEWLINE + - " " + OS.NEWLINE + - "" + OS.NEWLINE; - - ClipboardContent xmlTransferable = CopyCitationAction.processXslFo(Arrays.asList(citation, citation)); - - Object actual = xmlTransferable.get(ClipBoardManager.XML); - assertEquals(expected, actual); - } @Test void processHtmlAsHtml() throws Exception { diff --git a/src/test/java/org/jabref/logic/citationstyle/CitationStyleGeneratorTest.java b/src/test/java/org/jabref/logic/citationstyle/CitationStyleGeneratorTest.java index 6a8d84eeb69..7c398885243 100644 --- a/src/test/java/org/jabref/logic/citationstyle/CitationStyleGeneratorTest.java +++ b/src/test/java/org/jabref/logic/citationstyle/CitationStyleGeneratorTest.java @@ -1,17 +1,19 @@ package org.jabref.logic.citationstyle; +import java.util.List; + import org.jabref.logic.l10n.Localization; import org.jabref.logic.util.TestEntry; import org.jabref.model.database.BibDatabase; import org.jabref.model.entry.BibEntry; import org.jabref.model.entry.field.StandardField; +import org.jabref.model.entry.types.StandardEntryType; import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; import static org.junit.jupiter.api.Assertions.assertEquals; -@Disabled("For some reason, instead of vol and pp we get null. No idea about the origin of this problem.") class CitationStyleGeneratorTest { @Test @@ -21,7 +23,7 @@ void testIgnoreNewLine() { // if the default citation style changes this has to be modified String expected = "
\n" + - "
[1]
F. Last and J. Doe, .
\n" + + "
[1]
F. Last and J. Doe,
\n" + "
\n"; String citation = CitationStyleGenerator.generateCitation(entry, CitationStyle.getDefault()); assertEquals(expected, citation); @@ -34,7 +36,7 @@ void testIgnoreCarriageReturnNewLine() { // if the default citation style changes this has to be modified String expected = "
\n" + - "
[1]
F. Last and J. Doe, .
\n" + + "
[1]
F. Last and J. Doe,
\n" + "
\n"; String citation = CitationStyleGenerator.generateCitation(entry, CitationStyle.getDefault()); assertEquals(expected, citation); @@ -47,18 +49,9 @@ void testMissingCitationStyle() { assertEquals(expected, citation); } - @Test - void testAsciiDocFormat() { - String expectedCitation = "[1] B. Smith, B. Jones, and J. Williams, ``Title of the test entry,'' __BibTeX Journal__, vol. 34, no. 3, pp. 45–67, Jul. 2016.\n"; - BibEntry entry = TestEntry.getTestEntry(); - String style = CitationStyle.getDefault().getSource(); - CitationStyleOutputFormat format = CitationStyleOutputFormat.ASCII_DOC; - - String actualCitation = CitationStyleGenerator.generateCitation(entry, style, format, new BibDatabase()); - assertEquals(expectedCitation, actualCitation); - } @Test + @Disabled("Currently citeproc does not handler number field correctly https://github.com/JabRef/jabref/issues/8372") void testHtmlFormat() { String expectedCitation = "
\n" + "
[1]
B. Smith, B. Jones, and J. Williams, “Title of the test entry,” BibTeX Journal, vol. 34, no. 3, pp. 45–67, Jul. 2016.
\n" + @@ -71,18 +64,9 @@ void testHtmlFormat() { assertEquals(expectedCitation, actualCitation); } - @Test - void testRtfFormat() { - String expectedCitation = "[1]\\tab B. Smith, B. Jones, and J. Williams, \\uc0\\u8220{}Title of the test entry,\\uc0\\u8221{} {\\i{}BibTeX Journal}, vol. 34, no. 3, pp. 45\\uc0\\u8211{}67, Jul. 2016.\r\n"; - BibEntry entry = TestEntry.getTestEntry(); - String style = CitationStyle.getDefault().getSource(); - CitationStyleOutputFormat format = CitationStyleOutputFormat.RTF; - - String actualCitation = CitationStyleGenerator.generateCitation(entry, style, format, new BibDatabase()); - assertEquals(expectedCitation, actualCitation); - } @Test + @Disabled("Currently citeproc does not handle number field correctly https://github.com/JabRef/jabref/issues/8372") void testTextFormat() { String expectedCitation = "[1]B. Smith, B. Jones, and J. Williams, “Title of the test entry,” BibTeX Journal, vol. 34, no. 3, pp. 45–67, Jul. 2016.\n"; BibEntry entry = TestEntry.getTestEntry(); @@ -93,46 +77,22 @@ void testTextFormat() { assertEquals(expectedCitation, actualCitation); } - @Test - void testXslFoFormat() { - String expectedCitation = "\n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " [1]\n" + - " \n" + - " \n" + - " B. Smith, B. Jones, and J. Williams, “Title of the test entry,” BibTeX Journal, vol. 34, no. 3, pp. 45–67, Jul. 2016.\n" + - " \n" + - " \n" + - " \n" + - " \n" + - "\n"; - BibEntry entry = TestEntry.getTestEntry(); - String style = CitationStyle.getDefault().getSource(); - CitationStyleOutputFormat format = CitationStyleOutputFormat.XSL_FO; - - String actualCitation = CitationStyleGenerator.generateCitation(entry, style, format, new BibDatabase()); - assertEquals(expectedCitation, actualCitation); - } - @Test void testHandleDiacritics() { BibEntry entry = new BibEntry(); - entry.setField(StandardField.AUTHOR, "L{\"a}st, First and Doe, Jane"); + // We need to escape the backslash as well, because the slash is part of the LaTeX expression + entry.setField(StandardField.AUTHOR, "L{\\\"a}st, First and Doe, Jane"); // if the default citation style changes this has to be modified. // in this case ä was added to check if it is formatted appropriately String expected = "
\n" + - "
[1]
F. Läst and J. Doe, .
\n" + + "
[1]
F. Läst and J. Doe,
\n" + "
\n"; String citation = CitationStyleGenerator.generateCitation(entry, CitationStyle.getDefault()); assertEquals(expected, citation); } @Test + @Disabled("Currently citeproc does not handler number field correctly") void testHandleAmpersand() { String expectedCitation = "[1]B. Smith, B. Jones, and J. Williams, “&TitleTest&” BibTeX Journal, vol. 34, no. 3, pp. 45–67, Jul. 2016.\n"; BibEntry entry = TestEntry.getTestEntry(); @@ -143,4 +103,32 @@ void testHandleAmpersand() { String actualCitation = CitationStyleGenerator.generateCitation(entry, style, format, new BibDatabase()); assertEquals(expectedCitation, actualCitation); } + + @Test + void testHandleCrossRefFields() { + + BibEntry firstEntry = new BibEntry(StandardEntryType.InCollection) + .withCitationKey("smit2021") + .withField(StandardField.AUTHOR, "Smith, Bob") + .withField(StandardField.TITLE, "An article") + .withField(StandardField.PAGES, "1-10") + .withField(StandardField.CROSSREF, "jone2021"); + + BibEntry secondEntry = new BibEntry(StandardEntryType.Book) + .withCitationKey("jone2021") + .withField(StandardField.EDITOR, "Jones, John") + .withField(StandardField.PUBLISHER, "Great Publisher") + .withField(StandardField.TITLE, "A book") + .withField(StandardField.YEAR, "2021") + .withField(StandardField.ADDRESS, "Somewhere"); + + String expectedCitation = "[1]B. Smith, “An article,” J. Jones, Ed. Somewhere: Great Publisher, 2021, pp. 1–10.\n"; + BibDatabase bibDatabase = new BibDatabase(List.of(firstEntry, secondEntry)); + String style = CitationStyle.getDefault().getSource(); + + String actualCitation = CitationStyleGenerator.generateCitation(firstEntry, style, CitationStyleOutputFormat.TEXT, bibDatabase); + assertEquals(expectedCitation, actualCitation); + + } } +