-
Notifications
You must be signed in to change notification settings - Fork 50
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
Reformat methodsynopsis whitespaces #38
Conversation
Yes, indeed, that are the whitespace nodes which are rendered verbatim: Lines 161 to 169 in 785fec0
Just skipping this would yield the desired results for the methodsynopses, but would likely break other stuff. :( |
@cmb69 Do you see any chance to make this work somehow? If there is not any, I'll close this PR. |
phpdotnet/phd/Render.php | 1 +
1 file changed, 1 insertion(+)
diff --git a/phpdotnet/phd/Render.php b/phpdotnet/phd/Render.php
index a3d3413..df01e6a 100644
--- a/phpdotnet/phd/Render.php
+++ b/phpdotnet/phd/Render.php
@@ -161,6 +161,7 @@ class Render extends ObjectStorage
case \XMLReader::WHITESPACE: /* {{{ */
case \XMLReader::SIGNIFICANT_WHITESPACE:
/* WS is always WS */
+ if ($this->STACK[$r->depth - 1] === 'methodsynopsis') break;
$retval = $r->value;
foreach($this as $format) {
$format->appendData($retval); on top of this might already solve the whitespace issue for functions; methods would need additional care (because of the modifiers). Anyhow, it might be a good idea to add more tests (and to fix the test suite if necessary). |
Thank you for the help! I'll come back to this task as soon as I have some spare time for it.
is it the same thing what was proposed here: php/php-src#6367 (comment) ? When would you break the lines? Always? Or just for functions with a too long parameter list? |
For simplicity, it might make sense to have each parameter on its own line. |
I forgot how to properly generate the docs locally, but I used
(I'm not sure why the type precedes the method name) |
@cmb69 I didn't manage to understand how to run the test suite (or even how to properly generate the docs). Could you give me some pointers? Is the current format what you imagined? |
I never ran the test suite, so wouldn't know how to do it. How to build and render the docs is described in the tutorial on http://doc.php.net/, but apparently this site is down now. :( Anyhow, the output looks good to me, but the return types need to go at the end. This is accomplished by putting the output into |
Now, I used the following command to build the docs from doc-en (I found it in my zsh history):
I think last time I didn't specify the format (probably neither the other arguments...), and it might be the reason why the return types were misplaced as well as the pages missed any formatting. So now, I have pretty decent looking function/method/class reference pages. However, the new formatting looks a bit strange in case of class reference pages - at least at the first sight. |
I am a huge fan of the whitespace removal around parentheses, commas, etc.. Big, big thumbs up for that. I am not a fan of making the prototype, for every single function/method that has parameters, span across multiple lines. This can make class synopses almost unusable, IMO. For example, here is my screen's worth of DateTime methods: I don't know about anyone else, but my brain can't make quick sense of that. At the opposite end of the scale, small function/method prototypes also look awful, IMO. Note, my key issue is spreading the prototype across multiple lines where you wouldn't normally do that in your own code style. For prototypes where it would be clearer to span multiple lines (e.g. many parameters, or lots of parameter type declarations particularly with union types), I'm all for doing that: increasing the readability of the manual pages just as you would for actual code. If, for simplicity's sake, the choice is either to spread every single prototype (with any parameters) across multiple lines deliberately, or to not do that; personally, I would recommend staying with the latter. |
I'm not in favor of not splitting long argument lists, e.g. https://www.php.net/manual/en/function.snmp3-set.php is awful in my opinion; also see the SimpleXMLElement class synopsis above. Maybe we could only split long argument lists? |
Splitting makes long signatures much more readable but the inverse is also true. Most code formatting tools only split long lines, maybe 80-100 characters.
I'd check the whole signature. If the function name is very long, it might still make sense to split a short argument list. I'm not familiar with this code so I'm not sure how simple that is to implement. |
I'm afraid almost nobody is familiar with this code. |
I'm not keen on counting characters... However, I would be ok to either:
What do you think? |
Yes, we need to keep implementation complexity low. If splitting by number of arguments helps with that, this is preferable. Otherwise I'd prefer to split by number of characters. Addionally, we may consider to add |
I've just rebased to current master |
@salathe, would the overhauled PR resolve your concerns? |
Thanks. I think "reasonably good" is good enough for now. 👍
See above. 😸
There are other things missing (like |
Thanks! :)
Yeah, I'd like to propose fixes for these after this PR is merged. :) |
This PR removes some unnecessary whitespace characters from the methodsynopses.
So
becomes
Unfortunately, a few unnecessary whitespace characters still remain, and I couldn't yet find out how to remove them as well :/ For me, it looks like some whitespace characters from the XML get rendered directly to the HTML (e.g. around the
,
). Is it possible?