From ffd5d03c451590e9426580bd7bd1ddd21e5ad4b5 Mon Sep 17 00:00:00 2001 From: Johannes Manner Date: Tue, 16 Oct 2018 16:51:12 +0200 Subject: [PATCH 1/6] Change latex command handling only for XML Chars --- .../java/org/jabref/logic/layout/format/XMLChars.java | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/main/java/org/jabref/logic/layout/format/XMLChars.java b/src/main/java/org/jabref/logic/layout/format/XMLChars.java index 59c98142969..4a3ada367a7 100644 --- a/src/main/java/org/jabref/logic/layout/format/XMLChars.java +++ b/src/main/java/org/jabref/logic/layout/format/XMLChars.java @@ -30,7 +30,8 @@ public String format(String fieldText) { return fieldText; } - String formattedFieldText = firstFormat(fieldText); + String latexCommandFree = removeLatexCommands(fieldText); + String formattedFieldText = firstFormat(latexCommandFree); for (Map.Entry entry : XML_CHARS.entrySet()) { String s = entry.getKey(); @@ -42,6 +43,11 @@ public String format(String fieldText) { return restFormat(formattedFieldText); } + private String removeLatexCommands(String fieldText) { + LatexToUnicodeFormatter latexToUnicode = new LatexToUnicodeFormatter(); + return latexToUnicode.format(fieldText); + } + private static String firstFormat(String s) { return s.replaceAll("&|\\\\&", "&").replace("--", "–"); } From b1e78fabbdd4271b222cc6d7312edc312add3b86 Mon Sep 17 00:00:00 2001 From: Johannes Manner Date: Thu, 18 Oct 2018 10:59:29 +0200 Subject: [PATCH 2/6] Added Test for DocbookExporter --- .../logic/exporter/DocbookExporterTest.java | 85 +++++++++++++++++++ 1 file changed, 85 insertions(+) create mode 100644 src/test/java/org/jabref/logic/exporter/DocbookExporterTest.java diff --git a/src/test/java/org/jabref/logic/exporter/DocbookExporterTest.java b/src/test/java/org/jabref/logic/exporter/DocbookExporterTest.java new file mode 100644 index 00000000000..ce785816783 --- /dev/null +++ b/src/test/java/org/jabref/logic/exporter/DocbookExporterTest.java @@ -0,0 +1,85 @@ +package org.jabref.logic.exporter; + +import java.nio.charset.Charset; +import java.nio.charset.StandardCharsets; +import java.nio.file.Files; +import java.nio.file.Path; +import java.util.Arrays; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import org.jabref.logic.layout.LayoutFormatterPreferences; +import org.jabref.logic.xmp.XmpPreferences; +import org.jabref.model.database.BibDatabaseContext; +import org.jabref.model.entry.BibEntry; + +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.junitpioneer.jupiter.TempDirectory; +import org.mockito.Answers; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.mockito.Mockito.mock; + +@ExtendWith(TempDirectory.class) +public class DocbookExporterTest { + + private Exporter exportFormat; + public BibDatabaseContext databaseContext; + public Charset charset; + + @BeforeEach + public void setUp() { + Map customFormats = new HashMap<>(); + LayoutFormatterPreferences layoutPreferences = mock(LayoutFormatterPreferences.class, Answers.RETURNS_DEEP_STUBS); + SavePreferences savePreferences = mock(SavePreferences.class); + XmpPreferences xmpPreferences = mock(XmpPreferences.class); + ExporterFactory exporterFactory = ExporterFactory.create(customFormats, layoutPreferences, savePreferences, xmpPreferences); + + exportFormat = exporterFactory.getExporterByName("docbook").get(); + + databaseContext = new BibDatabaseContext(); + charset = StandardCharsets.UTF_8; + } + + @AfterEach + public void tearDown() { + exportFormat = null; + } + + @Test + public void testCorruptedTitleBraces(@TempDirectory.TempDir Path testFolder) throws Exception { + Path tmpFile = testFolder.resolve("testBraces"); + + BibEntry entry = new BibEntry(); + entry.setField("title", "Peptidomics of the larval {\\protect{{D}rosophila melanogaster}} central nervous system."); + + List entries = Arrays.asList(entry); + + exportFormat.export(databaseContext, tmpFile, charset, entries); + + List lines = Files.readAllLines(tmpFile); + assertEquals(20, lines.size()); + assertEquals(" Peptidomics of the larval Drosophila melanogaster central nervous system.", lines.get(9)); + } + + @Test + public void testCorruptedTitleUnicode(@TempDirectory.TempDir Path testFolder) throws Exception { + Path tmpFile = testFolder.resolve("testBraces"); + + BibEntry entry = new BibEntry(); + entry.setField("title", "Insect neuropeptide bursicon homodimers induce innate immune and stress genes during molting by activating the {NF}-$\\kappa$B transcription factor Relish."); + + List entries = Arrays.asList(entry); + + exportFormat.export(databaseContext, tmpFile, charset, entries); + + List lines = Files.readAllLines(tmpFile); + assertEquals(20, lines.size()); + assertEquals(" Insect neuropeptide bursicon homodimers induce innate immune and stress genes during molting by activating the NF-κB transcription factor Relish.", lines.get(9)); + } + +} From 1b0d85d4f801b28b6e7c21a0471fe8e836c00da5 Mon Sep 17 00:00:00 2001 From: Johannes Manner Date: Thu, 18 Oct 2018 11:21:41 +0200 Subject: [PATCH 3/6] Hopefully fixed travis error and added changelog entry --- CHANGELOG.md | 1 + .../java/org/jabref/logic/exporter/DocbookExporterTest.java | 3 ++- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 61130cb9435..a6393bd3d01 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,7 @@ We refer to [GitHub issues](https://github.com/JabRef/jabref/issues) by using `# ## [Unreleased] ### Changed +- We changed the latex command removal for docbook exporter. [#3838](https://github.com/JabRef/jabref/issues/3838) - We updated the dialog for setting up general fields. - URL field formatting is updated. All whitespace chars, located at the beginning/ending of the url, are trimmed automatically - We changed the behavior of the field formatting dialog such that the `bibtexkey` is not changed when formatting all fields or all text fields. diff --git a/src/test/java/org/jabref/logic/exporter/DocbookExporterTest.java b/src/test/java/org/jabref/logic/exporter/DocbookExporterTest.java index ce785816783..c1bfddb2947 100644 --- a/src/test/java/org/jabref/logic/exporter/DocbookExporterTest.java +++ b/src/test/java/org/jabref/logic/exporter/DocbookExporterTest.java @@ -27,10 +27,11 @@ @ExtendWith(TempDirectory.class) public class DocbookExporterTest { - private Exporter exportFormat; public BibDatabaseContext databaseContext; public Charset charset; + private Exporter exportFormat; + @BeforeEach public void setUp() { Map customFormats = new HashMap<>(); From f066830e1317500c063cae251dd098ed604a9620 Mon Sep 17 00:00:00 2001 From: Johannes Manner Date: Wed, 27 Mar 2019 09:43:27 +0100 Subject: [PATCH 4/6] Update DocbookExporterTest.java --- .../logic/exporter/DocbookExporterTest.java | 15 +++------------ 1 file changed, 3 insertions(+), 12 deletions(-) diff --git a/src/test/java/org/jabref/logic/exporter/DocbookExporterTest.java b/src/test/java/org/jabref/logic/exporter/DocbookExporterTest.java index c1bfddb2947..b05d31fa3a9 100644 --- a/src/test/java/org/jabref/logic/exporter/DocbookExporterTest.java +++ b/src/test/java/org/jabref/logic/exporter/DocbookExporterTest.java @@ -27,28 +27,19 @@ @ExtendWith(TempDirectory.class) public class DocbookExporterTest { - public BibDatabaseContext databaseContext; - public Charset charset; + public BibDatabaseContext databaseContext = new BibDatabaseContext();; + public Charset charset = StandardCharsets.UTF_8; private Exporter exportFormat; @BeforeEach public void setUp() { - Map customFormats = new HashMap<>(); LayoutFormatterPreferences layoutPreferences = mock(LayoutFormatterPreferences.class, Answers.RETURNS_DEEP_STUBS); SavePreferences savePreferences = mock(SavePreferences.class); XmpPreferences xmpPreferences = mock(XmpPreferences.class); - ExporterFactory exporterFactory = ExporterFactory.create(customFormats, layoutPreferences, savePreferences, xmpPreferences); + ExporterFactory exporterFactory = ExporterFactory.create(new HashMap<>(), layoutPreferences, savePreferences, xmpPreferences); exportFormat = exporterFactory.getExporterByName("docbook").get(); - - databaseContext = new BibDatabaseContext(); - charset = StandardCharsets.UTF_8; - } - - @AfterEach - public void tearDown() { - exportFormat = null; } @Test From 18b167b2ea7f59c4633f29c6c55e3a421d011fc8 Mon Sep 17 00:00:00 2001 From: Johannes Manner Date: Wed, 27 Mar 2019 10:26:22 +0100 Subject: [PATCH 5/6] Resolve jupiter problem --- .../org/jabref/logic/exporter/DocbookExporterTest.java | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/src/test/java/org/jabref/logic/exporter/DocbookExporterTest.java b/src/test/java/org/jabref/logic/exporter/DocbookExporterTest.java index b05d31fa3a9..fd16d1ad4cd 100644 --- a/src/test/java/org/jabref/logic/exporter/DocbookExporterTest.java +++ b/src/test/java/org/jabref/logic/exporter/DocbookExporterTest.java @@ -7,24 +7,20 @@ import java.util.Arrays; import java.util.HashMap; import java.util.List; -import java.util.Map; import org.jabref.logic.layout.LayoutFormatterPreferences; import org.jabref.logic.xmp.XmpPreferences; import org.jabref.model.database.BibDatabaseContext; import org.jabref.model.entry.BibEntry; -import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.extension.ExtendWith; -import org.junitpioneer.jupiter.TempDirectory; +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; -@ExtendWith(TempDirectory.class) public class DocbookExporterTest { public BibDatabaseContext databaseContext = new BibDatabaseContext();; @@ -43,7 +39,7 @@ public void setUp() { } @Test - public void testCorruptedTitleBraces(@TempDirectory.TempDir Path testFolder) throws Exception { + public void testCorruptedTitleBraces(@TempDir Path testFolder) throws Exception { Path tmpFile = testFolder.resolve("testBraces"); BibEntry entry = new BibEntry(); @@ -59,7 +55,7 @@ public void testCorruptedTitleBraces(@TempDirectory.TempDir Path testFolder) thr } @Test - public void testCorruptedTitleUnicode(@TempDirectory.TempDir Path testFolder) throws Exception { + public void testCorruptedTitleUnicode(@TempDir Path testFolder) throws Exception { Path tmpFile = testFolder.resolve("testBraces"); BibEntry entry = new BibEntry(); From ea120af4138125e947b77d3c9830f9efbaaf081d Mon Sep 17 00:00:00 2001 From: Johannes Manner Date: Wed, 27 Mar 2019 10:38:56 +0100 Subject: [PATCH 6/6] Update DocbookExporterTest.java --- .../org/jabref/logic/exporter/DocbookExporterTest.java | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/test/java/org/jabref/logic/exporter/DocbookExporterTest.java b/src/test/java/org/jabref/logic/exporter/DocbookExporterTest.java index fd16d1ad4cd..a10a91ec6ff 100644 --- a/src/test/java/org/jabref/logic/exporter/DocbookExporterTest.java +++ b/src/test/java/org/jabref/logic/exporter/DocbookExporterTest.java @@ -4,8 +4,8 @@ import java.nio.charset.StandardCharsets; import java.nio.file.Files; import java.nio.file.Path; +import java.util.ArrayList; import java.util.Arrays; -import java.util.HashMap; import java.util.List; import org.jabref.logic.layout.LayoutFormatterPreferences; @@ -30,12 +30,13 @@ public class DocbookExporterTest { @BeforeEach public void setUp() { + List customFormats = new ArrayList<>(); LayoutFormatterPreferences layoutPreferences = mock(LayoutFormatterPreferences.class, Answers.RETURNS_DEEP_STUBS); SavePreferences savePreferences = mock(SavePreferences.class); XmpPreferences xmpPreferences = mock(XmpPreferences.class); - ExporterFactory exporterFactory = ExporterFactory.create(new HashMap<>(), layoutPreferences, savePreferences, xmpPreferences); + ExporterFactory exporterFactory = ExporterFactory.create(customFormats, layoutPreferences, savePreferences, xmpPreferences); - exportFormat = exporterFactory.getExporterByName("docbook").get(); + exportFormat = exporterFactory.getExporterByName("docbook4").get(); } @Test