Skip to content

Commit

Permalink
Merge pull request #974 from tobiasdiez/alwaystrim
Browse files Browse the repository at this point in the history
Always trim fields on save and remove TrimFormatter
  • Loading branch information
simonharrer committed Mar 16, 2016
2 parents 7befb08 + e2668af commit 7965ce6
Show file tree
Hide file tree
Showing 7 changed files with 42 additions and 60 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ to [sourceforge feature requests](https://sourceforge.net/p/jabref/features/) by
- Implemented [#455](https://github.com/JabRef/jabref/issues/455): Add button in preference dialog to reset preferences
- Add ability to run arbitrary formatters as cleanup actions (some old cleanup jobs are replaced by this functionality)
- Implemented [#756](https://github.com/JabRef/jabref/issues/756): Add possibility to reformat all entries on save (under Preferences, File)
- All fields in a bib entry are written without any leading and trailing whitespace
- Comments and preamble are serialized with capitalized first letter, i.e. `@Comment` instead of `@comment` and `@Preamble` instead of `@PREAMBLE`.
- Global sorting options and preferences are removed. Databases can still be sorted on save, but this is configured locally and stored in the file
- OvidImporter now also imports fields: doi, issn, language and keywords
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/net/sf/jabref/exporter/LatexFieldFormatter.java
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,8 @@ public String format(String content, String fieldName)
return formatWithoutResolvingStrings(result, fieldName);
}

// Trim whitespace
result = result.trim();
return formatAndResolveStrings(result, fieldName);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,12 @@ public class BibtexFieldFormatters {
public static final AuthorsFormatter AUTHORS_FORMATTER = new AuthorsFormatter();
public static final LatexFormatter LATEX_FORMATTER = new LatexFormatter();
public static final UnitFormatter UNIT_FORMATTER = new UnitFormatter();
public static final TrimFormatter TRIM_FORMATTER = new TrimFormatter();
public static final RemoveBracesFormatter REMOVE_BRACES_FORMATTER = new RemoveBracesFormatter();
public static final HTMLToLatexFormatter HTML_TO_LATEX = new HTMLToLatexFormatter();
public static final UnicodeToLatexFormatter UNICODE_TO_LATEX = new UnicodeToLatexFormatter();
public static final EraseFormatter ERASE = new EraseFormatter();

public static final List<Formatter> ALL = Arrays.asList(PAGE_NUMBERS, SUPERSCRIPTS, DATE, AUTHORS_FORMATTER,
LATEX_FORMATTER, MONTH_FORMATTER, UNIT_FORMATTER, TRIM_FORMATTER, REMOVE_BRACES_FORMATTER, HTML_TO_LATEX,
UNICODE_TO_LATEX, ERASE);
LATEX_FORMATTER, MONTH_FORMATTER, UNIT_FORMATTER, REMOVE_BRACES_FORMATTER, HTML_TO_LATEX, UNICODE_TO_LATEX,
ERASE);
}

This file was deleted.

37 changes: 37 additions & 0 deletions src/test/java/net/sf/jabref/bibtex/BibEntryWriterTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -366,4 +366,41 @@ public void addFieldWithLongerLength() throws IOException {
// @formatter:on
assertEquals(expected, actual);
}

@Test
public void doNotWriteEmptyFields() throws IOException {
StringWriter stringWriter = new StringWriter();

BibEntry entry = new BibEntry("1234", "article");
entry.setField("author", " ");
entry.setField("note", "some note");

writer.write(entry, stringWriter, BibDatabaseMode.BIBTEX);

String actual = stringWriter.toString();

String expected = Globals.NEWLINE + "@Article{," + Globals.NEWLINE +
" note = {some note}" + Globals.NEWLINE +
"}" + Globals.NEWLINE;

assertEquals(expected, actual);
}

@Test
public void trimFieldContents() throws IOException {
StringWriter stringWriter = new StringWriter();

BibEntry entry = new BibEntry("1234", "article");
entry.setField("note", " some note \t");

writer.write(entry, stringWriter, BibDatabaseMode.BIBTEX);

String actual = stringWriter.toString();

String expected = Globals.NEWLINE + "@Article{," + Globals.NEWLINE +
" note = {some note}" + Globals.NEWLINE +
"}" + Globals.NEWLINE;

assertEquals(expected, actual);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,6 @@ public static Collection<Object[]> instancesToTest() {
new Object[]{new CaseKeeper()},
new Object[]{new PageNumbersFormatter()},
new Object[]{new LowerCaseChanger()},
new Object[]{new TrimFormatter()},
new Object[]{new HTMLToLatexFormatter()},
new Object[]{new SuperscriptFormatter()},
new Object[]{new UnitFormatter()},
Expand Down

This file was deleted.

0 comments on commit 7965ce6

Please sign in to comment.