Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add minimal support for biblatex data annotations #11506

Merged
merged 3 commits into from
Jul 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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) {
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);
}
}
Loading