Skip to content

Commit

Permalink
[DOXIA-753] Do not end lists with a blank line
Browse files Browse the repository at this point in the history
Otherwise every nested list is implicitly "loose" instead of "tight"
  • Loading branch information
kwin committed Oct 22, 2024
1 parent a299dec commit f0a40a2
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -448,7 +448,7 @@ public void sectionTitle_(int level) {

@Override
public void list_() {
ensureBlankLine();
ensureBeginningOfLine();
}

@Override
Expand Down Expand Up @@ -476,7 +476,7 @@ public void numberedList(int numbering, SinkEventAttributes attributes) {

@Override
public void numberedList_() {
writeUnescaped(EOL);
ensureBeginningOfLine();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,12 +157,12 @@ protected String getFooterBlock() {

/** {@inheritDoc} */
protected String getListBlock(String item) {
return MarkdownMarkup.LIST_UNORDERED_ITEM_START_MARKUP + getEscapedText(item) + EOL + EOL;
return MarkdownMarkup.LIST_UNORDERED_ITEM_START_MARKUP + getEscapedText(item) + EOL;
}

/** {@inheritDoc} */
protected String getNumberedListBlock(String item) {
return MarkdownMarkup.LIST_ORDERED_ITEM_START_MARKUP + getEscapedText(item) + EOL + EOL;
return MarkdownMarkup.LIST_ORDERED_ITEM_START_MARKUP + getEscapedText(item) + EOL;
}

/** {@inheritDoc} */
Expand Down Expand Up @@ -486,7 +486,6 @@ public void testNestedListWithBlockquotesParagraphsAndCode() {

String expected = "- item1" + EOL
+ " - item1a" + EOL
+ EOL
+ "- " + EOL + EOL
+ " > blockquote" + EOL + EOL
+ "- item3" + EOL
Expand Down Expand Up @@ -548,7 +547,7 @@ public void testMultilineVerbatimSourceAfterListItem() {

String expected = "- Before" + EOL + EOL + MarkdownMarkup.INDENT + MarkdownMarkup.VERBATIM_START_MARKUP + EOL
+ MarkdownMarkup.INDENT + "codeline1" + EOL + MarkdownMarkup.INDENT + "codeline2" + EOL
+ MarkdownMarkup.INDENT + MarkdownMarkup.VERBATIM_END_MARKUP + EOL + EOL + "After" + EOL + EOL;
+ MarkdownMarkup.INDENT + MarkdownMarkup.VERBATIM_END_MARKUP + EOL + EOL + "After" + EOL;
assertEquals(expected, getSinkContent(), "Wrong verbatim!");
}

Expand All @@ -570,4 +569,36 @@ public void testDefinitionListWithInlineStyles() {
+ "<dd>prefix <code>code</code><em>suffix&lt;a&gt;test&lt;/a&gt;</em></dd>" + EOL + "</dl>" + EOL + EOL;
assertEquals(expected, getSinkContent(), "Wrong heading after inline element!");
}

@Test
public void testNestedListBeingTight() {
try (final Sink sink = getSink()) {
sink.list();
sink.listItem();
sink.text("item 1");
sink.listItem_();
sink.listItem();
sink.text("item 2");
sink.list();
sink.listItem();
sink.text("item 2 a");
sink.listItem_();
sink.listItem();
sink.text("item 2 b");
sink.listItem_();
sink.list_();
sink.listItem_();
sink.list_();
sink.listItem();
sink.text("item 3");
sink.listItem_();
sink.list();
}
String expected = "- item 1" + EOL
+ "- item 2" + EOL
+ " - item 2 a" + EOL
+ " - item 2 b" + EOL
+ "- item 3" + EOL;
assertEquals(expected, getSinkContent());
}
}

0 comments on commit f0a40a2

Please sign in to comment.