diff --git a/core/src/main/java/com/google/googlejavaformat/java/javadoc/JavadocLexer.java b/core/src/main/java/com/google/googlejavaformat/java/javadoc/JavadocLexer.java
index ab89e5d1c..5609e7c8e 100644
--- a/core/src/main/java/com/google/googlejavaformat/java/javadoc/JavadocLexer.java
+++ b/core/src/main/java/com/google/googlejavaformat/java/javadoc/JavadocLexer.java
@@ -640,14 +640,20 @@ private static boolean hasMultipleNewlines(String s) {
}
/*
- * This also eats any trailing whitespace. We would be smart enough to ignore that, anyway --
- * except in the case of
/
, inside which we otherwise leave whitespace intact.
+ * This also eats any trailing whitespace before the newline. We would be smart enough to ignore
+ * that, anyway -- except in the case of /
, inside which we otherwise leave whitespace
+ * intact.
*
* We'd remove the trailing whitespace later on (in JavaCommentsHelper.rewrite), but I feel safer
* stripping it now: It otherwise might confuse our line-length count, which we use for wrapping.
*/
private static final Pattern CLASSIC_NEWLINE_PATTERN = compile("[ \t]*\n[ \t]*[*]?[ \t]?");
- private static final Pattern MARKDOWN_NEWLINE_PATTERN = compile("[ \t]*\n[ \t]*");
+ /*
+ * With Traditional comments, the initial space and leading `*` characters (if any) are still
+ * present in the input, but with Markdown comments, the leading `///` characters and shared
+ * initial whitespace have been removed at the point where this pattern is applied.
+ */
+ private static final Pattern MARKDOWN_NEWLINE_PATTERN = compile("[ \t]*\n");
// We ensure elsewhere that we match this only at the beginning of a line.
// Only match tags that start with a lowercase letter, to avoid false matches on unescaped
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 3601d4b01..2d7d9326d 100644
--- a/core/src/test/java/com/google/googlejavaformat/java/JavadocFormattingTest.java
+++ b/core/src/test/java/com/google/googlejavaformat/java/JavadocFormattingTest.java
@@ -2066,14 +2066,13 @@ public void markdownBlankLinesAroundSnippetAndNoMangling() {
/// hello again
class Test {}\
""";
- // TODO(b/530531076): Restore the indentation of `private String s;`
String expected =
"""
/// hello world
///
/// {@snippet :
/// public class Foo {
- /// private String s;
+ /// private String s;
/// }
/// }
///