From f6e9c5cbd1a5a45a3362b9f5064809c9e39237c3 Mon Sep 17 00:00:00 2001 From: Oliver Kopp Date: Thu, 26 Nov 2026 18:08:45 +0000 Subject: [PATCH] BACKPORT-CONFLICT --- CHANGELOG.md | 2 + .../jabref/logic/layout/format/HTMLChars.java | 36 ++++- .../logic/preview/BstPreviewLayout.java | 148 ++---------------- .../jabref/logic/util/strings/StringUtil.java | 6 + .../logic/bst/BstPreviewLayoutTest.java | 106 ++++++++++--- .../logic/layout/format/HTMLCharsTest.java | 12 +- .../logic/util/strings/StringUtilTest.java | 2 + 7 files changed, 150 insertions(+), 162 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6d4fb5ff2867..b72d1fab74d9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -33,6 +33,8 @@ Note that this project **does not** adhere to [Semantic Versioning](https://semv - We fixed an issue where back navigation selected a deleted entry instead of skipping it. [#17353](https://github.com/JabRef/jabref/issues/17353) - We fixed the linked file tooltip showing the old file name after renaming or moving the file. [#9277](https://github.com/JabRef/jabref/issues/9277) - We fixed an issue where citationcount, day, and dayfiled columns were sorted alphabetically instead of numerically. [#17459](https://github.com/JabRef/jabref/issues/17459) +- We fixed an issue where BST entry previews showed italic and bold text as Unicode mathematical letters. [#17902](https://github.com/JabRef/jabref/pull/17902) +- We fixed an issue where the customized entry preview ignored small caps and showed LaTeX commands inside emphasized text. [#17902](https://github.com/JabRef/jabref/pull/17902) ## [6.0-beta.1] - 2026-09-21 diff --git a/jablib/src/main/java/org/jabref/logic/layout/format/HTMLChars.java b/jablib/src/main/java/org/jabref/logic/layout/format/HTMLChars.java index bc07427d54d1..3de7a1a531e0 100644 --- a/jablib/src/main/java/org/jabref/logic/layout/format/HTMLChars.java +++ b/jablib/src/main/java/org/jabref/logic/layout/format/HTMLChars.java @@ -2,6 +2,7 @@ import java.util.Map; import java.util.Objects; +import java.util.Set; import java.util.regex.Pattern; import org.jabref.logic.layout.ParamLayoutFormatter; @@ -20,6 +21,9 @@ public class HTMLChars implements ParamLayoutFormatter { /// - `&Hey` **Matched** private static final Pattern HTML_ENTITY_PATTERN = Pattern.compile("&(?!(?:[a-z0-9]+|#[0-9]{1,6}|#x[0-9a-fA-F]{1,6});)"); + // Declarations that apply to the rest of the enclosing group instead of taking an argument + private static final Set SWITCHES = Set.of("em", "it", "bf", "sc", "scshape"); + private boolean keepCurlyBraces = false; @Override @@ -31,8 +35,10 @@ public void setArgument(String arg) { @Override public String format(String inField) { - String field = normalizedField(inField); + return convert(normalizedField(inField)).replace("~", " "); // Replace any remaining ~ with   (non-breaking spaces) + } + private String convert(String field) { StringBuilder sb = new StringBuilder(); StringBuilder currentCommand = null; @@ -50,7 +56,8 @@ public String format(String inField) { /* Close Command */ String command = currentCommand.toString(); String result = HTML_CHARS.get(command); - sb.append(Objects.requireNonNullElse(result, command)); + // A formatting command without argument formats nothing + sb.append(Objects.requireNonNullElse(result, getHTMLTag(command).isEmpty() ? command : "")); } escaped = true; incommand = true; @@ -112,13 +119,20 @@ public String format(String inField) { // command. // If so, handle. String tag = getHTMLTag(command); + // `\textsc {X}` is `\textsc{X}`; switches such as `{\em X}` instead apply to the rest of the group + int nextNonWhitespace = skipWhitespace(field, i); + if (!tag.isEmpty() && Character.isWhitespace(c) && !SWITCHES.contains(command) + && (nextNonWhitespace < field.length()) && (field.charAt(nextNonWhitespace) == '{')) { + i = nextNonWhitespace; + c = '{'; + } if (!tag.isEmpty()) { String part = StringUtil.getPart(field, i, true); if (this.keepCurlyBraces && (c == '{' || (c == '}'))) { i++; } i += part.length(); - sb.append('<').append(tag).append('>').append(part).append("'); + sb.append('<').append(tag).append('>').append(convert(part)).append("'); } else if (c == '{') { String argument = StringUtil.getPart(field, i, true); i += this.keepCurlyBraces ? argument.length() + 1 : argument.length(); @@ -172,7 +186,7 @@ public String format(String inField) { } } - return sb.toString().replace("~", " "); // Replace any remaining ~ with   (non-breaking spaces) + return sb.toString(); } private String normalizedField(String inField) { @@ -185,6 +199,14 @@ private String normalizedField(String inField) { .replaceAll("\\$([^$]*)\\$", this.keepCurlyBraces ? "\\\\{$1\\\\}" : "$1}"); } + private static int skipWhitespace(String field, int index) { + while ((index < field.length()) && Character.isWhitespace(field.charAt(index))) { + index++; + } + return index; + } + + /// Returns the opening tag without angle brackets; its first word is the element name private String getHTMLTag(String latexCommand) { String result = ""; switch (latexCommand) { @@ -203,6 +225,12 @@ private String getHTMLTag(String latexCommand) { case "bf": result = "b"; break; + // Small caps + case "textsc": + case "sc": + case "scshape": + result = "span style=\"font-variant: small-caps\""; + break; // Underline case "underline": result = "u"; diff --git a/jablib/src/main/java/org/jabref/logic/preview/BstPreviewLayout.java b/jablib/src/main/java/org/jabref/logic/preview/BstPreviewLayout.java index 0f749e53925d..352e08ec2993 100644 --- a/jablib/src/main/java/org/jabref/logic/preview/BstPreviewLayout.java +++ b/jablib/src/main/java/org/jabref/logic/preview/BstPreviewLayout.java @@ -14,10 +14,15 @@ import org.jabref.logic.cleanup.ConvertToBibtexCleanup; import org.jabref.logic.formatter.bibtexfields.RemoveNewlinesFormatter; import org.jabref.logic.l10n.Localization; +import org.jabref.logic.layout.format.HTMLChars; import org.jabref.logic.layout.format.LatexToUnicodeFormatter; import org.jabref.logic.layout.format.RemoveLatexCommandsFormatter; +<<<<<<< HEAD import org.jabref.logic.layout.format.RemoveTilde; import org.jabref.logic.openoffice.style.BstStyle; +======= +import org.jabref.logic.openoffice.bst.BstStyle; +>>>>>>> 201bff7020 (Render BST preview italics and bold as text, not math letters (#17902)) import org.jabref.logic.util.StandardFileType; import org.jabref.model.database.BibDatabaseContext; import org.jabref.model.entry.BibEntry; @@ -40,15 +45,6 @@ public final class BstPreviewLayout implements PreviewLayout { private static final Pattern LATEX_COMMAND_PATTERN = Pattern.compile("(?m)^\\\\.*$"); private static final Pattern MULTIPLE_SPACES_PATTERN = Pattern.compile(" +"); - // LaTeX inline formatting → HTML. Italic and bold survive `LatexToUnicodeFormatter`, while - // `\textsc{...}` has to be converted earlier because it would otherwise be reduced to plain text. - private static final Pattern EMPH_PATTERN = Pattern.compile("\\\\emph\\{([^}]*?)}"); - private static final Pattern TEXTIT_PATTERN = Pattern.compile("\\\\textit\\{([^}]*?)}"); - private static final Pattern TEXTBF_PATTERN = Pattern.compile("\\\\textbf\\{([^}]*?)}"); - private static final Pattern GROUP_EM_PATTERN = Pattern.compile("\\{\\\\em\\s+([^}]*?)}"); - private static final Pattern GROUP_IT_PATTERN = Pattern.compile("\\{\\\\it\\s+([^}]*?)}"); - private static final Pattern GROUP_BF_PATTERN = Pattern.compile("\\{\\\\bf\\s+([^}]*?)}"); - /// Matches a single LaTeX math command wrapped in the `{{$...$}}` form written by some /// exporters, e.g. `{{$\Sigma$}}`. Group 1 is the command without its leading backslash /// (`Sigma`). Reads as: `{{` `$` `\` (command) `$` `}}`. @@ -152,145 +148,21 @@ public String generatePreview(BibEntry originalEntry, BibDatabaseContext databas result = LATEX_COMMAND_PATTERN.matcher(result).replaceAll(""); // Remove some IEEEtran.bst output (resulting from a multiline \\providecommand) result = result.replace("#2}}", ""); - result = convertInlineSmallCapsToHtml(result); + // HTMLChars would turn line breaks into
+ result = new RemoveNewlinesFormatter().format(result); + // Before LatexToUnicodeFormatter, which would turn italic and bold into Unicode mathematical letters + // (not searchable, read out letter by letter by screen readers) + result = new HTMLChars().format(result); // Have quotes right - and more result = new LatexToUnicodeFormatter().format(result); result = result.replace("``", "\""); result = result.replace("''", "\""); - // Convert LaTeX inline formatting to HTML before RemoveLatexCommandsFormatter strips them. - // \\emph{X} and {\\em X} forms (IEEEtran uses \\emph, abbrv uses {\\em}) - result = EMPH_PATTERN.matcher(result).replaceAll("$1"); - result = TEXTIT_PATTERN.matcher(result).replaceAll("$1"); - result = GROUP_EM_PATTERN.matcher(result).replaceAll("$1"); - result = GROUP_IT_PATTERN.matcher(result).replaceAll("$1"); - result = TEXTBF_PATTERN.matcher(result).replaceAll("$1"); - result = GROUP_BF_PATTERN.matcher(result).replaceAll("$1"); // Final cleanup - result = new RemoveNewlinesFormatter().format(result); result = new RemoveLatexCommandsFormatter().format(result); - result = new RemoveTilde().format(result); result = MULTIPLE_SPACES_PATTERN.matcher(result.trim()).replaceAll(" "); return result; } - private static String convertInlineSmallCapsToHtml(String latex) { - String html = replaceCommandWithBalancedArgument(latex, "textsc"); - return replaceLegacySwitchWithBalancedArgument(html, "sc"); - } - - private static String replaceCommandWithBalancedArgument(String input, String command) { - String commandPrefix = "\\" + command; - StringBuilder output = new StringBuilder(input.length()); - int index = 0; - while (index < input.length()) { - if (!input.startsWith(commandPrefix, index) || isEscaped(input, index)) { - output.append(input.charAt(index)); - index++; - continue; - } - - int commandEnd = index + commandPrefix.length(); - if ((commandEnd < input.length()) && Character.isLetter(input.charAt(commandEnd))) { - output.append(input.charAt(index)); - index++; - continue; - } - - int openingBrace = skipWhitespace(input, commandEnd); - if ((openingBrace >= input.length()) || (input.charAt(openingBrace) != '{')) { - output.append(input.charAt(index)); - index++; - continue; - } - - int contentStart = openingBrace + 1; - int groupEnd = findBalancedGroupEnd(input, contentStart); - if (groupEnd < 0) { - output.append(input, index, input.length()); - break; - } - - output.append("") - .append(input, contentStart, groupEnd) - .append(""); - index = groupEnd + 1; - } - return output.toString(); - } - - private static String replaceLegacySwitchWithBalancedArgument(String input, String command) { - String legacyCommandPrefix = "{\\" + command; - StringBuilder output = new StringBuilder(input.length()); - int index = 0; - while (index < input.length()) { - if (!input.startsWith(legacyCommandPrefix, index)) { - output.append(input.charAt(index)); - index++; - continue; - } - - int commandEnd = index + legacyCommandPrefix.length(); - if ((commandEnd < input.length()) && Character.isLetter(input.charAt(commandEnd))) { - output.append(input.charAt(index)); - index++; - continue; - } - if ((commandEnd >= input.length()) || (!Character.isWhitespace(input.charAt(commandEnd)) && (input.charAt(commandEnd) != '}'))) { - output.append(input.charAt(index)); - index++; - continue; - } - - int contentStart = skipWhitespace(input, commandEnd); - int groupEnd = findBalancedGroupEnd(input, contentStart); - if (groupEnd < 0) { - output.append(input, index, input.length()); - break; - } - - output.append("") - .append(input, contentStart, groupEnd) - .append(""); - index = groupEnd + 1; - } - return output.toString(); - } - - private static int skipWhitespace(String input, int startIndex) { - int index = startIndex; - while ((index < input.length()) && Character.isWhitespace(input.charAt(index))) { - index++; - } - return index; - } - - private static int findBalancedGroupEnd(String input, int contentStart) { - int depth = 0; - for (int index = contentStart; index < input.length(); index++) { - char currentCharacter = input.charAt(index); - if (isEscaped(input, index)) { - continue; - } - if (currentCharacter == '{') { - depth++; - } else if (currentCharacter == '}') { - if (depth == 0) { - return index; - } - depth--; - } - } - return -1; - } - - private static boolean isEscaped(String input, int index) { - int backslashCount = 0; - for (int pos = index - 1; pos >= 0 && input.charAt(pos) == '\\'; pos--) { - backslashCount++; - } - return (backslashCount % 2) == 1; - } - /// Replaces `{{$\Cmd$}}` math expressions in all fields of the given entry by the corresponding /// Unicode character, wrapped in braces. The entry is modified in place, so it has to be a copy. /// diff --git a/jablib/src/main/java/org/jabref/logic/util/strings/StringUtil.java b/jablib/src/main/java/org/jabref/logic/util/strings/StringUtil.java index 9bcf769ca101..9227cb7e1293 100644 --- a/jablib/src/main/java/org/jabref/logic/util/strings/StringUtil.java +++ b/jablib/src/main/java/org/jabref/logic/util/strings/StringUtil.java @@ -104,6 +104,12 @@ public static String getPart(String text, int startIndex, boolean terminateOnEnd // end argument and leave whitespace for further processing break; } + if ((c == '\\') && ((index + 1) < text.length())) { + // Keep escaped characters together, so that `\{` and `\}` do not count as grouping + part.append(c).append(text.charAt(index + 1)); + index += 2; + continue; + } if ((c == '}') && (--count < 0)) { break; } else if (c == '{') { diff --git a/jablib/src/test/java/org/jabref/logic/bst/BstPreviewLayoutTest.java b/jablib/src/test/java/org/jabref/logic/bst/BstPreviewLayoutTest.java index e82ef7dbe71e..66a108c76217 100644 --- a/jablib/src/test/java/org/jabref/logic/bst/BstPreviewLayoutTest.java +++ b/jablib/src/test/java/org/jabref/logic/bst/BstPreviewLayoutTest.java @@ -30,7 +30,7 @@ void generatePreviewForSimpleEntryUsingAbbr() throws URISyntaxException { BibEntry entry = new BibEntry().withField(StandardField.AUTHOR, "Oliver Kopp") .withField(StandardField.TITLE, "Thoughts on Development"); String preview = bstPreviewLayout.generatePreview(entry, bibDatabaseContext); - assertEquals("O.\u00a0Kopp. Thoughts on development.", preview); + assertEquals("O. Kopp. Thoughts on development.", preview); } @Test @@ -40,7 +40,7 @@ void generatePreviewForEntryWithMathFormulaInTitle() throws URISyntaxException { .withField(StandardField.AUTHOR, "Jane Doe") .withField(StandardField.TITLE, "Characterization of $\\alpha$"); String preview = bstPreviewLayout.generatePreview(entry, bibDatabaseContext); - assertEquals("J.\u00a0Doe. Characterization of α.", preview); + assertEquals("J. Doe. Characterization of α.", preview); } @Test @@ -50,21 +50,21 @@ void monthMayIsCorrectlyRendered() throws URISyntaxException { .withField(StandardField.TITLE, "Thoughts on Development") .withField(StandardField.MONTH, "#May#"); String preview = bstPreviewLayout.generatePreview(entry, bibDatabaseContext); - assertEquals("O.\u00a0Kopp. Thoughts on development, May.", preview); + assertEquals("O. Kopp. Thoughts on development, May.", preview); } @Test void generatePreviewForSliceTheoremPaperUsingAbbr() throws URISyntaxException { BstPreviewLayout bstPreviewLayout = new BstPreviewLayout(Path.of(BstPreviewLayoutTest.class.getResource("abbrv.bst").toURI())); String preview = bstPreviewLayout.generatePreview(getSliceTheoremPaper(), bibDatabaseContext); - assertEquals("T.\u00a0Diez. Slice theorem for fréchet group actions and covariant symplectic field theory. May 2014.", preview); + assertEquals("T. Diez. Slice theorem for fréchet group actions and covariant symplectic field theory. May 2014.", preview); } @Test void generatePreviewForSliceTheoremPaperUsingIEEE() throws URISyntaxException { BstPreviewLayout bstPreviewLayout = new BstPreviewLayout(Path.of(BstPreviewLayoutTest.class.getResource("IEEEtran.bst").toURI())); String preview = bstPreviewLayout.generatePreview(getSliceTheoremPaper(), bibDatabaseContext); - assertEquals("T.\u00a0Diez, \"Slice theorem for fréchet group actions and covariant symplectic field theory\" May 2014.", preview); + assertEquals("T. Diez, \"Slice theorem for fréchet group actions and covariant symplectic field theory\" May 2014.", preview); } @Test @@ -73,7 +73,7 @@ void mathSymbolsInBracedMathAreConvertedToUnicode() throws URISyntaxException { BibEntry entry = new BibEntry().withField(StandardField.AUTHOR, "Oliver Kopp") .withField(StandardField.TITLE, "{{$\\Sigma$}}{{$\\Delta$}} Modulator"); String preview = bstPreviewLayout.generatePreview(entry, bibDatabaseContext); - assertEquals("O.\u00a0Kopp. \u03a3\u0394 modulator.", preview); + assertEquals("O. Kopp. \u03a3\u0394 modulator.", preview); } @ParameterizedTest @@ -90,32 +90,51 @@ private static Stream generatePreviewHandlesInlineFormatting() { return Stream.of( // Small-caps forms that should be preserved in the preview output - Arguments.of("\\textsc{L{\\'o}pez}", "O.\u00a0Kopp. López."), - Arguments.of("{\\sc L{\\'o}pez}", "O.\u00a0Kopp. López."), - Arguments.of("\\textsc{Outer \\textsc{inner} text}", "O.\u00a0Kopp. Outer inner text."), + Arguments.of("\\textsc{L{\\'o}pez}", "O. Kopp. López."), + Arguments.of("{\\sc L{\\'o}pez}", "O. Kopp. López."), + Arguments.of("\\textsc{Outer \\textsc{inner} text}", "O. Kopp. Outer inner text."), // Parser edge cases that should still keep the surrounding small-caps span intact - Arguments.of("\\textsc {L{\\'o}pez}", "O.\u00a0Kopp. López."), - Arguments.of("\\textsc{A\\{B\\}C}", "O.\u00a0Kopp. ABC."), - Arguments.of("{\\scshape Lopez}", "O.\u00a0Kopp. Lopez."), + Arguments.of("\\textsc {L{\\'o}pez}", "O. Kopp. López."), + Arguments.of("\\textsc{A\\{B\\}C}", "O. Kopp. ABC."), + Arguments.of("{\\scshape Lopez}", "O. Kopp. Lopez."), // Malformed input should fall back to the existing preview pipeline without failing - Arguments.of("\\textsc{L{\\'o}pez", "O.\u00a0Kopp. López."), - Arguments.of("{\\sc L{\\'o}pez", "O.\u00a0Kopp. lópez."), - - // Existing superscript and subscript rendering should remain unchanged - Arguments.of("Proceedings of the 9\\textsuperscript{th} symposium", "O.\u00a0Kopp. Proceedings of the 9ᵗʰ symposium."), - Arguments.of("{H\\textsubscript{2}O}", "O.\u00a0Kopp. H₂O.") + Arguments.of("\\textsc{L{\\'o}pez", "O. Kopp. López."), + Arguments.of("{\\sc L{\\'o}pez", "O. Kopp. lópez."), + + // Emphasis becomes HTML, not Unicode mathematical italic or bold letters + // abbrv lowercases titles, as BibTeX does inside {\\em ...} + Arguments.of("On {\\em Drosophila} genetics", "O. Kopp. On drosophila genetics."), + Arguments.of("On \\emph{Drosophila} genetics", "O. Kopp. On Drosophila genetics."), + Arguments.of("On \\textit{Drosophila} genetics", "O. Kopp. On Drosophila genetics."), + Arguments.of("On \\textbf{Drosophila} genetics", "O. Kopp. On Drosophila genetics."), + + // Superscript and subscript become HTML + Arguments.of("Proceedings of the 9\\textsuperscript{th} symposium", "O. Kopp. Proceedings of the 9th symposium."), + Arguments.of("{H\\textsubscript{2}O}", "O. Kopp. H2O.") ); } + @Test + void journalEmphasizedByBstIsRenderedItalic() throws URISyntaxException { + BstPreviewLayout bstPreviewLayout = new BstPreviewLayout(Path.of(BstPreviewLayoutTest.class.getResource("abbrv.bst").toURI())); + BibEntry entry = new BibEntry(StandardEntryType.Article) + .withField(StandardField.AUTHOR, "Karen A. Cooper") + .withField(StandardField.TITLE, "Cocoa and health: a decade of research") + .withField(StandardField.JOURNAL, "British Journal of Nutrition") + .withField(StandardField.YEAR, "2007"); + String preview = bstPreviewLayout.generatePreview(entry, bibDatabaseContext); + assertEquals("K. A. Cooper. Cocoa and health: a decade of research. British Journal of Nutrition, 2007.", preview); + } + @Test void unresolvableBracedMathIsKept() throws URISyntaxException { BstPreviewLayout bstPreviewLayout = new BstPreviewLayout(Path.of(BstPreviewLayoutTest.class.getResource("abbrv.bst").toURI())); BibEntry entry = new BibEntry().withField(StandardField.AUTHOR, "Oliver Kopp") .withField(StandardField.TITLE, "{{$\\notacommand$}} Modulator"); String preview = bstPreviewLayout.generatePreview(entry, bibDatabaseContext); - assertEquals("O.\u00a0Kopp. modulator.", preview); + assertEquals("O. Kopp. notacommand modulator.", preview); } @Test @@ -129,6 +148,55 @@ void unparsableBstShowsPreviewError(@TempDir Path tempDir) throws IOException { assertEquals("Error parsing file '" + invalidBst.toString() + "'", preview); } +<<<<<<< HEAD +======= + @Test + void generatePreviewResolvesXDataFields() throws URISyntaxException { + BstPreviewLayout bstPreviewLayout = new BstPreviewLayout(Path.of(BstPreviewLayoutTest.class.getResource("abbrv.bst").toURI())); + BibEntry xdata = new BibEntry(new UnknownEntryType("xdata")) + .withCitationKey("CAT") + .withField(StandardField.PUBLISHER, "Addison-Wesley") + .withField(StandardField.ADDRESS, "Reading, MA") + .withField(StandardField.SERIES, "Computers and Typesetting"); + BibEntry book = new BibEntry(StandardEntryType.Book) + .withCitationKey("Knuth") + .withField(StandardField.TITLE, "The {\\TeX} Book") + .withField(StandardField.YEAR, "1984") + .withField(StandardField.AUTHOR, "Knuth, Donald E.") + .withField(StandardField.XDATA, "CAT") + .withField(StandardField.NUMBER, "1"); + BibDatabaseContext context = new BibDatabaseContext(new BibDatabase(List.of(xdata, book))); + + String preview = bstPreviewLayout.generatePreview(book, context); + + assertEquals("D. E. Knuth. The TeX Book. Number 1 in Computers and Typesetting. Addison-Wesley, Reading, MA, 1984.", preview); + } + + @Test + void generatePreviewIgnoresLibraryPreambleWhenResolvingXDataFields() throws URISyntaxException { + BstPreviewLayout bstPreviewLayout = new BstPreviewLayout(Path.of(BstPreviewLayoutTest.class.getResource("abbrv.bst").toURI())); + BibEntry xdata = new BibEntry(new UnknownEntryType("xdata")) + .withCitationKey("CAT") + .withField(StandardField.PUBLISHER, "Addison-Wesley") + .withField(StandardField.ADDRESS, "Reading, MA") + .withField(StandardField.SERIES, "Computers and Typesetting"); + BibEntry book = new BibEntry(StandardEntryType.Book) + .withCitationKey("Knuth") + .withField(StandardField.TITLE, "The {\\TeX} Book") + .withField(StandardField.YEAR, "1984") + .withField(StandardField.AUTHOR, "Knuth, Donald E.") + .withField(StandardField.XDATA, "CAT") + .withField(StandardField.NUMBER, "1"); + BibDatabase database = new BibDatabase(List.of(xdata, book)); + database.setPreamble("Plain text preamble"); + BibDatabaseContext context = new BibDatabaseContext(database); + + String preview = bstPreviewLayout.generatePreview(book, context); + + assertEquals("D. E. Knuth. The TeX Book. Number 1 in Computers and Typesetting. Addison-Wesley, Reading, MA, 1984.", preview); + } + +>>>>>>> 201bff7020 (Render BST preview italics and bold as text, not math letters (#17902)) private static BibEntry getSliceTheoremPaper() { return new BibEntry(StandardEntryType.Article) .withField(StandardField.AUTHOR, "Tobias Diez") diff --git a/jablib/src/test/java/org/jabref/logic/layout/format/HTMLCharsTest.java b/jablib/src/test/java/org/jabref/logic/layout/format/HTMLCharsTest.java index 98ec3c0e61cb..b45dfa2d51e3 100644 --- a/jablib/src/test/java/org/jabref/logic/layout/format/HTMLCharsTest.java +++ b/jablib/src/test/java/org/jabref/logic/layout/format/HTMLCharsTest.java @@ -72,7 +72,17 @@ private static Stream provideLaTeXHighlightingFormattingData() { Arguments.of("hallo", "\\underline{hallo}"), Arguments.of("hallo", "\\sout{hallo}"), - Arguments.of("hallo", "\\texttt{hallo}") + Arguments.of("hallo", "\\texttt{hallo}"), + + Arguments.of("hallo", "\\textsc{hallo}"), + Arguments.of("hallo", "{\\sc hallo}"), + Arguments.of("hallo", "{\\scshape hallo}"), + Arguments.of("hallo", "\\textsc {hallo}"), + + Arguments.of("López", "\\emph{L{\\'o}pez}"), + Arguments.of("The TeX Book", "{\\em The {\\TeX} Book}"), + Arguments.of("a b c", "\\textbf{a \\textit{b} c}"), + Arguments.of("hallo", "\\textsc\\hallo") ); } diff --git a/jablib/src/test/java/org/jabref/logic/util/strings/StringUtilTest.java b/jablib/src/test/java/org/jabref/logic/util/strings/StringUtilTest.java index 8f2aadedcbe5..18d02911b10e 100644 --- a/jablib/src/test/java/org/jabref/logic/util/strings/StringUtilTest.java +++ b/jablib/src/test/java/org/jabref/logic/util/strings/StringUtilTest.java @@ -188,6 +188,8 @@ void stripBrackets(String expected, String input) { '', 'A closed mouth catches no }flies}', 25, false # Get the word from the end of the sentence bite, 'Barking dogs seldom bite', 19, true + # Escaped braces do not end the group + 'A\\{B\\}C', '{A\\{B\\}C} D', 0, true """) void getPart(String expected, String input, int startIndex, boolean forward) { assertEquals(expected, StringUtil.getPart(input, startIndex, forward));