-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Added CiteFormatter and BibLatexFormatter for CAYW feature #13704
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
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package org.jabref.http.server.cayw.format; | ||
|
||
import java.util.List; | ||
import java.util.stream.Collectors; | ||
|
||
import org.jabref.http.server.cayw.CAYWQueryParams; | ||
import org.jabref.http.server.cayw.gui.CAYWEntry; | ||
import org.jabref.model.entry.BibEntry; | ||
|
||
import jakarta.ws.rs.core.MediaType; | ||
import org.jvnet.hk2.annotations.Service; | ||
|
||
@Service | ||
public class CitepFormatter implements CAYWFormatter { | ||
|
||
@Override | ||
public List<String> getFormatNames() { | ||
return List.of("citep", "cite"); | ||
} | ||
|
||
@Override | ||
public MediaType getMediaType() { | ||
return MediaType.TEXT_PLAIN_TYPE; | ||
} | ||
|
||
@Override | ||
public String format(CAYWQueryParams queryParams, List<CAYWEntry> caywEntries) { | ||
List<BibEntry> bibEntries = caywEntries.stream() | ||
.map(CAYWEntry::bibEntry) | ||
.toList(); | ||
String joined = bibEntries.stream() | ||
.map(entry -> entry.getCitationKey().orElse("")) | ||
.collect(Collectors.joining(",")); | ||
return "\\citep{" + joined + "}"; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,6 @@ | ||
package org.jabref.http.server.cayw.format; | ||
|
||
import java.util.List; | ||
import java.util.Optional; | ||
import java.util.stream.Collectors; | ||
|
||
import org.jabref.http.server.cayw.CAYWQueryParams; | ||
|
@@ -15,8 +14,8 @@ | |
public class LatexFormatter implements CAYWFormatter { | ||
|
||
@Override | ||
public String getFormatName() { | ||
return "latex"; | ||
public List<String> getFormatNames() { | ||
return List.of("latex", "tex"); | ||
} | ||
|
||
@Override | ||
|
@@ -25,15 +24,11 @@ public MediaType getMediaType() { | |
} | ||
|
||
@Override | ||
public String format(CAYWQueryParams queryParams, List<CAYWEntry> cawEntries) { | ||
String command = Optional.ofNullable(queryParams.getCommand()) | ||
.filter(cmd -> !cmd.isBlank()) | ||
.orElse("cite"); | ||
|
||
List<BibEntry> bibEntries = cawEntries.stream() | ||
public String format(CAYWQueryParams queryParams, List<CAYWEntry> caywEntries) { | ||
String command = queryParams.getCommand() != null ? queryParams.getCommand() : "autocite"; | ||
List<BibEntry> bibEntries = caywEntries.stream() | ||
.map(CAYWEntry::bibEntry) | ||
.toList(); | ||
|
||
return "\\%s{%s}".formatted(command, | ||
bibEntries.stream() | ||
.map(entry -> entry.getCitationKey().orElse("")) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Empty string is used as a fallback for missing citation keys, which could lead to invalid LaTeX syntax. Should handle this case more explicitly or throw an exception. |
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,11 +11,11 @@ | |
import org.jvnet.hk2.annotations.Service; | ||
|
||
@Service | ||
public class MMDFormatter implements CAYWFormatter { | ||
public class MmdFormatter implements CAYWFormatter { | ||
|
||
@Override | ||
public String getFormatName() { | ||
return "mmd"; | ||
public List<String> getFormatNames() { | ||
return List.of("mmd", "multimarkdown"); | ||
} | ||
|
||
@Override | ||
|
@@ -24,13 +24,12 @@ public MediaType getMediaType() { | |
} | ||
|
||
@Override | ||
public String format(CAYWQueryParams queryParams, List<CAYWEntry> cawEntries) { | ||
List<BibEntry> bibEntries = cawEntries.stream() | ||
.map(CAYWEntry::bibEntry) | ||
.toList(); | ||
|
||
public String format(CAYWQueryParams queryParams, List<CAYWEntry> caywEntries) { | ||
List<BibEntry> bibEntries = caywEntries.stream() | ||
.map(CAYWEntry::bibEntry) | ||
.toList(); | ||
Comment on lines
+28
to
+30
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This intermediate list creation is unnecessary since the stream is used immediately after. The operations can be chained directly for better performance. |
||
return bibEntries.stream() | ||
.map(entry -> "[@"+ entry.getCitationKey().orElse("") + "]") | ||
.collect(Collectors.joining(" ")); | ||
.map(bibEntry -> "[@" + bibEntry.getCitationKey().orElse("") + "]") | ||
.collect(Collectors.joining("")); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,10 +12,9 @@ | |
|
||
@Service | ||
public class PandocFormatter implements CAYWFormatter { | ||
|
||
@Override | ||
public String getFormatName() { | ||
return "pandoc"; | ||
public List<String> getFormatNames() { | ||
return List.of("pandoc", "markdown"); | ||
} | ||
|
||
@Override | ||
|
@@ -24,13 +23,21 @@ public MediaType getMediaType() { | |
} | ||
|
||
@Override | ||
public String format(CAYWQueryParams queryParams, List<CAYWEntry> cawEntries) { | ||
List<BibEntry> bibEntries = cawEntries.stream() | ||
.map(CAYWEntry::bibEntry) | ||
.toList(); | ||
|
||
return bibEntries.stream() | ||
.map(entry -> "[@"+ entry.getCitationKey().orElse("") + "]") | ||
.collect(Collectors.joining(" ")); | ||
public String format(CAYWQueryParams queryParams, List<CAYWEntry> caywEntries) { | ||
String command = queryParams.getCommand(); | ||
List<BibEntry> bibEntries = caywEntries.stream() | ||
.map(CAYWEntry::bibEntry) | ||
.toList(); | ||
// Handle "parencite" command with square brackets | ||
if ("parencite".equalsIgnoreCase(command)) { | ||
Comment on lines
+31
to
+32
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The comment is trivial and only restates what is obvious from the code itself. Comments should add new information or reasoning that cannot be derived directly from the code. |
||
return bibEntries.stream() | ||
.map(bibEntry -> "[@" + bibEntry.getCitationKey().orElse("") + "]") | ||
.collect(Collectors.joining("")); | ||
} else { | ||
// Default: bare @key format with semicolon separator | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The comment merely describes what the code does without providing additional context or reasoning. Such trivial comments should be removed as they don't add value beyond what's visible in the code. |
||
return bibEntries.stream() | ||
.map(bibEntry -> "@" + bibEntry.getCitationKey().orElse("")) | ||
.collect(Collectors.joining("; ")); | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,8 +14,8 @@ | |
public class TypstFormatter implements CAYWFormatter { | ||
|
||
@Override | ||
public String getFormatName() { | ||
return "typst"; | ||
public List<String> getFormatNames() { | ||
return List.of("typst", "typ"); | ||
} | ||
|
||
@Override | ||
|
@@ -24,13 +24,12 @@ public MediaType getMediaType() { | |
} | ||
|
||
@Override | ||
public String format(CAYWQueryParams queryParams, List<CAYWEntry> cawEntries) { | ||
List<BibEntry> bibEntries = cawEntries.stream() | ||
.map(CAYWEntry::bibEntry) | ||
.toList(); | ||
|
||
public String format(CAYWQueryParams queryParams, List<CAYWEntry> caywEntries) { | ||
List<BibEntry> bibEntries = caywEntries.stream() | ||
.map(CAYWEntry::bibEntry) | ||
.toList(); | ||
Comment on lines
+28
to
+30
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Intermediate list creation is unnecessary since the stream is used immediately after. The stream operations could be chained directly for better performance. |
||
return bibEntries.stream() | ||
.map(entry -> "@" + entry.getCitationKey().orElse("")) | ||
.collect(Collectors.joining(" ")); | ||
.map(bibEntry -> "@" + bibEntry.getCitationKey().orElse("")) | ||
.collect(Collectors.joining(", ")); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please set up your workspace with autoformatting and checkstyle according to our guide
https://devdocs.jabref.org/getting-into-the-code/guidelines-for-setting-up-a-local-workspace/intellij-13-code-style.html