Skip to content

Fix #807: helpmojo flattens nested lists in javadoc - #1259

Open
arturobernalg wants to merge 1 commit into
apache:masterfrom
arturobernalg:fix/807-nested-list-helpmojo
Open

arturobernalg wants to merge 1 commit into
apache:masterfrom
arturobernalg:fix/807-nested-list-helpmojo

Conversation

@arturobernalg

@arturobernalg arturobernalg commented Oct 29, 2026 •

Copy link
Copy Markdown
Member

Fixes #807.

HtmlToPlainTextConverter.FormattingVisitor appended "\n * " for every <li> regardless of nesting depth, and its cleanup step collated any run of spaces -- including indentation meant to show nesting -- down to one. A nested <ul>/<li> structure in a Mojo's or parameter's javadoc always rendered as one flat bullet level in the plain-text output used by mvn <plugin>:help, losing the nesting the javadoc author intended.

FormattingVisitor now tracks <ul>/<ol> nesting depth and indents each <li> accordingly, using a placeholder character for the indentation spaces so the existing space-collation cleanup doesn't erase it -- the placeholder is only expanded to real spaces as the last step of toString(). Added tests for a single-level list (unchanged output), a nested list, and a doubly-nested list. Full module suite, checkstyle and spotless pass locally.

To make clear that you license your contribution under the Apache License Version 2.0, January 2004, check one of the following:

  • I hereby declare this contribution to be licensed under the Apache License Version 2.0, January 2004
  • I hereby declare that I have filed an Apache Individual Contributor License Agreement.

HtmlToPlainTextConverter.FormattingVisitor appended "\n * " for every
<li> regardless of nesting depth, and its cleanup step collated any
run of spaces -- including indentation meant to show nesting -- down
to one. A nested <ul>/<li> structure in a Mojo's or parameter's
javadoc always rendered as one flat bullet level in the plain-text
output used by mvn <plugin>:help, losing the nesting the javadoc
author intended.

FormattingVisitor now tracks <ul>/<ol> nesting depth and indents each
<li> accordingly, using a placeholder character for the indentation
spaces so the existing space-collation cleanup doesn't erase it --
the placeholder is only expanded to real spaces as the last step of
toString(). Added tests for a single-level list (unchanged output), a
nested list, and a doubly-nested list.
@slachiewicz slachiewicz added the bug Something isn't working label Oct 29, 2026

@gnodet-bot gnodet-bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Clean, minimal fix for a real bug — LGTM.

What the fix does: FormattingVisitor now tracks <ul>/<ol> nesting depth and indents each <li> with (depth - 1) spaces. A U+0001 placeholder is used for indentation spaces so the existing space-collation cleanup in toString() doesn't erase them; the placeholder is only expanded to real spaces as the last step.

Correctness verified:

  • The toString() replacement ordering is essential and correct: replaceAll(" +", " ") collapses real spaces → replace("\n ", "\n") strips leading spaces after newlines → replace(INDENT_MARKER, " ") expands markers last. Any other order would corrupt the output.
  • U+0001 is a C0 control character that cannot appear in Java identifiers or normal javadoc — collision risk is effectively zero.
  • Top-level list output (depth=1) is identical to the old code: old code appended "\n * " then toString() stripped the leading space via replace("\n ", "\n") → "\n* "; new code appends "\n* " directly.
  • Math.max(0, listDepth - 1) on decrement is reasonable defensive coding for malformed HTML.

This review was generated by an AI agent, Hermès on behalf of @gnodet.

@kwin

kwin commented Nov 13, 2026

Copy link
Copy Markdown
Member

@arturobernalg Thanks for the fix. LGTM, however can you edit this PRs description? The formatting looks a bit off.

@arturobernalg

Copy link
Copy Markdown
Member Author

@kwin Fixed — the HTML tags weren't escaped. Should render correctly now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[MPLUGIN-505] helpmojo: does not respect nested list in javadoc

4 participants