From 67426927e3a4571f08b1917c7a1f67e8c4c9f1b0 Mon Sep 17 00:00:00 2001 From: Linus Dietz Date: Fri, 22 Nov 2024 16:38:13 +0000 Subject: [PATCH 1/9] Add Markdown export formatter --- .../logic/exporter/ExporterFactory.java | 5 + .../title-markdown/title-md.article.layout | 1 + .../title-markdown/title-md.book.layout | 1 + .../title-md.incollection.layout | 1 + .../title-md.inproceedings.layout | 1 + .../layout/title-markdown/title-md.layout | 1 + .../exporter/MarkdownTitleExporterTest.java | 190 ++++++++++++++++++ 7 files changed, 200 insertions(+) create mode 100644 src/main/resources/resource/layout/title-markdown/title-md.article.layout create mode 100644 src/main/resources/resource/layout/title-markdown/title-md.book.layout create mode 100644 src/main/resources/resource/layout/title-markdown/title-md.incollection.layout create mode 100644 src/main/resources/resource/layout/title-markdown/title-md.inproceedings.layout create mode 100644 src/main/resources/resource/layout/title-markdown/title-md.layout create mode 100644 src/test/java/org/jabref/logic/exporter/MarkdownTitleExporterTest.java diff --git a/src/main/java/org/jabref/logic/exporter/ExporterFactory.java b/src/main/java/org/jabref/logic/exporter/ExporterFactory.java index 28a89ebfe7c..acb72399a9e 100644 --- a/src/main/java/org/jabref/logic/exporter/ExporterFactory.java +++ b/src/main/java/org/jabref/logic/exporter/ExporterFactory.java @@ -13,6 +13,9 @@ import org.jabref.logic.util.StandardFileType; import org.jabref.logic.xmp.XmpPreferences; import org.jabref.model.database.BibDatabaseMode; +import org.jabref.model.entry.field.StandardField; +import org.jabref.model.metadata.SaveOrder; +import org.jabref.model.metadata.SaveOrder.SortCriterion; import org.jabref.model.metadata.SelfContainedSaveOrder; public class ExporterFactory { @@ -27,6 +30,7 @@ public static ExporterFactory create(CliPreferences preferences) { List customFormats = preferences.getExportPreferences().getCustomExporters(); LayoutFormatterPreferences layoutPreferences = preferences.getLayoutFormatterPreferences(); SelfContainedSaveOrder saveOrder = SelfContainedSaveOrder.of(preferences.getSelfContainedExportConfiguration().getSaveOrder()); + SelfContainedSaveOrder saveMostRecentFirst = new SelfContainedSaveOrder(SaveOrder.OrderType.SPECIFIED, List.of(new SortCriterion(StandardField.YEAR, true))); XmpPreferences xmpPreferences = preferences.getXmpPreferences(); FieldPreferences fieldPreferences = preferences.getFieldPreferences(); BibDatabaseMode bibDatabaseMode = preferences.getLibraryPreferences().getDefaultBibDatabaseMode(); @@ -43,6 +47,7 @@ public static ExporterFactory create(CliPreferences preferences) { exporters.add(new TemplateExporter(Localization.lang("HTML table"), "tablerefs", "tablerefs", "tablerefs", StandardFileType.HTML, layoutPreferences, saveOrder)); exporters.add(new TemplateExporter(Localization.lang("HTML list"), "listrefs", "listrefs", "listrefs", StandardFileType.HTML, layoutPreferences, saveOrder)); exporters.add(new TemplateExporter(Localization.lang("HTML table (with Abstract & BibTeX)"), "tablerefsabsbib", "tablerefsabsbib", "tablerefsabsbib", StandardFileType.HTML, layoutPreferences, saveOrder)); + exporters.add(new TemplateExporter(Localization.lang("Markdown Titles"), "title-md", "title-md", "title-markdown", StandardFileType.MARKDOWN, layoutPreferences, saveMostRecentFirst)); exporters.add(new TemplateExporter("Harvard RTF", "harvard", "harvard", "harvard", StandardFileType.RTF, layoutPreferences, saveOrder)); exporters.add(new TemplateExporter("ISO 690 RTF", "iso690rtf", "iso690RTF", "iso690rtf", StandardFileType.RTF, layoutPreferences, saveOrder)); exporters.add(new TemplateExporter("ISO 690", "iso690txt", "iso690", "iso690txt", StandardFileType.TXT, layoutPreferences, saveOrder)); diff --git a/src/main/resources/resource/layout/title-markdown/title-md.article.layout b/src/main/resources/resource/layout/title-markdown/title-md.article.layout new file mode 100644 index 00000000000..bd491638613 --- /dev/null +++ b/src/main/resources/resource/layout/title-markdown/title-md.article.layout @@ -0,0 +1 @@ +* \format[RemoveLatexCommands,HTMLChars]{\title}. \begin{journal}\format[RemoveLatexCommands,HTMLChars]{\journal}\end{journal}\begin{year} \format{\year}\end{year} diff --git a/src/main/resources/resource/layout/title-markdown/title-md.book.layout b/src/main/resources/resource/layout/title-markdown/title-md.book.layout new file mode 100644 index 00000000000..c136fa5fa3d --- /dev/null +++ b/src/main/resources/resource/layout/title-markdown/title-md.book.layout @@ -0,0 +1 @@ +* \format[RemoveLatexCommands,HTMLChars]{\title}.\begin{publisher} \format[RemoveLatexCommands,HTMLChars]{\publisher}\end{publisher} \format{\year}\end{year} diff --git a/src/main/resources/resource/layout/title-markdown/title-md.incollection.layout b/src/main/resources/resource/layout/title-markdown/title-md.incollection.layout new file mode 100644 index 00000000000..66a1528b0bc --- /dev/null +++ b/src/main/resources/resource/layout/title-markdown/title-md.incollection.layout @@ -0,0 +1 @@ +* \format[RemoveLatexCommands,HTMLChars]{\title}. \begin{booktitle}\format[RemoveLatexCommands,HTMLChars]{\booktitle}\end{booktitle}\begin{publisher}, \format[RemoveLatexCommands,HTMLChars]{\publisher}\end{publisher} \format{\year} diff --git a/src/main/resources/resource/layout/title-markdown/title-md.inproceedings.layout b/src/main/resources/resource/layout/title-markdown/title-md.inproceedings.layout new file mode 100644 index 00000000000..1d16d1eb94f --- /dev/null +++ b/src/main/resources/resource/layout/title-markdown/title-md.inproceedings.layout @@ -0,0 +1 @@ +* \format[RemoveLatexCommands,HTMLChars]{\title}. \begin{publisher}\format[RemoveLatexCommands,HTMLChars]{\publisher} \end{publisher}\begin{series}\format[RemoveLatexCommands,HTMLChars]{\series}\end{series}\begin{!series}\format[RemoveLatexCommands,HTMLChars]{\booktitle} \format{\year}\end{!series} diff --git a/src/main/resources/resource/layout/title-markdown/title-md.layout b/src/main/resources/resource/layout/title-markdown/title-md.layout new file mode 100644 index 00000000000..4fa6ad3e417 --- /dev/null +++ b/src/main/resources/resource/layout/title-markdown/title-md.layout @@ -0,0 +1 @@ +* \format[RemoveLatexCommands,HTMLChars]{\title}.\begin{year} \year\end{year} diff --git a/src/test/java/org/jabref/logic/exporter/MarkdownTitleExporterTest.java b/src/test/java/org/jabref/logic/exporter/MarkdownTitleExporterTest.java new file mode 100644 index 00000000000..078793bc145 --- /dev/null +++ b/src/test/java/org/jabref/logic/exporter/MarkdownTitleExporterTest.java @@ -0,0 +1,190 @@ +package org.jabref.logic.exporter; + +import org.jabref.logic.layout.LayoutFormatterPreferences; +import org.jabref.logic.util.StandardFileType; +import org.jabref.model.database.BibDatabaseContext; +import org.jabref.model.entry.BibEntry; +import org.jabref.model.entry.field.StandardField; +import org.jabref.model.entry.types.StandardEntryType; +import org.jabref.model.metadata.SaveOrder; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.io.TempDir; +import org.mockito.Answers; + +import java.nio.file.Files; +import java.nio.file.Path; +import java.util.Collections; +import java.util.List; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.mockito.Mockito.mock; + +class MarkdownTitleExporterTest { + + private static Exporter htmlWebsiteExporter; + private static BibDatabaseContext databaseContext; + + @BeforeAll + static void setUp() { + htmlWebsiteExporter = new TemplateExporter( + "Title-Markdown", + "title-md", + "title-md", + "title-markdown", + StandardFileType.MARKDOWN, + mock(LayoutFormatterPreferences.class, Answers.RETURNS_DEEP_STUBS), + SaveOrder.getDefaultSaveOrder(), + BlankLineBehaviour.DELETE_BLANKS); + + databaseContext = new BibDatabaseContext(); + } + + @Test + final void exportForNoEntriesWritesNothing(@TempDir Path tempFile) throws Exception { + Path file = tempFile.resolve("ThisIsARandomlyNamedFile"); + Files.createFile(file); + htmlWebsiteExporter.export(databaseContext, tempFile, Collections.emptyList()); + assertEquals(Collections.emptyList(), Files.readAllLines(file)); + } + + @Test + final void exportsCorrectContentArticle(@TempDir Path tempFile) throws Exception { + BibEntry entry = new BibEntry(StandardEntryType.Article) + .withCitationKey("test") + .withField(StandardField.AUTHOR, "Test Author") + .withField(StandardField.TITLE, "Test Title") + .withField(StandardField.JOURNAL, "Journal of this \\& that") + .withField(StandardField.PUBLISHER, "THE PRESS") + .withField(StandardField.YEAR, "2020"); + + Path file = tempFile.resolve("RandomFileName"); + Files.createFile(file); + htmlWebsiteExporter.export(databaseContext, file, Collections.singletonList(entry)); + + List expected = List.of( + "* Test Title. Journal of this & that 2020"); + + assertEquals(expected, Files.readAllLines(file)); + } + + + @Test + final void exportsCorrectContentInCollection(@TempDir Path tempFile) throws Exception { + BibEntry entry = new BibEntry(StandardEntryType.InCollection) + .withCitationKey("test") + .withField(StandardField.AUTHOR, "Test Author") + .withField(StandardField.TITLE, "Test Title") + .withField(StandardField.BOOKTITLE, "Test book") + .withField(StandardField.PUBLISHER, "PRESS") + .withField(StandardField.YEAR, "2020"); + + Path file = tempFile.resolve("RandomFileName"); + Files.createFile(file); + htmlWebsiteExporter.export(databaseContext, file, Collections.singletonList(entry)); + + List expected = List.of( + "* Test Title. Test book, PRESS 2020"); + + assertEquals(expected, Files.readAllLines(file)); + } + + @Test + final void exportsCorrectContentBook(@TempDir Path tempFile) throws Exception { + BibEntry entry = new BibEntry(StandardEntryType.Book) + .withCitationKey("test") + .withField(StandardField.AUTHOR, "Test Author") + .withField(StandardField.TITLE, "Test Title") + .withField(StandardField.BOOKTITLE, "Test book") + .withField(StandardField.PUBLISHER, "PRESS") + .withField(StandardField.YEAR, "2020"); + + Path file = tempFile.resolve("RandomFileName"); + Files.createFile(file); + htmlWebsiteExporter.export(databaseContext, file, Collections.singletonList(entry)); + + List expected = List.of( + "* Test Title. PRESS 2020"); + + assertEquals(expected, Files.readAllLines(file)); + } + + @Test + final void exportsCorrectContentInProceeedingsPublisher(@TempDir Path tempFile) throws Exception { + BibEntry entry = new BibEntry(StandardEntryType.InProceedings) + .withCitationKey("test") + .withField(StandardField.AUTHOR, "Test Author") + .withField(StandardField.TITLE, "Test Title") + .withField(StandardField.BOOKTITLE, "Test Conference") + .withField(StandardField.PUBLISHER, "ACM") + .withField(StandardField.SERIES, "CONF'20") + .withField(StandardField.YEAR, "2020"); + + Path file = tempFile.resolve("RandomFileName"); + Files.createFile(file); + htmlWebsiteExporter.export(databaseContext, file, Collections.singletonList(entry)); + + List expected = List.of( + "* Test Title. ACM CONF'20"); + + assertEquals(expected, Files.readAllLines(file)); + } + + @Test + final void exportsCorrectContentInProceeedingsNoPublisher(@TempDir Path tempFile) throws Exception { + BibEntry entry = new BibEntry(StandardEntryType.InProceedings) + .withCitationKey("test") + .withField(StandardField.AUTHOR, "Test Author") + .withField(StandardField.TITLE, "Test Title") + .withField(StandardField.BOOKTITLE, "Test Conference") + .withField(StandardField.SERIES, "CONF'20") + .withField(StandardField.YEAR, "2020"); + + Path file = tempFile.resolve("RandomFileName"); + Files.createFile(file); + htmlWebsiteExporter.export(databaseContext, file, Collections.singletonList(entry)); + + List expected = List.of( + "* Test Title. CONF'20"); + + assertEquals(expected, Files.readAllLines(file)); + } + + @Test + final void exportsCorrectContentInProceeedingsNoSeries(@TempDir Path tempFile) throws Exception { + BibEntry entry = new BibEntry(StandardEntryType.InProceedings) + .withCitationKey("test") + .withField(StandardField.AUTHOR, "Test Author") + .withField(StandardField.TITLE, "Test Title") + .withField(StandardField.BOOKTITLE, "Test Conference") + .withField(StandardField.YEAR, "2020"); + + Path file = tempFile.resolve("RandomFileName"); + Files.createFile(file); + htmlWebsiteExporter.export(databaseContext, file, Collections.singletonList(entry)); + + List expected = List.of( + "* Test Title. Test Conference 2020"); + + assertEquals(expected, Files.readAllLines(file)); + } + + @Test + final void exportsCorrectContentBracketsInTitle(@TempDir Path tempFile) throws Exception { + BibEntry entry = new BibEntry(StandardEntryType.Article) + .withCitationKey("test") + .withField(StandardField.AUTHOR, "Test Author") + .withField(StandardField.TITLE, "This is {JabRef}") + .withField(StandardField.JOURNAL, "Journal of this \\& that") + .withField(StandardField.YEAR, "2020"); + + Path file = tempFile.resolve("RandomFileName"); + Files.createFile(file); + htmlWebsiteExporter.export(databaseContext, file, Collections.singletonList(entry)); + + List expected = List.of( + "* This is JabRef. Journal of this & that 2020"); + + assertEquals(expected, Files.readAllLines(file)); + } +} From 044f6c4d5f9a0e910fcbf8f2ef546512374de20f Mon Sep 17 00:00:00 2001 From: Linus Dietz Date: Fri, 22 Nov 2024 16:48:29 +0000 Subject: [PATCH 2/9] updated the changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index fdf7e65a39e..6ce44bb3fa0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,7 @@ Note that this project **does not** adhere to [Semantic Versioning](https://semv ### Added +- We added a Markdown export functionality [#12220](https://github.com/JabRef/jabref/pull/12220) - We added a "view as BibTeX" option before importing an entry from the citation relation tab. [#11826](https://github.com/JabRef/jabref/issues/11826) - We added support finding LaTeX-encoded special characters based on plain Unicode and vice versa. [#11542](https://github.com/JabRef/jabref/pull/11542) - When a search hits a file, the file icon of that entry is changed accordingly. [#11542](https://github.com/JabRef/jabref/pull/11542) From a43f8d8bec5cb22a6d86fb341b16b31819da1dd9 Mon Sep 17 00:00:00 2001 From: Linus Dietz Date: Fri, 22 Nov 2024 17:01:43 +0000 Subject: [PATCH 3/9] fix checkstyle and l10n --- src/main/java/org/jabref/logic/exporter/ExporterFactory.java | 2 +- src/main/resources/l10n/JabRef_en.properties | 2 ++ .../org/jabref/logic/exporter/MarkdownTitleExporterTest.java | 2 +- 3 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/main/java/org/jabref/logic/exporter/ExporterFactory.java b/src/main/java/org/jabref/logic/exporter/ExporterFactory.java index acb72399a9e..99ec6de8789 100644 --- a/src/main/java/org/jabref/logic/exporter/ExporterFactory.java +++ b/src/main/java/org/jabref/logic/exporter/ExporterFactory.java @@ -47,7 +47,7 @@ public static ExporterFactory create(CliPreferences preferences) { exporters.add(new TemplateExporter(Localization.lang("HTML table"), "tablerefs", "tablerefs", "tablerefs", StandardFileType.HTML, layoutPreferences, saveOrder)); exporters.add(new TemplateExporter(Localization.lang("HTML list"), "listrefs", "listrefs", "listrefs", StandardFileType.HTML, layoutPreferences, saveOrder)); exporters.add(new TemplateExporter(Localization.lang("HTML table (with Abstract & BibTeX)"), "tablerefsabsbib", "tablerefsabsbib", "tablerefsabsbib", StandardFileType.HTML, layoutPreferences, saveOrder)); - exporters.add(new TemplateExporter(Localization.lang("Markdown Titles"), "title-md", "title-md", "title-markdown", StandardFileType.MARKDOWN, layoutPreferences, saveMostRecentFirst)); + exporters.add(new TemplateExporter(Localization.lang("Markdown titles"), "title-md", "title-md", "title-markdown", StandardFileType.MARKDOWN, layoutPreferences, saveMostRecentFirst)); exporters.add(new TemplateExporter("Harvard RTF", "harvard", "harvard", "harvard", StandardFileType.RTF, layoutPreferences, saveOrder)); exporters.add(new TemplateExporter("ISO 690 RTF", "iso690rtf", "iso690RTF", "iso690rtf", StandardFileType.RTF, layoutPreferences, saveOrder)); exporters.add(new TemplateExporter("ISO 690", "iso690txt", "iso690", "iso690txt", StandardFileType.TXT, layoutPreferences, saveOrder)); diff --git a/src/main/resources/l10n/JabRef_en.properties b/src/main/resources/l10n/JabRef_en.properties index 2a4ab3bef81..9dcc3d855d4 100644 --- a/src/main/resources/l10n/JabRef_en.properties +++ b/src/main/resources/l10n/JabRef_en.properties @@ -466,6 +466,8 @@ The\ marked\ area\ does\ not\ contain\ any\ legible\ text!=The marked area does HTML\ table=HTML table HTML\ table\ (with\ Abstract\ &\ BibTeX)=HTML table (with Abstract & BibTeX) +Markdown\ titles=Markdown titles + Icon=Icon Ignore=Ignore diff --git a/src/test/java/org/jabref/logic/exporter/MarkdownTitleExporterTest.java b/src/test/java/org/jabref/logic/exporter/MarkdownTitleExporterTest.java index 078793bc145..4d3c8afa180 100644 --- a/src/test/java/org/jabref/logic/exporter/MarkdownTitleExporterTest.java +++ b/src/test/java/org/jabref/logic/exporter/MarkdownTitleExporterTest.java @@ -7,6 +7,7 @@ import org.jabref.model.entry.field.StandardField; import org.jabref.model.entry.types.StandardEntryType; import org.jabref.model.metadata.SaveOrder; + import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.io.TempDir; @@ -68,7 +69,6 @@ final void exportsCorrectContentArticle(@TempDir Path tempFile) throws Exception assertEquals(expected, Files.readAllLines(file)); } - @Test final void exportsCorrectContentInCollection(@TempDir Path tempFile) throws Exception { BibEntry entry = new BibEntry(StandardEntryType.InCollection) From 41feb4e73d59f04c785c68a3ae61e3325d4ea7ca Mon Sep 17 00:00:00 2001 From: Linus Dietz Date: Fri, 22 Nov 2024 17:13:52 +0000 Subject: [PATCH 4/9] fix import order --- .../logic/exporter/MarkdownTitleExporterTest.java | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/test/java/org/jabref/logic/exporter/MarkdownTitleExporterTest.java b/src/test/java/org/jabref/logic/exporter/MarkdownTitleExporterTest.java index 4d3c8afa180..77260029da9 100644 --- a/src/test/java/org/jabref/logic/exporter/MarkdownTitleExporterTest.java +++ b/src/test/java/org/jabref/logic/exporter/MarkdownTitleExporterTest.java @@ -1,5 +1,10 @@ package org.jabref.logic.exporter; +import java.nio.file.Files; +import java.nio.file.Path; +import java.util.Collections; +import java.util.List; + import org.jabref.logic.layout.LayoutFormatterPreferences; import org.jabref.logic.util.StandardFileType; import org.jabref.model.database.BibDatabaseContext; @@ -13,11 +18,6 @@ import org.junit.jupiter.api.io.TempDir; import org.mockito.Answers; -import java.nio.file.Files; -import java.nio.file.Path; -import java.util.Collections; -import java.util.List; - import static org.junit.jupiter.api.Assertions.assertEquals; import static org.mockito.Mockito.mock; From 103888ac2a266afa3c4134581b2b6ed20ccff32f Mon Sep 17 00:00:00 2001 From: Linus Dietz Date: Fri, 22 Nov 2024 17:24:50 +0000 Subject: [PATCH 5/9] Update CHANGELOG.md Co-authored-by: Carl Christian Snethlage <50491877+calixtus@users.noreply.github.com> --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6ce44bb3fa0..78b0aed79e4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,7 +11,7 @@ Note that this project **does not** adhere to [Semantic Versioning](https://semv ### Added -- We added a Markdown export functionality [#12220](https://github.com/JabRef/jabref/pull/12220) +- We added a Markdown export layout [#12220](https://github.com/JabRef/jabref/pull/12220) - We added a "view as BibTeX" option before importing an entry from the citation relation tab. [#11826](https://github.com/JabRef/jabref/issues/11826) - We added support finding LaTeX-encoded special characters based on plain Unicode and vice versa. [#11542](https://github.com/JabRef/jabref/pull/11542) - When a search hits a file, the file icon of that entry is changed accordingly. [#11542](https://github.com/JabRef/jabref/pull/11542) From 63a5ca10fab9caa2a2c80fd86278cbe2e25167b9 Mon Sep 17 00:00:00 2001 From: Subhramit Basu Bhowmick Date: Mon, 25 Nov 2024 20:34:58 +0530 Subject: [PATCH 6/9] Add full stop (changelog) --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 78b0aed79e4..b89d1faa322 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,7 +11,7 @@ Note that this project **does not** adhere to [Semantic Versioning](https://semv ### Added -- We added a Markdown export layout [#12220](https://github.com/JabRef/jabref/pull/12220) +- We added a Markdown export layout. [#12220](https://github.com/JabRef/jabref/pull/12220) - We added a "view as BibTeX" option before importing an entry from the citation relation tab. [#11826](https://github.com/JabRef/jabref/issues/11826) - We added support finding LaTeX-encoded special characters based on plain Unicode and vice versa. [#11542](https://github.com/JabRef/jabref/pull/11542) - When a search hits a file, the file icon of that entry is changed accordingly. [#11542](https://github.com/JabRef/jabref/pull/11542) From 5cd4361ff7f7a6ee7d359ae45635a9037019bb5c Mon Sep 17 00:00:00 2001 From: Siedlerchr Date: Mon, 25 Nov 2024 21:46:46 +0100 Subject: [PATCH 7/9] remove explicit save order - just for test --- src/main/java/org/jabref/logic/exporter/ExporterFactory.java | 3 +-- .../org/jabref/logic/exporter/MarkdownTitleExporterTest.java | 4 +++- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/main/java/org/jabref/logic/exporter/ExporterFactory.java b/src/main/java/org/jabref/logic/exporter/ExporterFactory.java index 99ec6de8789..ba0328c662a 100644 --- a/src/main/java/org/jabref/logic/exporter/ExporterFactory.java +++ b/src/main/java/org/jabref/logic/exporter/ExporterFactory.java @@ -30,7 +30,6 @@ public static ExporterFactory create(CliPreferences preferences) { List customFormats = preferences.getExportPreferences().getCustomExporters(); LayoutFormatterPreferences layoutPreferences = preferences.getLayoutFormatterPreferences(); SelfContainedSaveOrder saveOrder = SelfContainedSaveOrder.of(preferences.getSelfContainedExportConfiguration().getSaveOrder()); - SelfContainedSaveOrder saveMostRecentFirst = new SelfContainedSaveOrder(SaveOrder.OrderType.SPECIFIED, List.of(new SortCriterion(StandardField.YEAR, true))); XmpPreferences xmpPreferences = preferences.getXmpPreferences(); FieldPreferences fieldPreferences = preferences.getFieldPreferences(); BibDatabaseMode bibDatabaseMode = preferences.getLibraryPreferences().getDefaultBibDatabaseMode(); @@ -47,7 +46,7 @@ public static ExporterFactory create(CliPreferences preferences) { exporters.add(new TemplateExporter(Localization.lang("HTML table"), "tablerefs", "tablerefs", "tablerefs", StandardFileType.HTML, layoutPreferences, saveOrder)); exporters.add(new TemplateExporter(Localization.lang("HTML list"), "listrefs", "listrefs", "listrefs", StandardFileType.HTML, layoutPreferences, saveOrder)); exporters.add(new TemplateExporter(Localization.lang("HTML table (with Abstract & BibTeX)"), "tablerefsabsbib", "tablerefsabsbib", "tablerefsabsbib", StandardFileType.HTML, layoutPreferences, saveOrder)); - exporters.add(new TemplateExporter(Localization.lang("Markdown titles"), "title-md", "title-md", "title-markdown", StandardFileType.MARKDOWN, layoutPreferences, saveMostRecentFirst)); + exporters.add(new TemplateExporter(Localization.lang("Markdown titles"), "title-md", "title-md", "title-markdown", StandardFileType.MARKDOWN, layoutPreferences, saveOrder)); exporters.add(new TemplateExporter("Harvard RTF", "harvard", "harvard", "harvard", StandardFileType.RTF, layoutPreferences, saveOrder)); exporters.add(new TemplateExporter("ISO 690 RTF", "iso690rtf", "iso690RTF", "iso690rtf", StandardFileType.RTF, layoutPreferences, saveOrder)); exporters.add(new TemplateExporter("ISO 690", "iso690txt", "iso690", "iso690txt", StandardFileType.TXT, layoutPreferences, saveOrder)); diff --git a/src/test/java/org/jabref/logic/exporter/MarkdownTitleExporterTest.java b/src/test/java/org/jabref/logic/exporter/MarkdownTitleExporterTest.java index 77260029da9..5e551d9bcc9 100644 --- a/src/test/java/org/jabref/logic/exporter/MarkdownTitleExporterTest.java +++ b/src/test/java/org/jabref/logic/exporter/MarkdownTitleExporterTest.java @@ -12,6 +12,7 @@ import org.jabref.model.entry.field.StandardField; import org.jabref.model.entry.types.StandardEntryType; import org.jabref.model.metadata.SaveOrder; +import org.jabref.model.metadata.SelfContainedSaveOrder; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Test; @@ -25,6 +26,7 @@ class MarkdownTitleExporterTest { private static Exporter htmlWebsiteExporter; private static BibDatabaseContext databaseContext; + private static final SelfContainedSaveOrder saveMostRecentFirstSaveOrder = new SelfContainedSaveOrder(SaveOrder.OrderType.SPECIFIED, List.of(new SaveOrder.SortCriterion(StandardField.YEAR, true))); @BeforeAll static void setUp() { @@ -35,7 +37,7 @@ static void setUp() { "title-markdown", StandardFileType.MARKDOWN, mock(LayoutFormatterPreferences.class, Answers.RETURNS_DEEP_STUBS), - SaveOrder.getDefaultSaveOrder(), + saveMostRecentFirstSaveOrder, BlankLineBehaviour.DELETE_BLANKS); databaseContext = new BibDatabaseContext(); From f56108c62ccbf7cec35685a261394026fae9e9ac Mon Sep 17 00:00:00 2001 From: Siedlerchr Date: Mon, 25 Nov 2024 21:50:58 +0100 Subject: [PATCH 8/9] checkstyle --- src/main/java/org/jabref/logic/exporter/ExporterFactory.java | 3 --- .../org/jabref/logic/exporter/MarkdownTitleExporterTest.java | 4 ++-- 2 files changed, 2 insertions(+), 5 deletions(-) diff --git a/src/main/java/org/jabref/logic/exporter/ExporterFactory.java b/src/main/java/org/jabref/logic/exporter/ExporterFactory.java index ba0328c662a..bcd6de20bef 100644 --- a/src/main/java/org/jabref/logic/exporter/ExporterFactory.java +++ b/src/main/java/org/jabref/logic/exporter/ExporterFactory.java @@ -13,9 +13,6 @@ import org.jabref.logic.util.StandardFileType; import org.jabref.logic.xmp.XmpPreferences; import org.jabref.model.database.BibDatabaseMode; -import org.jabref.model.entry.field.StandardField; -import org.jabref.model.metadata.SaveOrder; -import org.jabref.model.metadata.SaveOrder.SortCriterion; import org.jabref.model.metadata.SelfContainedSaveOrder; public class ExporterFactory { diff --git a/src/test/java/org/jabref/logic/exporter/MarkdownTitleExporterTest.java b/src/test/java/org/jabref/logic/exporter/MarkdownTitleExporterTest.java index 5e551d9bcc9..81d6e028d6f 100644 --- a/src/test/java/org/jabref/logic/exporter/MarkdownTitleExporterTest.java +++ b/src/test/java/org/jabref/logic/exporter/MarkdownTitleExporterTest.java @@ -26,7 +26,7 @@ class MarkdownTitleExporterTest { private static Exporter htmlWebsiteExporter; private static BibDatabaseContext databaseContext; - private static final SelfContainedSaveOrder saveMostRecentFirstSaveOrder = new SelfContainedSaveOrder(SaveOrder.OrderType.SPECIFIED, List.of(new SaveOrder.SortCriterion(StandardField.YEAR, true))); + private static final SelfContainedSaveOrder SAVE_MOST_RECENT_FIRST_SAVE_ORDER = new SelfContainedSaveOrder(SaveOrder.OrderType.SPECIFIED, List.of(new SaveOrder.SortCriterion(StandardField.YEAR, true))); @BeforeAll static void setUp() { @@ -37,7 +37,7 @@ static void setUp() { "title-markdown", StandardFileType.MARKDOWN, mock(LayoutFormatterPreferences.class, Answers.RETURNS_DEEP_STUBS), - saveMostRecentFirstSaveOrder, + SAVE_MOST_RECENT_FIRST_SAVE_ORDER, BlankLineBehaviour.DELETE_BLANKS); databaseContext = new BibDatabaseContext(); From 63118b1017dcf1fb402b5c5aaea6abf523b51670 Mon Sep 17 00:00:00 2001 From: Siedlerchr Date: Mon, 25 Nov 2024 21:53:09 +0100 Subject: [PATCH 9/9] temp dir --- .../exporter/MarkdownTitleExporterTest.java | 34 +++++++++---------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/src/test/java/org/jabref/logic/exporter/MarkdownTitleExporterTest.java b/src/test/java/org/jabref/logic/exporter/MarkdownTitleExporterTest.java index 81d6e028d6f..19ae753ef15 100644 --- a/src/test/java/org/jabref/logic/exporter/MarkdownTitleExporterTest.java +++ b/src/test/java/org/jabref/logic/exporter/MarkdownTitleExporterTest.java @@ -44,15 +44,15 @@ static void setUp() { } @Test - final void exportForNoEntriesWritesNothing(@TempDir Path tempFile) throws Exception { - Path file = tempFile.resolve("ThisIsARandomlyNamedFile"); + final void exportForNoEntriesWritesNothing(@TempDir Path tempDir) throws Exception { + Path file = tempDir.resolve("ThisIsARandomlyNamedFile"); Files.createFile(file); - htmlWebsiteExporter.export(databaseContext, tempFile, Collections.emptyList()); + htmlWebsiteExporter.export(databaseContext, tempDir, Collections.emptyList()); assertEquals(Collections.emptyList(), Files.readAllLines(file)); } @Test - final void exportsCorrectContentArticle(@TempDir Path tempFile) throws Exception { + final void exportsCorrectContentArticle(@TempDir Path tempDir) throws Exception { BibEntry entry = new BibEntry(StandardEntryType.Article) .withCitationKey("test") .withField(StandardField.AUTHOR, "Test Author") @@ -61,7 +61,7 @@ final void exportsCorrectContentArticle(@TempDir Path tempFile) throws Exception .withField(StandardField.PUBLISHER, "THE PRESS") .withField(StandardField.YEAR, "2020"); - Path file = tempFile.resolve("RandomFileName"); + Path file = tempDir.resolve("RandomFileName"); Files.createFile(file); htmlWebsiteExporter.export(databaseContext, file, Collections.singletonList(entry)); @@ -72,7 +72,7 @@ final void exportsCorrectContentArticle(@TempDir Path tempFile) throws Exception } @Test - final void exportsCorrectContentInCollection(@TempDir Path tempFile) throws Exception { + final void exportsCorrectContentInCollection(@TempDir Path tempDir) throws Exception { BibEntry entry = new BibEntry(StandardEntryType.InCollection) .withCitationKey("test") .withField(StandardField.AUTHOR, "Test Author") @@ -81,7 +81,7 @@ final void exportsCorrectContentInCollection(@TempDir Path tempFile) throws Exce .withField(StandardField.PUBLISHER, "PRESS") .withField(StandardField.YEAR, "2020"); - Path file = tempFile.resolve("RandomFileName"); + Path file = tempDir.resolve("RandomFileName"); Files.createFile(file); htmlWebsiteExporter.export(databaseContext, file, Collections.singletonList(entry)); @@ -92,7 +92,7 @@ final void exportsCorrectContentInCollection(@TempDir Path tempFile) throws Exce } @Test - final void exportsCorrectContentBook(@TempDir Path tempFile) throws Exception { + final void exportsCorrectContentBook(@TempDir Path tempDir) throws Exception { BibEntry entry = new BibEntry(StandardEntryType.Book) .withCitationKey("test") .withField(StandardField.AUTHOR, "Test Author") @@ -101,7 +101,7 @@ final void exportsCorrectContentBook(@TempDir Path tempFile) throws Exception { .withField(StandardField.PUBLISHER, "PRESS") .withField(StandardField.YEAR, "2020"); - Path file = tempFile.resolve("RandomFileName"); + Path file = tempDir.resolve("RandomFileName"); Files.createFile(file); htmlWebsiteExporter.export(databaseContext, file, Collections.singletonList(entry)); @@ -112,7 +112,7 @@ final void exportsCorrectContentBook(@TempDir Path tempFile) throws Exception { } @Test - final void exportsCorrectContentInProceeedingsPublisher(@TempDir Path tempFile) throws Exception { + final void exportsCorrectContentInProceeedingsPublisher(@TempDir Path tempDir) throws Exception { BibEntry entry = new BibEntry(StandardEntryType.InProceedings) .withCitationKey("test") .withField(StandardField.AUTHOR, "Test Author") @@ -122,7 +122,7 @@ final void exportsCorrectContentInProceeedingsPublisher(@TempDir Path tempFile) .withField(StandardField.SERIES, "CONF'20") .withField(StandardField.YEAR, "2020"); - Path file = tempFile.resolve("RandomFileName"); + Path file = tempDir.resolve("RandomFileName"); Files.createFile(file); htmlWebsiteExporter.export(databaseContext, file, Collections.singletonList(entry)); @@ -133,7 +133,7 @@ final void exportsCorrectContentInProceeedingsPublisher(@TempDir Path tempFile) } @Test - final void exportsCorrectContentInProceeedingsNoPublisher(@TempDir Path tempFile) throws Exception { + final void exportsCorrectContentInProceeedingsNoPublisher(@TempDir Path tempDir) throws Exception { BibEntry entry = new BibEntry(StandardEntryType.InProceedings) .withCitationKey("test") .withField(StandardField.AUTHOR, "Test Author") @@ -142,7 +142,7 @@ final void exportsCorrectContentInProceeedingsNoPublisher(@TempDir Path tempFile .withField(StandardField.SERIES, "CONF'20") .withField(StandardField.YEAR, "2020"); - Path file = tempFile.resolve("RandomFileName"); + Path file = tempDir.resolve("RandomFileName"); Files.createFile(file); htmlWebsiteExporter.export(databaseContext, file, Collections.singletonList(entry)); @@ -153,7 +153,7 @@ final void exportsCorrectContentInProceeedingsNoPublisher(@TempDir Path tempFile } @Test - final void exportsCorrectContentInProceeedingsNoSeries(@TempDir Path tempFile) throws Exception { + final void exportsCorrectContentInProceeedingsNoSeries(@TempDir Path tempDir) throws Exception { BibEntry entry = new BibEntry(StandardEntryType.InProceedings) .withCitationKey("test") .withField(StandardField.AUTHOR, "Test Author") @@ -161,7 +161,7 @@ final void exportsCorrectContentInProceeedingsNoSeries(@TempDir Path tempFile) t .withField(StandardField.BOOKTITLE, "Test Conference") .withField(StandardField.YEAR, "2020"); - Path file = tempFile.resolve("RandomFileName"); + Path file = tempDir.resolve("RandomFileName"); Files.createFile(file); htmlWebsiteExporter.export(databaseContext, file, Collections.singletonList(entry)); @@ -172,7 +172,7 @@ final void exportsCorrectContentInProceeedingsNoSeries(@TempDir Path tempFile) t } @Test - final void exportsCorrectContentBracketsInTitle(@TempDir Path tempFile) throws Exception { + final void exportsCorrectContentBracketsInTitle(@TempDir Path tempDir) throws Exception { BibEntry entry = new BibEntry(StandardEntryType.Article) .withCitationKey("test") .withField(StandardField.AUTHOR, "Test Author") @@ -180,7 +180,7 @@ final void exportsCorrectContentBracketsInTitle(@TempDir Path tempFile) throws E .withField(StandardField.JOURNAL, "Journal of this \\& that") .withField(StandardField.YEAR, "2020"); - Path file = tempFile.resolve("RandomFileName"); + Path file = tempDir.resolve("RandomFileName"); Files.createFile(file); htmlWebsiteExporter.export(databaseContext, file, Collections.singletonList(entry));