Skip to content

Commit

Permalink
Add minimal support for biblatex data annotations (#11506)
Browse files Browse the repository at this point in the history
* Add minimal support for biblatex data annotations

Fixes #11505

* update changelog
  • Loading branch information
odneill authored Jul 16, 2024
1 parent a5e1bd6 commit 7de6d59
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ Note that this project **does not** adhere to [Semantic Versioning](https://semv
### Added

- We added support for selecting and using CSL Styles in JabRef's OpenOffice/LibreOffice integration for inserting bibliographic and in-text citations into a document. [#2146](https://github.com/JabRef/jabref/issues/2146), [#8893](https://github.com/JabRef/jabref/issues/8893)
- Added minimal support for [biblatex data annotation](https://mirrors.ctan.org/macros/latex/contrib/biblatex/doc/biblatex.pdf#subsection.3.7) fields in .layout files. [#11505](https://github.com/JabRef/jabref/issues/11505)

### Changed

Expand Down
17 changes: 15 additions & 2 deletions src/main/java/org/jabref/logic/layout/LayoutHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public LayoutHelper(Reader in,
List<Path> fileDirForDatabase,
LayoutFormatterPreferences preferences,
JournalAbbreviationRepository abbreviationRepository) {
this.in = new PushbackReader(Objects.requireNonNull(in));
this.in = new PushbackReader(Objects.requireNonNull(in), 2);
this.preferences = Objects.requireNonNull(preferences);
this.abbreviationRepository = abbreviationRepository;
this.fileDirForDatabase = fileDirForDatabase;
Expand Down Expand Up @@ -262,7 +262,7 @@ private void parseField() throws IOException {
endOfFile = true;
}

if (!Character.isLetter((char) c) && (c != '_')) {
if (!validChar(c) && !validAnnotation(c)) {
unread(c);

name = buffer == null ? "" : buffer.toString();
Expand Down Expand Up @@ -345,6 +345,19 @@ private void parseField() throws IOException {
}
}

private boolean validAnnotation(int c) throws IOException {
// Only accept annotations that are followed by a valid character
boolean annotation = ((c == '+') || (c == ':')) && validChar(peek());

return annotation;
}

private boolean validChar(int c) throws IOException {
boolean character = Character.isLetter((char) c) || (c == '_');

return character;
}

private int peek() throws IOException {
int c = read();
unread(c);
Expand Down
13 changes: 13 additions & 0 deletions src/test/java/org/jabref/logic/layout/LayoutTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import org.jabref.model.entry.BibEntry;
import org.jabref.model.entry.LinkedFile;
import org.jabref.model.entry.field.StandardField;
import org.jabref.model.entry.field.UnknownField;
import org.jabref.model.entry.types.StandardEntryType;
import org.jabref.model.entry.types.UnknownEntryType;

Expand Down Expand Up @@ -173,4 +174,16 @@ void customNameFormatter() throws IOException {

assertEquals("JoeDoe and MaryJ", layoutText);
}

@Test
void annotatedField() throws IOException {
UnknownField annotatedField = new UnknownField("author+an");
BibEntry entry = new BibEntry(StandardEntryType.Article)
.withField(annotatedField, "1:corresponding,2:highlight")
.withField(StandardField.AUTHOR, "Joe Doe and Mary Jane");

String layoutText = layout("\\author: \\author \\author+an", entry);

assertEquals("Joe Doe and Mary Jane: Joe Doe and Mary Jane 1:corresponding,2:highlight", layoutText);
}
}

0 comments on commit 7de6d59

Please sign in to comment.