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
Original file line number Diff line number Diff line change
Expand Up @@ -203,20 +203,40 @@ 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 `<li>`
// from 4+ spaces to 2 spaces means `<li>` 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();

requestNewline();
}

void writeListClose(ListCloseTag token) {
if (!classicJavadoc && !token.value().isEmpty()) {
requestNewline();
writeToken(token);
requestNewline();
return;
}
if (classicJavadoc) {
requestNewline();
}
Expand All @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2636,13 +2636,13 @@ class Test {}
""";
// requestBlankLine() in writeTableOpen() inserts a blank line after <li> before <table> 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 =
"""
/// <ul>
/// <li>
/// <li>
///
/// <table>
/// <table>
/// <tr><td>Foo</td></tr>
/// </table>
///
Expand Down Expand Up @@ -2671,21 +2671,20 @@ void m() {}
void n() {}
}
""";
// Baseline: HTML `<li>` pushes 4-space indent, turning `<p>` into an indented code block.
String expected =
"""
class T {
/// Updates:
/// <li>A single [Foo]
/// <li>One or more [Bar]s
///
/// <p>See [Baz] for more details.
/// <p>See [Baz] for more details.
void m() {}

/// Updates:
/// <li>First item
///
/// <p>Following paragraph without blank line.
/// <p>Following paragraph without blank line.
void n() {}
}
""";
Expand Down Expand Up @@ -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 `<ul>`/`</ul>` onto adjacent lines.
String expected =
"""
class T {
/// Intro: <ul>
/// <li class="x">First item
/// Intro:
/// <ul>
/// <li class="x">First item
///
/// <p>Second paragraph.
/// <li>Second item </ul> Following text.
/// <p>Second paragraph.
/// <li>Second item
/// </ul>
/// Following text.
///
/// <ul>
/// text without li </ul>
/// text without li
/// </ul>
///
/// <dl>
/// <dt>Term
/// <dd>Definition
/// <dt>Term
/// <dd>Definition
///
/// <p>More details. </dl>
/// <p>More details.
/// </dl>
void m() {}
}
""";
Expand Down Expand Up @@ -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:
/// <li><ol>
/// <li>First
/// <li>First
///
/// <p>Details for first.
/// <li>Second
/// <p>Details for first.
/// <li>Second
///
/// <p>Details for second. </ol>
/// <p>Details for second.
/// </ol>
void m() {}

/// Works only if:
/// <li><ul>
/// First condition <ul>
/// Second condition
/// First condition
/// <ul>
/// Second condition
///
/// <p>Features:
/// <li><ul>
/// See [Foo].
/// <p>Features:
/// <li><ul>
/// See [Foo].
void n() {}
}
""";
Expand All @@ -2816,20 +2818,69 @@ class T {
/// <li>one
/// <p>more
/// </ul>
void m(int x) {}
/// @param y values: <ul>
/// <li>one [String]
/// <li>two {@link Object}
/// </ul>
void m(int x, int y) {}
}
""";
// Baseline: `@param` + `<ul>` + `<li>` pushes 8-space indentation.
// Note: flattening `<ul>`/`<li>` to the 2-space footer continuation indent prevents indented
// code blocks after blank lines (`<p>more`), at the trade-off that `<li>one [String]` starts
// a Type 6 HTML block (where `[String]` is literal, while `{@link Object}` still resolves).
String expected =
"""
class T {
/// Summary.
///
/// @param x values: <ul>
/// <li>one
/// @param x values:
/// <ul>
/// <li>one
///
/// <p>more </ul>
void m(int x) {}
/// <p>more
/// </ul>
/// @param y values:
/// <ul>
/// <li>one [String]
/// <li>two {@link Object}
/// </ul>
void m(int x, int y) {}
}
""";
doFormatTest(input, expected);
}

@Test
public void markdownInlineHtmlListAndFollowingMarkdownLink() {
assume().that(MARKDOWN_JAVADOC_SUPPORTED).isTrue();
String input =
"""
class T {
/// Intro <ul><li>a</ul> trailing words.
void m() {}

/// Updates:
/// <li>First item
///
/// See [String] for more details.
void n() {}
}
""";
String expected =
"""
class T {
/// Intro
/// <ul>
/// <li>a
/// </ul>
/// trailing words.
void m() {}

/// Updates:
/// <li>First item
///
/// See [String] for more details.
void n() {}
}
""";
doFormatTest(input, expected);
Expand Down Expand Up @@ -2864,31 +2915,7 @@ void m() {}
void n() {}
}
""";
// Baseline: HTML list tags interfere with Markdown list indentation and turn following blocks
// into indented code blocks.
String expected =
"""
class T {
/// - Outer item: <ul>
/// <li>HTML item </ul>
/// <li>Bare HTML li </ul>
///
/// Following paragraph in outer item.
///
/// > <ul>
/// > <li>Quoted HTML item
/// >
/// > <p>Quoted paragraph </ul>
void m() {}

/// <li>Bare HTML li
///
/// - Markdown item 1
/// - Markdown item 2
void n() {}
}
""";
doFormatTest(input, expected);
doFormatTest(input, input);
}

@Test
Expand Down
Loading