diff --git a/src/main/java/org/jabref/logic/openoffice/oocsltext/CSLCitationOOAdapter.java b/src/main/java/org/jabref/logic/openoffice/oocsltext/CSLCitationOOAdapter.java index 865806947f3..e9c611f02ec 100644 --- a/src/main/java/org/jabref/logic/openoffice/oocsltext/CSLCitationOOAdapter.java +++ b/src/main/java/org/jabref/logic/openoffice/oocsltext/CSLCitationOOAdapter.java @@ -69,7 +69,6 @@ public void insertCitation(XTextCursor cursor, CitationStyle selectedStyle, List OOText ooText = OOFormat.setLocaleNone(OOText.fromString(formattedCitation)); insertReferences(cursor, entries, ooText, selectedStyle.isNumericStyle()); - cursor.collapseToEnd(); } /** @@ -119,7 +118,6 @@ public void insertInTextCitation(XTextCursor cursor, CitationStyle selectedStyle } OOText ooText = OOFormat.setLocaleNone(OOText.fromString(finalText)); insertReferences(cursor, List.of(currentEntry), ooText, selectedStyle.isNumericStyle()); - cursor.collapseToEnd(); } } @@ -131,9 +129,6 @@ public void insertEmpty(XTextCursor cursor, CitationStyle selectedStyle, List entries, OOText CSLReferenceMark mark = markManager.createReferenceMark(entries); mark.insertReferenceIntoOO(document, cursor, ooText, !preceedingSpaceExists, false); - // Move the cursor to the end of the inserted text - cursor.collapseToEnd(); - markManager.setUpdateRequired(isNumericStyle); readAndUpdateExistingMarks(); - cursor.collapseToEnd(); } /** diff --git a/src/main/java/org/jabref/logic/openoffice/oocsltext/CSLFormatUtils.java b/src/main/java/org/jabref/logic/openoffice/oocsltext/CSLFormatUtils.java index 1ac64172287..525a1803be5 100644 --- a/src/main/java/org/jabref/logic/openoffice/oocsltext/CSLFormatUtils.java +++ b/src/main/java/org/jabref/logic/openoffice/oocsltext/CSLFormatUtils.java @@ -72,6 +72,15 @@ public static String transformHTML(String html) { // Clean up any remaining span tags html = html.replaceAll("]*>", ""); + // Convert line breaks to paragraph breaks + html = html.replaceAll("[\n\r]+", "

"); + + // Remove leading paragraph tags (preserving any whitespaces after them for indentation) + html = html.replaceAll("^\\s*

\\s*

", ""); + + // Remove extra trailing paragraph tags when there are multiple (keeping one) + html = html.replaceAll("(?:

\\s*

\\s*){2,}$", "

"); + return html; } @@ -113,9 +122,9 @@ public static String generateAlphanumericCitation(List entries, BibDat /** * Method to update citation number of a bibliographic entry (to be inserted in the list of references). - * By default, citeproc-java ({@link org.jabref.logic.citationstyle.CitationStyleGenerator#generateBibliography(List, String, CitationStyleOutputFormat, BibDatabaseContext, BibEntryTypesManager) generateBibliography} always start the numbering of a list of citations with "1". - * If a citation doesn't correspond to the first cited entry, the number should be changed to the relevant current citation number. - * If an entries has been cited before, the colder number should be reused. + * By default, citeproc-java ({@link org.jabref.logic.citationstyle.CitationStyleGenerator#generateBibliography(List, String, CitationStyleOutputFormat, BibDatabaseContext, BibEntryTypesManager) generateBibliography} always starts the numbering of a list of citations with "1". + * If a citation doesn't correspond to the first cited entry, the number should be changed to the appropriate current citation number. + * The numbers should be globally unique. If an entry has been cited before, the older citation number corresponding to it should be reused. * The number can be enclosed in different formats, such as "1", "1.", "1)", "(1)" or "[1]". *

* Precondition: Use ONLY with numeric citation styles.

diff --git a/src/main/java/org/jabref/logic/openoffice/oocsltext/CSLUpdateBibliography.java b/src/main/java/org/jabref/logic/openoffice/oocsltext/CSLUpdateBibliography.java index 107974934b4..732db3899ec 100644 --- a/src/main/java/org/jabref/logic/openoffice/oocsltext/CSLUpdateBibliography.java +++ b/src/main/java/org/jabref/logic/openoffice/oocsltext/CSLUpdateBibliography.java @@ -101,9 +101,7 @@ private void populateCSLBibTextSection(XTextDocument doc, // Use CSLCitationOOAdapter to insert the bibliography cslAdapter.insertBibliography(cursor, citationStyle, entries, bibDatabaseContext, bibEntryTypesManager); - LOGGER.debug("Bibliography inserted using CSLCitationOOAdapter"); - cursor.collapseToEnd(); LOGGER.debug("CSL bibliography section population completed"); } } diff --git a/src/test/java/org/jabref/logic/openoffice/oocsltext/CSLFormatUtilsTest.java b/src/test/java/org/jabref/logic/openoffice/oocsltext/CSLFormatUtilsTest.java index 57e054027fa..69df8bb42f1 100644 --- a/src/test/java/org/jabref/logic/openoffice/oocsltext/CSLFormatUtilsTest.java +++ b/src/test/java/org/jabref/logic/openoffice/oocsltext/CSLFormatUtilsTest.java @@ -159,114 +159,94 @@ static Stream ooHTMLTransformFromRawBibliography() { // Non-numeric, parentheses, commas, full stops, slashes, hyphens, colons, italics Arguments.of( - " Smith, B., Jones, B., & Williams, J. (2016). Title of the test entry. BibTeX Journal, 34(3), 45–67. https://doi.org/10.1001/bla.blubb\n", + " Smith, B., Jones, B., & Williams, J. (2016). Title of the test entry. BibTeX Journal, 34(3), 45–67. https://doi.org/10.1001/bla.blubb

", STYLE_LIST.stream().filter(e -> "American Psychological Association 7th edition".equals(e.getTitle())).findAny().get() ), // Numeric type "[1]", brackets, newlines Arguments.of( - " \n" + - " [1] B. Smith, B. Jones, and J. Williams, “Title of the test entry,” BibTeX Journal, vol. 34, no. 3, pp. 45–67, Jul. 2016, doi: 10.1001/bla.blubb.\n" + - " \n", + " [1] B. Smith, B. Jones, and J. Williams, “Title of the test entry,” BibTeX Journal, vol. 34, no. 3, pp. 45–67, Jul. 2016, doi: 10.1001/bla.blubb.

", STYLE_LIST.stream().filter(e -> "IEEE".equals(e.getTitle())).findAny().get() ), // Numeric type "1." Arguments.of( - " \n" + - " 1. Smith, B., Jones, B., Williams, J.: Title of the test entry. BibTeX Journal. 34, 45–67 (2016). https://doi.org/10.1001/bla.blubb.\n" + - " \n", + " 1. Smith, B., Jones, B., Williams, J.: Title of the test entry. BibTeX Journal. 34, 45–67 (2016). https://doi.org/10.1001/bla.blubb.

", STYLE_LIST.stream().filter(e -> "Springer - Lecture Notes in Computer Science".equals(e.getTitle())).findAny().get() ), Arguments.of( - " Smith, Bill, Bob Jones, and Jeff Williams. 2016. “Title of the Test Entry.” Edited by Phil Taylor. BibTeX Journal 34 (3): 45–67. https://doi.org/10.1001/bla.blubb.\n", + " Smith, Bill, Bob Jones, and Jeff Williams. 2016. “Title of the Test Entry.” Edited by Phil Taylor. BibTeX Journal 34 (3): 45–67. https://doi.org/10.1001/bla.blubb.

", STYLE_LIST.stream().filter(e -> "Chicago Manual of Style 17th edition (author-date)".equals(e.getTitle())).findAny().get() ), // Semicolons Arguments.of( - " \n" + - " 1. Smith B, Jones B, Williams J. Title of the test entry. Taylor P, editor. BibTeX Journal [Internet]. 2016 Jul;34(3):45–67. Available from: https://github.com/JabRef\n" + - " \n", + " 1. Smith B, Jones B, Williams J. Title of the test entry. Taylor P, editor. BibTeX Journal [Internet]. 2016 Jul;34(3):45–67. Available from: https://github.com/JabRef

", STYLE_LIST.stream().filter(e -> "Vancouver".equals(e.getTitle())).findAny().get() ), Arguments.of( - " \n" + - " 1. Smith, B., Jones, B. & Williams, J. Title of the test entry. BibTeX Journal 34, 45–67 (2016).\n" + - " \n", + " 1. Smith, B., Jones, B. & Williams, J. Title of the test entry. BibTeX Journal 34, 45–67 (2016).

", STYLE_LIST.stream().filter(e -> "Nature".equals(e.getTitle())).findAny().get() ), Arguments.of( - " \n" + - " 1. Smith B, Jones B, Williams J. Title of the test entry. Taylor P, ed. BibTeX Journal. 2016;34(3):45-67. doi:10.1001/bla.blubb\n" + - " \n", + " 1. Smith B, Jones B, Williams J. Title of the test entry. Taylor P, ed. BibTeX Journal. 2016;34(3):45-67. doi:10.1001/bla.blubb

", STYLE_LIST.stream().filter(e -> "American Medical Association 11th edition".equals(e.getTitle())).findAny().get() ), // Small-caps Arguments.of( - " Smith, B., Jones, B., Williams, J. (2016) Title of the test entry Taylor, P. (ed.). BibTeX Journal, 34(3), pp. 45–67.\n", + " Smith, B., Jones, B., Williams, J. (2016) Title of the test entry Taylor, P. (ed.). BibTeX Journal, 34(3), pp. 45–67.

", STYLE_LIST.stream().filter(e -> "De Montfort University - Harvard".equals(e.getTitle())).findAny().get() ), // Underlines Arguments.of( - " Smith, Bill, Bob Jones, and Jeff Williams. “Title of the test entry.” Ed. Phil Taylor. BibTeX Journal 34.3 (2016): 45–67. .\n", + " Smith, Bill, Bob Jones, and Jeff Williams. “Title of the test entry.” Ed. Phil Taylor. BibTeX Journal 34.3 (2016): 45–67. .

", STYLE_LIST.stream().filter(e -> "Modern Language Association 7th edition (underline)".equals(e.getTitle())).findAny().get() ), // Non-breaking spaces Arguments.of( - " Smith, Bill, Bob Jones, & Jeff Williams, “Title of the test entry,” BibTeX Journal, 2016, vol. 34, no. 3, pp. 45–67.\n", + " Smith, Bill, Bob Jones, & Jeff Williams, “Title of the test entry,” BibTeX Journal, 2016, vol. 34, no. 3, pp. 45–67.

", STYLE_LIST.stream().filter(e -> "Histoire & Mesure (Français)".equals(e.getTitle())).findAny().get() ), // Numeric with a full stop - "1." Arguments.of( - " \n" + - " 1. Smith, B., Jones, B. and Williams, J. 2016. Title of the test entry. BibTeX Journal. 34: 45–67.\n" + - " \n", + " 1. Smith, B., Jones, B. and Williams, J. 2016. Title of the test entry. BibTeX Journal. 34: 45–67.

", STYLE_LIST.stream().filter(e -> "The Journal of Veterinary Medical Science".equals(e.getTitle())).findAny().get() ), // Bold text, bold numeric with a full stop - "1." Arguments.of( - " \n" + - " 1. Smith B, Jones B, Williams J. Title of the test entry. BibTeX Journal 2016 ; 34 : 45–67.\n" + - " \n", + " 1. Smith B, Jones B, Williams J. Title of the test entry. BibTeX Journal 2016 ; 34 : 45–67.

", STYLE_LIST.stream().filter(e -> "Acta Orthopædica Belgica".equals(e.getTitle())).findAny().get() ), // Naked numeric - "1" Arguments.of( - " \n" + - " 1 Smith Bill, Jones Bob, Williams Jeff. Title of the test entry. BibTeX Journal 2016;34(3):45–67. Doi: 10.1001/bla.blubb.\n" + - " \n", + " 1 Smith Bill, Jones Bob, Williams Jeff. Title of the test entry. BibTeX Journal 2016;34(3):45–67. Doi: 10.1001/bla.blubb.

", STYLE_LIST.stream().filter(e -> "Acta Anaesthesiologica Taiwanica".equals(e.getTitle())).findAny().get() ), // Numeric in parentheses - "(1)" Arguments.of( - " \n" + - " (1) Smith, B.; Jones, B.; Williams, J. Title of the Test Entry. BibTeX Journal 2016, 34 (3), 45–67. https://doi.org/10.1001/bla.blubb.\n" + - " \n", + " (1) Smith, B.; Jones, B.; Williams, J. Title of the Test Entry. BibTeX Journal 2016, 34 (3), 45–67. https://doi.org/10.1001/bla.blubb.

", STYLE_LIST.stream().filter(e -> "American Chemical Society".equals(e.getTitle())).findAny().get() ), // Numeric with right parenthesis - "1)" Arguments.of( - " \n" + - " 1) Smith B., Jones B., Williams J., BibTeX Journal, 34, 45–67 (2016).\n" + - " \n", + " 1) Smith B., Jones B., Williams J., BibTeX Journal, 34, 45–67 (2016).

", STYLE_LIST.stream().filter(e -> "Chemical and Pharmaceutical Bulletin".equals(e.getTitle())).findAny().get() ), // Numeric in superscript - "1" Arguments.of( - " 1 B. Smith, B. Jones, and J. Williams, “Title of the test entry,” BibTeX Journal 34(3), 45–67 (2016).\n", + " 1 B. Smith, B. Jones, and J. Williams, “Title of the test entry,” BibTeX Journal 34(3), 45–67 (2016).

", STYLE_LIST.stream().filter(e -> "American Institute of Physics 4th edition".equals(e.getTitle())).findAny().get() ) ); @@ -521,55 +501,43 @@ static Stream updateSingleNumericCitation() { // Type: "[1]" Arguments.of( - " \n" + - " [3] B. Smith, B. Jones, and J. Williams, “Title of the test entry,” BibTeX Journal, vol. 34, no. 3, pp. 45–67, Jul. 2016, doi: 10.1001/bla.blubb.\n" + - " \n", + " [3] B. Smith, B. Jones, and J. Williams, “Title of the test entry,” BibTeX Journal, vol. 34, no. 3, pp. 45–67, Jul. 2016, doi: 10.1001/bla.blubb.

", STYLE_LIST.stream().filter(e -> "IEEE".equals(e.getTitle())).findAny().get() ), // Type: "1." Arguments.of( - " \n" + - " 3. Smith, B., Jones, B. and Williams, J. 2016. Title of the test entry. BibTeX Journal. 34: 45–67.\n" + - " \n", + " 3. Smith, B., Jones, B. and Williams, J. 2016. Title of the test entry. BibTeX Journal. 34: 45–67.

", STYLE_LIST.stream().filter(e -> "The Journal of Veterinary Medical Science".equals(e.getTitle())).findAny().get() ), - // Type:"1." + // Type: "1." Arguments.of( - " \n" + - " 3. Smith B, Jones B, Williams J. Title of the test entry. BibTeX Journal 2016 ; 34 : 45–67.\n" + - " \n", + " 3. Smith B, Jones B, Williams J. Title of the test entry. BibTeX Journal 2016 ; 34 : 45–67.

", STYLE_LIST.stream().filter(e -> "Acta Orthopædica Belgica".equals(e.getTitle())).findAny().get() ), // Type: "1" Arguments.of( - " \n" + - " 3 Smith Bill, Jones Bob, Williams Jeff. Title of the test entry. BibTeX Journal 2016;34(3):45–67. Doi: 10.1001/bla.blubb.\n" + - " \n", + " 3 Smith Bill, Jones Bob, Williams Jeff. Title of the test entry. BibTeX Journal 2016;34(3):45–67. Doi: 10.1001/bla.blubb.

", STYLE_LIST.stream().filter(e -> "Acta Anaesthesiologica Taiwanica".equals(e.getTitle())).findAny().get() ), // Type: "(1)" Arguments.of( - " \n" + - " (3) Smith, B.; Jones, B.; Williams, J. Title of the Test Entry. BibTeX Journal 2016, 34 (3), 45–67. https://doi.org/10.1001/bla.blubb.\n" + - " \n", + " (3) Smith, B.; Jones, B.; Williams, J. Title of the Test Entry. BibTeX Journal 2016, 34 (3), 45–67. https://doi.org/10.1001/bla.blubb.

", STYLE_LIST.stream().filter(e -> "American Chemical Society".equals(e.getTitle())).findAny().get() ), // Type: "1)" Arguments.of( - " \n" + - " 3) Smith B., Jones B., Williams J., BibTeX Journal, 34, 45–67 (2016).\n" + - " \n", + " 3) Smith B., Jones B., Williams J., BibTeX Journal, 34, 45–67 (2016).

", STYLE_LIST.stream().filter(e -> "Chemical and Pharmaceutical Bulletin".equals(e.getTitle())).findAny().get() ), // Type: "1" Arguments.of( - " 3 B. Smith, B. Jones, and J. Williams, “Title of the test entry,” BibTeX Journal 34(3), 45–67 (2016).\n", + " 3 B. Smith, B. Jones, and J. Williams, “Title of the test entry,” BibTeX Journal 34(3), 45–67 (2016).

", STYLE_LIST.stream().filter(e -> "American Institute of Physics 4th edition".equals(e.getTitle())).findAny().get() ) );