Skip to content

Commit 275998e

Browse files
author
Torsten Krause
committed
Fixed error when processing adjacent empty emphasises
1 parent a8621c9 commit 275998e

File tree

2 files changed

+43
-4
lines changed

2 files changed

+43
-4
lines changed

module/handler/text-commonmark/src/main/java/io/markdom/handler/text/commonmark/ContentBuffer.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -196,9 +196,11 @@ private void moveLineBreakInFrontOfBeginnings() {
196196
}
197197

198198
private void unprepareLine() {
199-
if (!pendingLineBreak) {
200-
pendingLineBreak = true;
201-
unbeginNewLine();
199+
if (!isEmpty()) {
200+
if (!pendingLineBreak) {
201+
pendingLineBreak = true;
202+
unbeginNewLine();
203+
}
202204
}
203205
}
204206

module/handler/text-commonmark/src/test/java/io/markdom/handler/commonmark/CommonmarkTextMarkdomHandlerContentTests.java

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1798,6 +1798,24 @@ public void nestedEmphasisesWithoutConttentsInbetweenLinebreaksAreRemoved2() {
17981798

17991799
}
18001800

1801+
@Test
1802+
public void nestedEmphasisesWithoutAnyContentAreRemoved() {
1803+
1804+
// @formatter:off
1805+
paragraph.addContents(
1806+
factory.emphasisContent(
1807+
MarkdomEmphasisLevel.LEVEL_2,
1808+
factory.emphasisContent(
1809+
MarkdomEmphasisLevel.LEVEL_1
1810+
)
1811+
)
1812+
);
1813+
// @formatter:on
1814+
1815+
assertEquals("\\", getCommonmarkText());
1816+
1817+
}
1818+
18011819
@Test
18021820
public void adjacentEmphasisesAreRemovedSurroundedByMultipleStars() {
18031821

@@ -1890,6 +1908,24 @@ public void adjacentEmphasisesAreRemovedSurroundedByMultipleUnderscoresAndStars(
18901908

18911909
}
18921910

1911+
@Test
1912+
public void adjacentEmphasisesWithoutAnyContentAreRemoved() {
1913+
1914+
// @formatter:off
1915+
paragraph.addContents(
1916+
factory.emphasisContent(
1917+
MarkdomEmphasisLevel.LEVEL_2
1918+
),
1919+
factory.emphasisContent(
1920+
MarkdomEmphasisLevel.LEVEL_1
1921+
)
1922+
);
1923+
// @formatter:on
1924+
1925+
assertEquals("\\", getCommonmarkText());
1926+
1927+
}
1928+
18931929
@Test
18941930
public void singleEmphasisesCanBeInterruptedBySoftLineBreaks() {
18951931

@@ -3056,7 +3092,8 @@ public void singleTextContentThatContainsOnlyThreeOrMoreDashesWithOptionalSpaces
30563092

30573093
@ParameterizedTest
30583094
@ValueSource(strings = { "___", "__ __", "_ _ _", "__ __ __" })
3059-
public void singleTextContentThatContainsOnlyThreeOrMoreUnderscoredWithOptionalSpacesIsEscapedTheBeginning(String underscores) {
3095+
public void singleTextContentThatContainsOnlyThreeOrMoreUnderscoredWithOptionalSpacesIsEscapedTheBeginning(
3096+
String underscores) {
30603097

30613098
// @formatter:off
30623099
paragraph.addContents(

0 commit comments

Comments
 (0)