Skip to content

Commit

Permalink
Merge branch 'main' into LuceneSearch
Browse files Browse the repository at this point in the history
  • Loading branch information
koppor authored Aug 28, 2024
2 parents 6616c2a + cdfd7bc commit 73890f1
Showing 1 changed file with 25 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -153,29 +153,35 @@ public void insertBibliography(XTextCursor cursor, CitationStyle selectedStyle,

String style = selectedStyle.getSource();

// Sort entries based on their order of appearance in the document
entries.sort(Comparator.comparingInt(entry -> markManager.getCitationNumber(entry.getCitationKey().orElse(""))));
for (BibEntry entry : entries) {
String citation = CitationStyleGenerator.generateCitation(List.of(entry), style, CSLFormatUtils.OUTPUT_FORMAT, bibDatabaseContext, bibEntryTypesManager).getFirst();
String citationKey = entry.getCitationKey().orElse("");
int currentNumber = markManager.getCitationNumber(citationKey);
if (selectedStyle.isNumericStyle()) {
// Sort entries based on their order of appearance in the document
entries.sort(Comparator.comparingInt(entry -> markManager.getCitationNumber(entry.getCitationKey().orElse(""))));

String formattedCitation;
if (selectedStyle.isNumericStyle()) {
formattedCitation = CSLFormatUtils.updateSingleBibliographyNumber(CSLFormatUtils.transformHTML(citation), currentNumber);
} else {
formattedCitation = CSLFormatUtils.transformHTML(citation);
}
OOText ooText = OOFormat.setLocaleNone(OOText.fromString(formattedCitation));
for (BibEntry entry : entries) {
String citation = CitationStyleGenerator.generateCitation(List.of(entry), style, CSLFormatUtils.OUTPUT_FORMAT, bibDatabaseContext, bibEntryTypesManager).getFirst();
String citationKey = entry.getCitationKey().orElse("");
int currentNumber = markManager.getCitationNumber(citationKey);

OOTextIntoOO.write(document, cursor, ooText);
if (selectedStyle.isNumericStyle()) {
// Select the paragraph break
cursor.goLeft((short) 1, true);
String formattedCitation = CSLFormatUtils.updateSingleBibliographyNumber(CSLFormatUtils.transformHTML(citation), currentNumber);
OOText ooText = OOFormat.setLocaleNone(OOText.fromString(formattedCitation));

OOTextIntoOO.write(document, cursor, ooText);
// Select the paragraph break
cursor.goLeft((short) 1, true);

// Delete the selected content (paragraph break)
cursor.setString("");
}
} else {
// Ordering will be according to citeproc item data provider (default)
List<String> citations = CitationStyleGenerator.generateCitation(entries, style, CSLFormatUtils.OUTPUT_FORMAT, bibDatabaseContext, bibEntryTypesManager);

// Delete the selected content (paragraph break)
cursor.setString("");
for (String citation : citations) {
String formattedCitation = CSLFormatUtils.transformHTML(citation);
OOText ooText = OOFormat.setLocaleNone(OOText.fromString(formattedCitation));
OOTextIntoOO.write(document, cursor, ooText);
}
cursor.collapseToEnd();
}
}

Expand Down

0 comments on commit 73890f1

Please sign in to comment.