diff --git a/core/src/main/java/com/google/googlejavaformat/java/javadoc/JavadocWriter.java b/core/src/main/java/com/google/googlejavaformat/java/javadoc/JavadocWriter.java
index c5d2c83a8..2b18e08ea 100644
--- a/core/src/main/java/com/google/googlejavaformat/java/javadoc/JavadocWriter.java
+++ b/core/src/main/java/com/google/googlejavaformat/java/javadoc/JavadocWriter.java
@@ -203,13 +203,27 @@ void writeSnippetEnd(SnippetEnd token) {
}
void writeListOpen(ListOpenTag token) {
+ if (!classicJavadoc && !token.value().isEmpty()) {
+ // In Markdown Javadoc, HTML list tags do not establish a CommonMark container block, so
+ // pushing indentation can reach 4 spaces after a blank line and create indented code blocks.
+ // Note that inside block tags (where continuation indent is 2 spaces), flattening `
`
+ // from 4+ spaces to 2 spaces means `` starts a standard Type 6 HTML block rather than a
+ // paragraph continuation line, so Markdown `[link]` syntax inside HTML list items renders
+ // literally (consistent with body text and Markdown list items; `{@link ...}` still works).
+ if (!atStartOfLine) {
+ requestNewline();
+ }
+ writeToken(token);
+ requestNewline();
+ return;
+ }
if (classicJavadoc) {
requestBlankLine();
}
writeToken(token);
continuingListItemOfInnermostList = false;
- int indent = token.value().isEmpty() ? 0 : 2; // No indent for Markdown since no explicit open
+ int indent = classicJavadoc ? 2 : 0; // No indent for Markdown since no explicit open
indentStack.push(new ListIndent(indent));
postWriteModifiedContinuingListStack.push();
@@ -217,6 +231,12 @@ void writeListOpen(ListOpenTag token) {
}
void writeListClose(ListCloseTag token) {
+ if (!classicJavadoc && !token.value().isEmpty()) {
+ requestNewline();
+ writeToken(token);
+ requestNewline();
+ return;
+ }
if (classicJavadoc) {
requestNewline();
}
@@ -238,6 +258,11 @@ void writeListItemOpen(ListItemOpenTag token) {
pendingListItemSpace = false;
requestNewline();
+ if (!classicJavadoc && token.value().startsWith("<")) {
+ writeToken(token);
+ return;
+ }
+
if (continuingListItemOfInnermostList) {
// TODO(cpovirk): consider whether we can handle this only with operations on the indent stack
continuingListItemOfInnermostList = false;
diff --git a/core/src/test/java/com/google/googlejavaformat/java/JavadocFormattingTest.java b/core/src/test/java/com/google/googlejavaformat/java/JavadocFormattingTest.java
index 679683f5b..ef5e86ea3 100644
--- a/core/src/test/java/com/google/googlejavaformat/java/JavadocFormattingTest.java
+++ b/core/src/test/java/com/google/googlejavaformat/java/JavadocFormattingTest.java
@@ -2636,13 +2636,13 @@ class Test {}
""";
// requestBlankLine() in writeTableOpen() inserts a blank line after before when
// inside a list item. Also, we might prefer to eliminate the blank lines around the table
- // element and to indent the table contents and close tag at least as far as the open tag.
+ // element.
String expected =
"""
///
- /// -
+ ///
-
///
- ///
+ ///
///
@@ -2671,7 +2671,6 @@ void m() {}
void n() {}
}
""";
- // Baseline: HTML `- ` pushes 4-space indent, turning `
` into an indented code block.
String expected =
"""
class T {
@@ -2679,13 +2678,13 @@ class T {
///
- A single [Foo]
///
- One or more [Bar]s
///
- ///
See [Baz] for more details.
+ ///
See [Baz] for more details.
void m() {}
/// Updates:
///
- First item
///
- ///
Following paragraph without blank line.
+ ///
Following paragraph without blank line.
void n() {}
}
""";
@@ -2720,25 +2719,28 @@ class T {
void m() {}
}
""";
- // Baseline: HTML list tags push 2+4+ spaces of indentation (turning paragraphs into indented
- // code blocks) and join `
` onto adjacent lines.
String expected =
"""
class T {
- /// Intro:
- /// - First item
+ /// Intro:
+ ///
+ /// - First item
///
- ///
Second paragraph.
- ///
- Second item
Following text.
+ /// Second paragraph.
+ ///
- Second item
+ ///
+ /// Following text.
///
///
+ /// text without li
+ ///
///
///
- /// - Term
- ///
- Definition
+ ///
- Term
+ ///
- Definition
///
- ///
More details.
+ /// More details.
+ ///
void m() {}
}
""";
@@ -2774,29 +2776,29 @@ void m() {}
void n() {}
}
""";
- // Baseline: nested HTML lists push deep indentation, turning paragraphs into indented code
- // blocks.
String expected =
"""
class T {
/// Types:
///
- /// - First
+ ///
- First
///
- ///
Details for first.
- ///
- Second
+ ///
Details for first.
+ ///
- Second
///
- ///
Details for second.
+ /// Details for second.
+ ///
void m() {}
/// Works only if:
///
- /// First condition
- /// Second condition
+ /// First condition
+ ///
+ /// Second condition
///
- /// Features:
- ///
- /// See [Foo].
+ /// Features:
+ ///
+ /// See [Foo].
void n() {}
}
""";
@@ -2816,20 +2818,69 @@ class T {
/// - one
///
more
///
- void m(int x) {}
+ /// @param y values:
+ /// - one [String]
+ ///
- two {@link Object}
+ ///
+ void m(int x, int y) {}
}
""";
- // Baseline: `@param` + `` + `- ` pushes 8-space indentation.
+ // Note: flattening `
- ///
- /// Following paragraph in outer item.
- ///
- /// >
- /// > - Quoted HTML item
- /// >
- /// >
Quoted paragraph
- void m() {}
-
- /// - Bare HTML li
- ///
- /// - Markdown item 1
- /// - Markdown item 2
- void n() {}
- }
- """;
- doFormatTest(input, expected);
+ doFormatTest(input, input);
}
@Test