Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions src/main/java/org/jabref/htmltonode/rich/RichTextRenderer.java
Original file line number Diff line number Diff line change
Expand Up @@ -166,8 +166,14 @@ private void paragraph(List<Inline> inlines, double scale, int minWeight, double
}
appendRun(text, effective);
}
case Inline.LineBreak ignored ->
startParagraph(0);
case Inline.LineBreak ignored -> {
// A break renders as a blank line even with no content of its own, so a second
// consecutive break (e.g. `<br><br>`) still triggers a fresh model.nl() in the next
// startParagraph() call instead of being swallowed by separateParagraph()'s
// occupied-check (mirrors the empty-line handling for preserved "\n\n" in appendRun).
startParagraph(0);
paragraphOccupied = true;
}
case Inline.Image image -> {
if (RenderSupport.createImageView(image, options, baseSize) != null) {
model.addNodeSegment(() -> RenderSupport.createImageView(image, options, baseSize));
Expand Down
10 changes: 10 additions & 0 deletions src/test/java/org/jabref/htmltonode/RichTextRendererTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,16 @@ void lineBreaksSplitParagraphs() {
assertEquals("b", model.getPlainText(1));
}

@Test
void consecutiveLineBreaksKeepTheBlankLineBetweenThem() {
StyledTextModel model = model("a<br><br>b");

assertEquals(3, model.size());
assertEquals("a", model.getPlainText(0));
assertEquals("", model.getPlainText(1));
assertEquals("b", model.getPlainText(2));
}

@Test
void preservedNewlinesInPreSplitParagraphs() {
StyledTextModel model = model("<pre>x = 1\ny = 2</pre>");
Expand Down