Skip to content

Prevent Markdown Javadoc tokens from emitting uncommented newlines. - #1544

Merged
copybara-service[bot] merged 1 commit into
masterfrom
test_1028886732
Nov 26, 2026
Merged

copybara-service[bot] merged 1 commit into
masterfrom
test_1028886732

Conversation

@copybara-service

Copy link
Copy Markdown

Prevent Markdown Javadoc tokens from emitting uncommented newlines.

When formatting /// Markdown Javadoc comments, tokens containing raw newlines (from LIST_ITEM_START_PATTERN matching -\n, multi-line or unclosed HTML tags like </pre\n\n<p>, FOOTER_TAG_PATTERN matching @param\n<T>, and multi-line MOE strip comments) were written verbatim, emitting bare uncommented lines that corrupted Java code or split comments.

Restrict LIST_ITEM_START_PATTERN to horizontal whitespace ([ \t]?), bound visitListItemOrBlockQuote to endPosition(node), and normalize internal whitespace in FooterJavadocTagStart and MOE strip comment tokens. Avoid consuming trailing horizontal whitespace together with \n outside formatting-preserving contexts in Markdown mode so NEWLINE_PATTERN does not skip close tokens at the end of a line (MARKDOWN_HARD_LINE_BREAK_PATTERN is left unchanged). In JavadocWriter, write continuation lines of any multi-line token with the comment prefix (reusing this path for writeHtmlComment), defer the space after Markdown list markers while suppressing pending newlines/blank lines for same-line content, set atStartOfLine in writeBeginJavadoc for Markdown comments, and request a newline while clearing atStartOfLine when closing Markdown lists and block quotes.

When formatting `///` Markdown Javadoc comments, tokens containing raw newlines (from `LIST_ITEM_START_PATTERN` matching `-\n`, multi-line or unclosed HTML tags like `</pre\n\n<p>`, `FOOTER_TAG_PATTERN` matching `@param\n<T>`, and multi-line MOE strip comments) were written verbatim, emitting bare uncommented lines that corrupted Java code or split comments.

Restrict `LIST_ITEM_START_PATTERN` to horizontal whitespace (`[ \t]?`), bound `visitListItemOrBlockQuote` to `endPosition(node)`, and normalize internal whitespace in `FooterJavadocTagStart` and MOE strip comment tokens. Avoid consuming trailing horizontal whitespace together with `\n` outside formatting-preserving contexts in Markdown mode so `NEWLINE_PATTERN` does not skip close tokens at the end of a line (`MARKDOWN_HARD_LINE_BREAK_PATTERN` is left unchanged). In `JavadocWriter`, write continuation lines of any multi-line token with the comment prefix (reusing this path for `writeHtmlComment`), defer the space after Markdown list markers while suppressing pending newlines/blank lines for same-line content, set `atStartOfLine` in `writeBeginJavadoc` for Markdown comments, and request a newline while clearing `atStartOfLine` when closing Markdown lists and block quotes.

PiperOrigin-RevId: 1030639801
@copybara-service
copybara-service Bot merged commit c8cd285 into master Nov 26, 2026
12 checks passed
@copybara-service
copybara-service Bot deleted the test_1028886732 branch November 26, 2026 13:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant