Prevent leading blank lines in list items when formatting block tags.#1410
Closed
copybara-service[bot] wants to merge 1 commit into
Closed
Prevent leading blank lines in list items when formatting block tags.#1410copybara-service[bot] wants to merge 1 commit into
copybara-service[bot] wants to merge 1 commit into
Conversation
0e485a8 to
7c4bbd5
Compare
* Update `writeTableOpen`, `writePreOpen`, `writeBlockquoteOpenOrClose`, `writeMarkdownTable`, and `writeMarkdownFencedCodeBlock` in `JavadocWriter` to uniformly call `requestBlankLineForBlockTag()` (`if (wroteAnythingSignificant && !atStartOfLine)`), ensuring that block elements opening immediately at the start of a list item (`<li>` or `- `) do not get preceded by an unnecessary blank line. * Update `writeListOpen` and `writeListItemOpen` in `JavadocWriter` to check `if (wroteAnythingSignificant)` before requesting a newline or blank line, and set `atStartOfLine = true` in `writeBeginJavadoc` for `///` comments. This prevents `google-java-format` from prepending a leading blank line (`///\n`) when a list is the very first element in a Javadoc comment. * Fix a `NullPointerException` in `MarkdownPositions.visitListItem` when a Markdown list item has a non-`Paragraph` first child (such as `- <table>...</table>`), safely falling through when `firstChild` is not an instance of `Paragraph`. * Update unit tests in `JavadocFormattingTest` (`tableInHtmlListItem`, `tableInMarkdownListItem`, `tableInsideMarkdownListItemAfterText`, and `markdownLooseLists`) to verify correct formatting without unwanted blank lines or `NullPointerException` crashes. PiperOrigin-RevId: 945755137
7c4bbd5 to
b7de448
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Prevent leading blank lines in list items when formatting block tags.
writeTableOpen,writePreOpen,writeBlockquoteOpenOrClose,writeMarkdownTable, andwriteMarkdownFencedCodeBlockinJavadocWriterto uniformly callrequestBlankLineForBlockTag()(if (wroteAnythingSignificant && !atStartOfLine)), ensuring that block elements opening immediately at the start of a list item (<li>or-) do not get preceded by an unnecessary blank line.writeListOpenandwriteListItemOpeninJavadocWriterto checkif (wroteAnythingSignificant)before requesting a newline or blank line, and setatStartOfLine = trueinwriteBeginJavadocfor///comments. This preventsgoogle-java-formatfrom prepending a leading blank line (///\n) when a list is the very first element in a Javadoc comment.NullPointerExceptioninMarkdownPositions.visitListItemwhen a Markdown list item has a non-Paragraphfirst child (such as- <table>...</table>), safely falling through whenfirstChildis not an instance ofParagraph.JavadocFormattingTest(tableInHtmlListItem,tableInMarkdownListItem,tableInsideMarkdownListItemAfterText, andmarkdownLooseLists) to verify correct formatting without unwanted blank lines orNullPointerExceptioncrashes.