From efeecc572fcc6e061d65986cbbd756d4bae9bb0d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89amonn=20McManus?= Date: Mon, 27 Jul 2026 18:42:24 -0700 Subject: [PATCH] In Markdown Javadoc, indent continuation lines for Javadoc block tags by +2 rather than +4. The reason is that a +4 indentation could be interpreted as a Markdown [indented code block](https://spec.commonmark.org/0.31.2/#indented-code-blocks) in some circumstances. PiperOrigin-RevId: 954951163 --- .../googlejavaformat/java/javadoc/JavadocWriter.java | 2 +- .../googlejavaformat/java/JavadocFormattingTest.java | 8 +++----- 2 files changed, 4 insertions(+), 6 deletions(-) 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 27cc934ea..877335dbb 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 @@ -521,7 +521,7 @@ enum AutoIndent { private int innerIndent() { int innerIndent = continuingListItemStack.total() + continuingListStack.total(); if (continuingFooterTag) { - innerIndent += 4; + innerIndent += classicJavadoc ? 4 : 2; } return innerIndent; } 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 fcb4e7d53..fd0c96b75 100644 --- a/core/src/test/java/com/google/googlejavaformat/java/JavadocFormattingTest.java +++ b/core/src/test/java/com/google/googlejavaformat/java/JavadocFormattingTest.java @@ -1980,17 +1980,15 @@ public void markdownBlockTagContinuationLines() { /// rather than +4. record Test(String foo) {} """; - // TODO(b/537488642): continuation lines should be +2 to avoid the bug here. - // The four-space indentation leads to the second paragraph being interpreted as a code block. String expected = """ /// Something something something. /// /// @param foo a parameter with a long description that will need to be wrapped onto multiple lines, -/// with each line being indented by the default amount for continuation lines in a block tag. +/// with each line being indented by the default amount for continuation lines in a block tag. /// -/// There is even a second paragraph which illustrates why the indentation should be +2 rather -/// than +4. +/// There is even a second paragraph which illustrates why the indentation should be +2 rather +/// than +4. record Test(String foo) {} """;