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 53f6f1a29..e27f39b3e 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 @@ -260,7 +260,9 @@ void writeParagraphOpen(Token token) { } void writeBlockquoteOpenOrClose(Token token) { - requestBlankLine(); + if (wroteAnythingSignificant) { + requestBlankLine(); + } writeToken(token); @@ -268,7 +270,9 @@ void writeBlockquoteOpenOrClose(Token token) { } void writePreOpen(PreOpenTag token) { - requestBlankLine(); + if (wroteAnythingSignificant) { + requestBlankLine(); + } writeToken(token); } @@ -288,7 +292,9 @@ void writeCodeClose(CodeCloseTag token) { } void writeTableOpen(TableOpenTag token) { - requestBlankLine(); + if (wroteAnythingSignificant) { + requestBlankLine(); + } writeToken(token); } 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 ac4cfc088..7083a878d 100644 --- a/core/src/test/java/com/google/googlejavaformat/java/JavadocFormattingTest.java +++ b/core/src/test/java/com/google/googlejavaformat/java/JavadocFormattingTest.java @@ -2160,14 +2160,100 @@ public void tableAtStartOfComment() { /// class Test {} """; - // TODO(kak): we shouldn't spew out these 2 leading blank lines + String expected = input; + doFormatTest(input, expected); + } + + @Test + public void blockquoteAtStartOfComment() { + assume().that(MARKDOWN_JAVADOC_SUPPORTED).isTrue(); + String input = + """ + ///
+ /// line 1 + /// line 2 + ///
+ class Test {} + """; String expected = """ + ///
/// + /// line 1 line 2 /// + ///
+ class Test {} + """; + doFormatTest(input, expected); + } + + @Test + public void preAtStartOfComment() { + assume().that(MARKDOWN_JAVADOC_SUPPORTED).isTrue(); + String input = + """ + ///
+        /// line 1
+        /// line 2
+        /// 
+ class Test {} + """; + String expected = input; + doFormatTest(input, expected); + } + + @Test + public void tableInHtmlListItem() { + assume().that(MARKDOWN_JAVADOC_SUPPORTED).isTrue(); + String input = + """ + /// + class Test {} + """; + // requestBlankLine() in writeTableOpen() inserts a blank line after
  • before when + // inside a list item. + String expected = + """ + ///
    + /// + ///
    Foo
    + /// + /// + class Test {} + """; + doFormatTest(input, expected); + } + + @Test + public void tableInsideMarkdownListItemAfterText() { + assume().that(MARKDOWN_JAVADOC_SUPPORTED).isTrue(); + String input = + """ + /// - item text + /// + /// + ///
    Foo
    + class Test {} + """; + // requestBlankLine() in writeTableOpen() inserts a blank line after item text before + // inside the list item. + String expected = + """ + /// + /// - item text + /// + ///
    + /// + ///
    Foo
    class Test {} """; doFormatTest(input, expected);