From 7df1afb9a6b6e0cfa7e99cf6b571cb9211b11293 Mon Sep 17 00:00:00 2001 From: Oliver Kopp Date: Mon, 21 May 2018 22:28:04 +0200 Subject: [PATCH 1/3] Add NormalizeEnDashesFormatter --- CHANGELOG.md | 1 + .../jabref/logic/formatter/Formatters.java | 2 + .../NormalizeEnDashesFormatter.java | 32 +++++++++++ .../NormalizeEnDashesFormatterTest.java | 54 +++++++++++++++++++ 4 files changed, 89 insertions(+) create mode 100644 src/main/java/org/jabref/logic/formatter/bibtexfields/NormalizeEnDashesFormatter.java create mode 100644 src/test/java/org/jabref/logic/formatter/bibtexfields/NormalizeEnDashesFormatterTest.java diff --git a/CHANGELOG.md b/CHANGELOG.md index 40193767400..a3296f4ce62 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,6 +15,7 @@ We refer to [GitHub issues](https://github.com/JabRef/jabref/issues) by using `# - We added a fetcher based on RFC-IDs. [#3971](https://github.com/JabRef/jabref/issues/3971) - We changed the implementation of the `[shorttitle]` key pattern. It now removes small words like `a`, `an`, `on`, `the` etc. Refer to the help page for a complete overview. [Feature request in the forum](http://discourse.jabref.org/t/jabref-differences-in-shorttitle-between-versions-3-8-1-and-4-not-discounting-the-a-an-of-in-titles/1147) - We added a formatter for adding braces around the `title` field. E.g., `title = {ExamPle}` becomes `title = {{ExamPle}}`, which prevents BibTeX to convert it to lower case. You can use it at the [cleanup entries](http://help.jabref.org/en/CleanupEntries) functionality. +- We added a formatter to ensure correct en dashes in the `title` field. E.g., `title = {Example - illustrative}` becomes `title = {Example -- illustrative}`. - We streamlined the defaults for a [cleanup of entries](http://help.jabref.org/en/CleanupEntries) in the case of BibTeX. ### Fixed diff --git a/src/main/java/org/jabref/logic/formatter/Formatters.java b/src/main/java/org/jabref/logic/formatter/Formatters.java index 2d9f8b615a1..918f5f77fa4 100644 --- a/src/main/java/org/jabref/logic/formatter/Formatters.java +++ b/src/main/java/org/jabref/logic/formatter/Formatters.java @@ -13,6 +13,7 @@ import org.jabref.logic.formatter.bibtexfields.HtmlToUnicodeFormatter; import org.jabref.logic.formatter.bibtexfields.LatexCleanupFormatter; import org.jabref.logic.formatter.bibtexfields.NormalizeDateFormatter; +import org.jabref.logic.formatter.bibtexfields.NormalizeEnDashesFormatter; import org.jabref.logic.formatter.bibtexfields.NormalizeMonthFormatter; import org.jabref.logic.formatter.bibtexfields.NormalizeNamesFormatter; import org.jabref.logic.formatter.bibtexfields.NormalizePagesFormatter; @@ -53,6 +54,7 @@ public class Formatters { new LatexCleanupFormatter(), new MinifyNameListFormatter(), new NormalizeDateFormatter(), + new NormalizeEnDashesFormatter(), new NormalizeMonthFormatter(), new NormalizeNamesFormatter(), new NormalizePagesFormatter(), diff --git a/src/main/java/org/jabref/logic/formatter/bibtexfields/NormalizeEnDashesFormatter.java b/src/main/java/org/jabref/logic/formatter/bibtexfields/NormalizeEnDashesFormatter.java new file mode 100644 index 00000000000..2fc020cd3cc --- /dev/null +++ b/src/main/java/org/jabref/logic/formatter/bibtexfields/NormalizeEnDashesFormatter.java @@ -0,0 +1,32 @@ +package org.jabref.logic.formatter.bibtexfields; + +import org.jabref.logic.formatter.AbstractFormatter; +import org.jabref.logic.l10n.Localization; + +public class NormalizeEnDashesFormatter extends AbstractFormatter { + + @Override + public String getName() { + return Localization.lang("Normalize en dashes"); + } + + @Override + public String getKey() { + return "normalize_en_dashes"; + } + + @Override + public String format(String value) { + return value.replaceAll(" - ", " -- "); + } + + @Override + public String getDescription() { + return Localization.lang("Normalizes the en dashes."); + } + + @Override + public String getExampleInput() { + return "Winery - A Modeling Tool for TOSCA-based Cloud Applications"; + } +} diff --git a/src/test/java/org/jabref/logic/formatter/bibtexfields/NormalizeEnDashesFormatterTest.java b/src/test/java/org/jabref/logic/formatter/bibtexfields/NormalizeEnDashesFormatterTest.java new file mode 100644 index 00000000000..ace49c02398 --- /dev/null +++ b/src/test/java/org/jabref/logic/formatter/bibtexfields/NormalizeEnDashesFormatterTest.java @@ -0,0 +1,54 @@ +package org.jabref.logic.formatter.bibtexfields; + +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +/** + * Tests in addition to the general tests from {@link org.jabref.logic.formatter.FormatterTest} + */ +public class NormalizeEnDashesFormatterTest { + + private NormalizeEnDashesFormatter formatter; + + @BeforeEach + public void setUp() { + formatter = new NormalizeEnDashesFormatter(); + } + + @Test + public void formatExample() { + assertEquals("Winery -- A Modeling Tool for TOSCA-based Cloud Applications", formatter.format(formatter.getExampleInput())); + } + + @Test + public void formatExampleOfChangelog() { + assertEquals("Example -- illustrative", formatter.format("Example - illustrative")); + } + + @Test + public void dashesWithinWordsAreKept() { + assertEquals("Example-illustrative", formatter.format("Example-illustrative")); + } + + @Test + public void dashesPreceededByASpaceAreKept() { + assertEquals("Example -illustrative", formatter.format("Example -illustrative")); + } + + @Test + public void dashesFollowedByASpaceAreKept() { + assertEquals("Example- illustrative", formatter.format("Example- illustrative")); + } + + @Test + public void dashAtTheBeginningIsKept() { + assertEquals("- illustrative", formatter.format("- illustrative")); + } + + @Test + public void dashAtTheEndIsKept() { + assertEquals("Example-", formatter.format("Example-")); + } +} From f4455604b53f6f929077506e0ff021a74e4ef27b Mon Sep 17 00:00:00 2001 From: Oliver Kopp Date: Fri, 25 May 2018 08:25:55 +0200 Subject: [PATCH 2/3] Adapt to new Formatter hiearchy --- .../formatter/bibtexfields/NormalizeEnDashesFormatter.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/org/jabref/logic/formatter/bibtexfields/NormalizeEnDashesFormatter.java b/src/main/java/org/jabref/logic/formatter/bibtexfields/NormalizeEnDashesFormatter.java index 2fc020cd3cc..cb50cc6a10d 100644 --- a/src/main/java/org/jabref/logic/formatter/bibtexfields/NormalizeEnDashesFormatter.java +++ b/src/main/java/org/jabref/logic/formatter/bibtexfields/NormalizeEnDashesFormatter.java @@ -1,9 +1,9 @@ package org.jabref.logic.formatter.bibtexfields; -import org.jabref.logic.formatter.AbstractFormatter; import org.jabref.logic.l10n.Localization; +import org.jabref.model.cleanup.Formatter; -public class NormalizeEnDashesFormatter extends AbstractFormatter { +public class NormalizeEnDashesFormatter extends Formatter { @Override public String getName() { From 33d12099aaaa0c4d94b20b7c2257e3268f73373c Mon Sep 17 00:00:00 2001 From: Oliver Kopp Date: Fri, 25 May 2018 09:13:30 +0200 Subject: [PATCH 3/3] Add missing localization keys --- src/main/resources/l10n/JabRef_en.properties | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/main/resources/l10n/JabRef_en.properties b/src/main/resources/l10n/JabRef_en.properties index e4500956deb..159f4f4a85b 100644 --- a/src/main/resources/l10n/JabRef_en.properties +++ b/src/main/resources/l10n/JabRef_en.properties @@ -1957,6 +1957,7 @@ LaTeX\ to\ Unicode=LaTeX to Unicode Lower\ case=Lower case Minify\ list\ of\ person\ names=Minify list of person names Normalize\ date=Normalize date +Normalize\ en\ dashes=Normalize en dashes Normalize\ month=Normalize month Normalize\ month\ to\ BibTeX\ standard\ abbreviation.=Normalize month to BibTeX standard abbreviation. Normalize\ names\ of\ persons=Normalize names of persons @@ -1964,6 +1965,7 @@ Normalize\ page\ numbers=Normalize page numbers Normalize\ pages\ to\ BibTeX\ standard.=Normalize pages to BibTeX standard. Normalizes\ lists\ of\ persons\ to\ the\ BibTeX\ standard.=Normalizes lists of persons to the BibTeX standard. Normalizes\ the\ date\ to\ ISO\ date\ format.=Normalizes the date to ISO date format. +Normalizes\ the\ en\ dashes.=Normalizes the en dashes. Ordinals\ to\ LaTeX\ superscript=Ordinals to LaTeX superscript Protect\ terms=Protect terms Add\ enclosing\ braces=Add enclosing braces