Skip to content

Commit 0e9fcdb

Browse files
committed
Ue cite in typst format only when key contains slash
1 parent d6fe81e commit 0e9fcdb

File tree

2 files changed

+16
-4
lines changed

2 files changed

+16
-4
lines changed

jabsrv/src/main/java/org/jabref/http/server/cayw/format/TypstFormatter.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,13 @@ public String format(CAYWQueryParams queryParams, List<CAYWEntry> caywEntries) {
2424
.toList();
2525

2626
return bibEntries.stream()
27-
.map(entry -> entry.getCitationKey().map("#cite(label(\"%s\"))"::formatted))
27+
.map(entry -> entry.getCitationKey().map(key -> {
28+
if (key.contains("/")) {
29+
return "#cite(label(\"%s\"))".formatted(key);
30+
} else {
31+
return "@%s".formatted(key);
32+
}
33+
}))
2834
.flatMap(Optional::stream)
2935
.collect(Collectors.joining(" "));
3036
}

jabsrv/src/test/java/org/jabref/http/server/cayw/format/CAYWFormattersTest.java

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,6 @@ void biblatex_explicitCommand() {
5050

5151
@Test
5252
void biblatex_missingKey() {
53-
// If you decide to DROP empties, change formatter + this expectation.
5453
BibLatexFormatter formatter = new BibLatexFormatter("autocite");
5554
String actual = formatter.format(queryParams(null), caywEntries("key1", "", "key3"));
5655
assertEquals("\\autocite{key1,key3}", actual); // current implementation
@@ -83,7 +82,14 @@ void pandoc() {
8382
@Test
8483
void typst() {
8584
TypstFormatter formatter = new TypstFormatter();
86-
String actual = formatter.format(queryParams(null), caywEntries("key1", "key2/slash"));
87-
assertEquals("#cite(label(\"key1\")) #cite(label(\"key2/slash\"))", actual);
85+
String actual = formatter.format(queryParams(null), caywEntries("key1", "key2"));
86+
assertEquals("@key1 @key2", actual);
87+
}
88+
89+
@Test
90+
void typst_slashInKey() {
91+
TypstFormatter formatter = new TypstFormatter();
92+
String actual = formatter.format(queryParams(null), caywEntries("key1", "key2/slash", "key3"));
93+
assertEquals("@key1 #cite(label(\"key2/slash\")) @key3", actual);
8894
}
8995
}

0 commit comments

Comments
 (0)