From a733cbcbb1c4660193d921146be46bc6c3f3d9ab Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89amonn=20McManus?= Date: Thu, 9 Apr 2026 09:47:13 -0700 Subject: [PATCH] Add a giant TODO comment listing the remaining Markdown cases we don't handle well. Also add test methods that currently illustrate the incorrect handling. As we fix each issue, we can delete it from the comment and ensure that its test method produces the expected result. PiperOrigin-RevId: 897161602 --- .../java/JavadocFormattingTest.java | 186 +++++++++++++++++- 1 file changed, 185 insertions(+), 1 deletion(-) 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 f9a399b53..72f1d784f 100644 --- a/core/src/test/java/com/google/googlejavaformat/java/JavadocFormattingTest.java +++ b/core/src/test/java/com/google/googlejavaformat/java/JavadocFormattingTest.java @@ -1775,6 +1775,187 @@ class Test {} doFormatTest(input, expected); } + @Test + public void markdownBackslashes() { + assume().that(MARKDOWN_JAVADOC_SUPPORTED).isTrue(); + String input = + """ + /// \\
is not a break. + /// \\* is not an HTML entity. + /// foo\\ + /// bar + class Test {} + """; + // TODO: the
should not cause a line break, and the end-of-line backslash should. + // I don't think anything changes if we do or do not respect the \& backslash. + String expected = + """ + /// \\
+ /// is not a break. \\* is not an HTML entity. foo\\ bar + class Test {} + """; + doFormatTest(input, expected); + } + + @Test + public void markdownThematicBreaks() { + assume().that(MARKDOWN_JAVADOC_SUPPORTED).isTrue(); + String input = + """ + /// foo + /// *** + /// bar + class Test {} + """; + // TODO: the line break before `***` should be preserved. + // It's OK to introduce a blank line before `bar` since it is a new paragraph. + String expected = + """ + /// foo *** + /// + /// bar + class Test {} + """; + doFormatTest(input, expected); + } + + @Test + public void markdownSetextHeadings() { + assume().that(MARKDOWN_JAVADOC_SUPPORTED).isTrue(); + String input = + """ + /// Heading + /// ======= + /// Phoebe B. Peabody-Beebe + /// + /// Subheading + /// ---------- + class Test {} + """; + // TODO: the line breaks before the lines of repeated characters should be preserved. + // Or, we could rewrite this style of heading as `# Heading`. + String expected = + """ + /// Heading ======= + /// + /// Phoebe B. Peabody-Beebe + /// + /// Subheading ---------- + class Test {} + """; + doFormatTest(input, expected); + } + + @Test + public void markdownIndentedCodeBlocks() { + assume().that(MARKDOWN_JAVADOC_SUPPORTED).isTrue(); + String input = + """ + /// code block + /// is indented + class Test {} + """; + // TODO: the evil indented code block should be preserved. + String expected = + """ + /// code block is indented + class Test {} + """; + doFormatTest(input, expected); + } + + @Test + public void markdownLinkReferenceDefinitions() { + assume().that(MARKDOWN_JAVADOC_SUPPORTED).isTrue(); + String input = + """ + /// [foo] + /// [foo]: /url "title" + class Test {} + """; + String expected = + """ + /// [foo] [foo]: /url "title" + class Test {} + """; + doFormatTest(input, expected); + } + + @Test + public void markdownLooseLists() { + assume().that(MARKDOWN_JAVADOC_SUPPORTED).isTrue(); + String input = + """ + /// - item 1 + /// + /// - item 2 + class Test {} + """; + // TODO: the line break between items should be preserved, and there should not be a blank line + // before the list. + String expected = + """ + /// + /// - item 1 + /// - item 2 + class Test {} + """; + doFormatTest(input, expected); + } + + @Test + public void markdownBlockQuotes() { + assume().that(MARKDOWN_JAVADOC_SUPPORTED).isTrue(); + String input = + """ + /// > foo + /// > bar + class Test {} + """; + // TODO: the block quote should be preserved, and ideally bar would be joined to foo. + String expected = + """ + /// > + /// + /// foo > bar + class Test {} + """; + doFormatTest(input, expected); + } + + @Test + public void markdownCodeSpans() { + assume().that(MARKDOWN_JAVADOC_SUPPORTED).isTrue(); + String input = + """ + /// `