You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
* Refactor CitationStyleGeneratorTest
* Add test: [StAX] Parse title, isNumericStyle
* Add CSLFormatUtils
* Refactor CSLCitationOOAdapter and add JavaDoc
* Add test for citeproc DIN 1505-2
* Better method names, more javadoc
* Add tests for CSLFormatUtils
* Add javadoc for adapter
* Fix locales
* Fix submodules for styles
* OpenRewrite
* Fix submodules for styles
* Fix locales
* Rename test method
* Change order of methods in mark manager
* Fix submodules for styles
* Fix locales
* Disable test
* Review actions - I
* Better javadoc for disabled test
* Remove "public" as per best practices
* Review changes [3]
* Swap arguments for CitationStyleTest
* Add comment to @disabled
* Contains utility constants and methods for processing of CSL citations as generated by methods of <a href="https://github.com/michel-kraemer/citeproc-java">citeproc-java</a> ({@link org.jabref.logic.citationstyle.CitationStyleGenerator}).
24
+
* <p>These methods are used in {@link CSLCitationOOAdapter} which inserts CSL citation text into an OO document.</p>
25
+
*/
26
+
publicclassCSLFormatUtils {
27
+
28
+
// TODO: These are static final fields right now, should add the functionality to let user select these and store them in preferences.
* Transforms provided HTML into a format that can be fully parsed and inserted into an OO document.
37
+
* Context: The HTML produced by {@link org.jabref.logic.citationstyle.CitationStyleGenerator#generateCitation(List, String, CitationStyleOutputFormat, BibDatabaseContext, BibEntryTypesManager) generateCitation} or {@link org.jabref.logic.citationstyle.CitationStyleGenerator#generateInText(List, String, CitationStyleOutputFormat, BibDatabaseContext, BibEntryTypesManager) generateInText} is not directly (completely) parsable by by {@link OOTextIntoOO#write(XTextDocument, XTextCursor, OOText) write}.
38
+
* For more details, read the documentation for the {@link OOTextIntoOO} class.
* @param html The HTML string to be transformed into OO-write ready HTML.
42
+
* @return The formatted html string.
43
+
*/
44
+
publicstaticStringtransformHTML(Stringhtml) {
45
+
// Initial clean up of escaped characters
46
+
html = StringEscapeUtils.unescapeHtml4(html);
47
+
48
+
// Handle margins (spaces between citation number and text)
49
+
html = html.replaceAll("<div class=\"csl-left-margin\">(.*?)</div><div class=\"csl-right-inline\">(.*?)</div>", "$1 $2");
50
+
51
+
// Remove unsupported tags
52
+
html = html.replaceAll("<div[^>]*>", "");
53
+
html = html.replace("</div>", "");
54
+
55
+
// Remove unsupported links
56
+
html = html.replaceAll("<a[^>]*>", "");
57
+
html = html.replace("</a>", "");
58
+
59
+
// Replace span tags with inline styles for bold
60
+
html = html.replaceAll("<span style=\"font-weight: ?bold;?\">(.*?)</span>", "<b>$1</b>");
61
+
62
+
// Replace span tags with inline styles for italic
63
+
html = html.replaceAll("<span style=\"font-style: ?italic;?\">(.*?)</span>", "<i>$1</i>");
64
+
65
+
// Replace span tags with inline styles for underline
66
+
html = html.replaceAll("<span style=\"text-decoration: ?underline;?\">(.*?)</span>", "<u>$1</u>");
67
+
68
+
html = html.replaceAll("<span style=\"font-variant: ?small-caps;?\">(.*?)</span>", "<smallcaps>$1</smallcaps>");
69
+
70
+
// Clean up any remaining span tags
71
+
html = html.replaceAll("</?span[^>]*>", "");
72
+
73
+
returnhtml;
74
+
}
75
+
76
+
/**
77
+
* Alphanumeric citations are not natively supported by citeproc-java (see {@link org.jabref.logic.citationstyle.CitationStyleGenerator#generateInText(List, String, CitationStyleOutputFormat, BibDatabaseContext, BibEntryTypesManager) generateInText}).
78
+
* Thus, we manually format a citation to produce its alphanumeric form.
79
+
*
80
+
* @param entries the list of entries for which the alphanumeric citation is to be generated.
81
+
* @return the alphanumeric citation (for a single entry or a group of entries).
* Method to update citation number of a bibliographic entry (to be inserted in the list of references).
114
+
* By default, citeproc-java ({@link org.jabref.logic.citationstyle.CitationStyleGenerator#generateCitation(List, String, CitationStyleOutputFormat, BibDatabaseContext, BibEntryTypesManager) generateCitation} always start the numbering of a list of citations with "1".
115
+
* If a citation doesn't correspond to the first cited entry, the number should be changed to the relevant current citation number.
116
+
* If an entries has been cited before, the colder number should be reused.
117
+
* The number can be enclosed in different formats, such as "1", "1.", "1)", "(1)" or "[1]".
118
+
* <p>
119
+
* <b>Precondition:</b> Use ONLY with numeric citation styles.</p>
120
+
*
121
+
* @param citation the numeric citation with an unresolved number.
122
+
* @param currentNumber the correct number to update the citation with.
123
+
* @return the bibliographic citation with resolved number.
// if the apa-7th-citation.csl citation style changes this has to be modified
53
55
Stringexpected = " <div class=\"csl-entry\">"
@@ -58,6 +60,21 @@ void aPACitation() {
58
60
assertEquals(expected, citation);
59
61
}
60
62
63
+
/**
64
+
* Fails due to citeproc-java ({@link CitationStyleGenerator#generateInText(List, String, CitationStyleOutputFormat, BibDatabaseContext, BibEntryTypesManager) generateInText}) returning an empty citation.
65
+
* Alphanumeric citations are thus, currently manually generated by formatting (see {@link org.jabref.logic.openoffice.oocsltext.CSLFormatUtils#generateAlphanumericCitation(List, BibDatabaseContext) generateAlphaNumericCitation}).
66
+
*/
67
+
@Test
68
+
@Disabled("Till alphanumeric citations are supported by citeproc-java")
" <div class=\"csl-left-margin\">[1]</div><div class=\"csl-right-inline\">B. Smith, B. Jones, and J. Williams, “Title of the test entry,” <span style=\"font-style: italic\">BibTeX Journal</span>, vol. 34, no. 3, pp. 45–67, Jul. 2016, doi: 10.1001/bla.blubb.</div>\n" +
StringactualCitation = CitationStyleGenerator.generateCitation(List.of(entry), style, format, newBibDatabaseContext(), bibEntryTypesManager).getFirst();
120
+
StringactualCitation = CitationStyleGenerator.generateCitation(List.of(testEntry), style, format, context, bibEntryTypesManager).getFirst();
105
121
assertEquals(expectedCitation, actualCitation);
106
122
}
107
123
108
124
@Test
109
125
voidtextFormat() {
110
126
StringexpectedCitation = "[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";
StringactualCitation = CitationStyleGenerator.generateCitation(List.of(entry), style, format, newBibDatabaseContext(newBibDatabase(List.of(entry))), bibEntryTypesManager).getFirst();
131
+
StringactualCitation = CitationStyleGenerator.generateCitation(List.of(testEntry), style, format, context, bibEntryTypesManager).getFirst();
117
132
assertEquals(expectedCitation, actualCitation);
118
133
}
119
134
@@ -134,12 +149,11 @@ void handleDiacritics() {
134
149
@Test
135
150
voidhandleAmpersand() {
136
151
StringexpectedCitation = "[1]B. Smith, B. Jones, and J. Williams, “Famous quote: “&TitleTest&” - that is it,” BibTeX Journal, vol. 34, no. 3, pp. 45–67, Jul. 2016, doi: 10.1001/bla.blubb.\n";
137
-
BibEntryentry = TestEntry.getTestEntry();
138
-
entry.setField(StandardField.TITLE, "Famous quote: “&TitleTest&” - that is it");
152
+
testEntry.setField(StandardField.TITLE, "Famous quote: “&TitleTest&” - that is it");
0 commit comments