Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move whitespace formatting to generic XHTML format #95

Merged

Conversation

haszi
Copy link
Contributor

@haszi haszi commented Feb 13, 2024

Move whitespace formatting from Render.php to the generic XHTML format and add the option for each format to control their own whitespace formatting. Add a test to ensure XHTML formatting is correct.

The current way of handling this in Render.php not only applies to all formats (XHTML, PDF, Manpage, etc.), it also does not allow formats to control the output of significant whitespace. With this PR, formats can implement the format_whitespace() method and override default whitespace output.

This PR also moves the existing conditional whitespace formatting to the generic XHTML format as I assumed this was specifically added for rendering the documentation in XHTML format.

Note:
this also corrects a minor inconvenience in formatting where whitespace after the very first <methodsynopsis>, <constructorsynopsis> or <destructorsynopsis> is printed. This was due to a non-existent $elementStack[$currentDepth] in in_array($elementStack[$currentDepth] ?? "", ["methodname", "methodparam", "type", "void"], true).

Because of this fix, existing tests will need a minor update if this PR is merged which I will take care of.

@haszi
Copy link
Contributor Author

haszi commented Feb 13, 2024

A note relating to the TODO in the generic XHTML format:

whitespace in <type> elements is not removed because XMLReader returns it as part of the <type>'s text. I'm planning on removing the lines that don't work (right under the TODO) and if there are no objections, add trim the text in the method handling the <type> elements' text.

Copy link
Member

@Girgias Girgias left a comment

Choose a reason for hiding this comment

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

Thank you this looks good :)

tests/xhtml/data/whitespace_formatting_001.xml Outdated Show resolved Hide resolved
tests/xhtml/whitespace_formatting_001.phpt Outdated Show resolved Hide resolved
@haszi haszi requested a review from Girgias February 13, 2024 17:48
@Girgias Girgias merged commit 27e3bc3 into php:master Feb 13, 2024
4 checks passed
@haszi haszi deleted the Move-whitespace-formatting-to-generic-XHTML-formatter branch February 14, 2024 09:16
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.

2 participants