-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add Markdown export formatter * updated the changelog * fix checkstyle and l10n * fix import order * Update CHANGELOG.md Co-authored-by: Carl Christian Snethlage <[email protected]> * Add full stop (changelog) * remove explicit save order - just for test * checkstyle * temp dir --------- Co-authored-by: Carl Christian Snethlage <[email protected]> Co-authored-by: Subhramit Basu Bhowmick <[email protected]> Co-authored-by: Siedlerchr <[email protected]>
- Loading branch information
1 parent
dc9c49f
commit b453985
Showing
9 changed files
with
201 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 1 addition & 0 deletions
1
src/main/resources/resource/layout/title-markdown/title-md.article.layout
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
* \format[RemoveLatexCommands,HTMLChars]{\title}. \begin{journal}\format[RemoveLatexCommands,HTMLChars]{\journal}\end{journal}\begin{year} \format{\year}\end{year} |
1 change: 1 addition & 0 deletions
1
src/main/resources/resource/layout/title-markdown/title-md.book.layout
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
* \format[RemoveLatexCommands,HTMLChars]{\title}.\begin{publisher} \format[RemoveLatexCommands,HTMLChars]{\publisher}\end{publisher} \format{\year}\end{year} |
1 change: 1 addition & 0 deletions
1
src/main/resources/resource/layout/title-markdown/title-md.incollection.layout
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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} |
1 change: 1 addition & 0 deletions
1
src/main/resources/resource/layout/title-markdown/title-md.inproceedings.layout
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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} |
1 change: 1 addition & 0 deletions
1
src/main/resources/resource/layout/title-markdown/title-md.layout
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
* \format[RemoveLatexCommands,HTMLChars]{\title}.\begin{year} \year\end{year} |
192 changes: 192 additions & 0 deletions
192
src/test/java/org/jabref/logic/exporter/MarkdownTitleExporterTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,192 @@ | ||
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; | ||
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.jabref.model.metadata.SelfContainedSaveOrder; | ||
|
||
import org.junit.jupiter.api.BeforeAll; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.io.TempDir; | ||
import org.mockito.Answers; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.mockito.Mockito.mock; | ||
|
||
class MarkdownTitleExporterTest { | ||
|
||
private static Exporter htmlWebsiteExporter; | ||
private static BibDatabaseContext databaseContext; | ||
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() { | ||
htmlWebsiteExporter = new TemplateExporter( | ||
"Title-Markdown", | ||
"title-md", | ||
"title-md", | ||
"title-markdown", | ||
StandardFileType.MARKDOWN, | ||
mock(LayoutFormatterPreferences.class, Answers.RETURNS_DEEP_STUBS), | ||
SAVE_MOST_RECENT_FIRST_SAVE_ORDER, | ||
BlankLineBehaviour.DELETE_BLANKS); | ||
|
||
databaseContext = new BibDatabaseContext(); | ||
} | ||
|
||
@Test | ||
final void exportForNoEntriesWritesNothing(@TempDir Path tempDir) throws Exception { | ||
Path file = tempDir.resolve("ThisIsARandomlyNamedFile"); | ||
Files.createFile(file); | ||
htmlWebsiteExporter.export(databaseContext, tempDir, Collections.emptyList()); | ||
assertEquals(Collections.emptyList(), Files.readAllLines(file)); | ||
} | ||
|
||
@Test | ||
final void exportsCorrectContentArticle(@TempDir Path tempDir) 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 = tempDir.resolve("RandomFileName"); | ||
Files.createFile(file); | ||
htmlWebsiteExporter.export(databaseContext, file, Collections.singletonList(entry)); | ||
|
||
List<String> expected = List.of( | ||
"* Test Title. Journal of this & that 2020"); | ||
|
||
assertEquals(expected, Files.readAllLines(file)); | ||
} | ||
|
||
@Test | ||
final void exportsCorrectContentInCollection(@TempDir Path tempDir) 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 = tempDir.resolve("RandomFileName"); | ||
Files.createFile(file); | ||
htmlWebsiteExporter.export(databaseContext, file, Collections.singletonList(entry)); | ||
|
||
List<String> expected = List.of( | ||
"* Test Title. Test book, PRESS 2020"); | ||
|
||
assertEquals(expected, Files.readAllLines(file)); | ||
} | ||
|
||
@Test | ||
final void exportsCorrectContentBook(@TempDir Path tempDir) 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 = tempDir.resolve("RandomFileName"); | ||
Files.createFile(file); | ||
htmlWebsiteExporter.export(databaseContext, file, Collections.singletonList(entry)); | ||
|
||
List<String> expected = List.of( | ||
"* Test Title. PRESS 2020"); | ||
|
||
assertEquals(expected, Files.readAllLines(file)); | ||
} | ||
|
||
@Test | ||
final void exportsCorrectContentInProceeedingsPublisher(@TempDir Path tempDir) 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 = tempDir.resolve("RandomFileName"); | ||
Files.createFile(file); | ||
htmlWebsiteExporter.export(databaseContext, file, Collections.singletonList(entry)); | ||
|
||
List<String> expected = List.of( | ||
"* Test Title. ACM CONF'20"); | ||
|
||
assertEquals(expected, Files.readAllLines(file)); | ||
} | ||
|
||
@Test | ||
final void exportsCorrectContentInProceeedingsNoPublisher(@TempDir Path tempDir) 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 = tempDir.resolve("RandomFileName"); | ||
Files.createFile(file); | ||
htmlWebsiteExporter.export(databaseContext, file, Collections.singletonList(entry)); | ||
|
||
List<String> expected = List.of( | ||
"* Test Title. CONF'20"); | ||
|
||
assertEquals(expected, Files.readAllLines(file)); | ||
} | ||
|
||
@Test | ||
final void exportsCorrectContentInProceeedingsNoSeries(@TempDir Path tempDir) 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 = tempDir.resolve("RandomFileName"); | ||
Files.createFile(file); | ||
htmlWebsiteExporter.export(databaseContext, file, Collections.singletonList(entry)); | ||
|
||
List<String> expected = List.of( | ||
"* Test Title. Test Conference 2020"); | ||
|
||
assertEquals(expected, Files.readAllLines(file)); | ||
} | ||
|
||
@Test | ||
final void exportsCorrectContentBracketsInTitle(@TempDir Path tempDir) 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 = tempDir.resolve("RandomFileName"); | ||
Files.createFile(file); | ||
htmlWebsiteExporter.export(databaseContext, file, Collections.singletonList(entry)); | ||
|
||
List<String> expected = List.of( | ||
"* This is JabRef. Journal of this & that 2020"); | ||
|
||
assertEquals(expected, Files.readAllLines(file)); | ||
} | ||
} |