Skip to content

Commit 5afb621

Browse files
committed
Empty list items can no longer interrupt a paragraph (spec 0.26, #55)
1 parent af25da2 commit 5afb621

1 file changed

Lines changed: 13 additions & 8 deletions

File tree

commonmark/src/main/java/org/commonmark/internal/ListBlockParser.java

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -57,12 +57,6 @@ private static ListData parseListMarker(CharSequence line, final int markerIndex
5757
}
5858

5959
ListBlock listBlock = createListBlock(matcher);
60-
if (inParagraph && listBlock instanceof OrderedList) {
61-
// Ordered lists can only interrupt paragraphs with a start number of 1.
62-
if (((OrderedList) listBlock).getStartNumber() != 1) {
63-
return null;
64-
}
65-
}
6660

6761
int markerLength = matcher.end() - matcher.start();
6862
int indexAfterMarker = markerIndex + markerLength;
@@ -85,6 +79,17 @@ private static ListData parseListMarker(CharSequence line, final int markerIndex
8579
}
8680
}
8781

82+
if (inParagraph) {
83+
// If the list item is ordered, the start number must be 1 to interrupt a paragraph.
84+
if (listBlock instanceof OrderedList && ((OrderedList) listBlock).getStartNumber() != 1) {
85+
return null;
86+
}
87+
// Empty list item can not interrupt a paragraph.
88+
if (!hasContent) {
89+
return null;
90+
}
91+
}
92+
8893
if (!hasContent || (contentColumn - columnAfterMarker) > Parsing.CODE_BLOCK_INDENT) {
8994
// If this line is blank or has a code block, default to 1 space after marker
9095
contentColumn = columnAfterMarker + 1;
@@ -138,8 +143,8 @@ public BlockStart tryStart(ParserState state, MatchedBlockParser matchedBlockPar
138143
}
139144
int markerIndex = state.getNextNonSpaceIndex();
140145
int markerColumn = state.getColumn() + state.getIndent();
141-
ListData listData = parseListMarker(state.getLine(), markerIndex, markerColumn,
142-
matchedBlockParser.getParagraphContent() != null);
146+
boolean inParagraph = matchedBlockParser.getParagraphContent() != null;
147+
ListData listData = parseListMarker(state.getLine(), markerIndex, markerColumn, inParagraph);
143148
if (listData == null) {
144149
return BlockStart.none();
145150
}

0 commit comments

Comments
 (0)