-
-
Notifications
You must be signed in to change notification settings - Fork 196
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
put source code below docstring #343
Comments
I think no location is inherently better, I personally prefer to have it right at the top. There's a practical argument that putting it after the docstring is more tricky as it would require quite a bit of additional whitespace to make sure it doesn't overlay the docstring. You can of course change it in a custom template by swapping the order in the |
Thanks. I don't really know much about these templates. You mean changing from this
to this?
|
Yes, exactly. You can find some more resources on how templates work at |
Great. Or perhaps pdoc has a more sophisticated way of overcoming this, like using templates stored in a non-standard path? |
You can overwrite only specific parts of a template with a local file. Pleae read the links I posted. :) |
Yes sorry ... I had seen that and was just about to edit my comment when you answered. 1. When you say "overwrite specific parts of a template" (using the I understand I must rewrite full "named" sections, like ... So if I just want to add a line somewhere within the body block, I need to locate the "subblock" where it is ... {% if module.members %}
<h2>API Documentation</h2>
<h4>{{ module.fullname }}</h4> {# <------------- MY ADDITION #}
{{ nav_members(module.members.values()) }}
{% endif %} I guess the 2) Does that mean we cannot add sections which do not exist using the For example, this {% block search_js %}
{% if search %}
{% include "search.html.jinja2" %}
{% endif %}
{% endblock %} I wouldn't be able to add something like that using just a But I should instead put a FULL custom index.html.jinja2 in my Thanks ! |
|
Awesome. Thank you so much. I have already moved my docstrings above the source code section and all looks great.
I don't see anything odd. So I'd rather do this instead of what I said above? {{ docstring(doc) }} {# I already moved this up #}
{% if doc.type != "variable" %}
<br> {# I should also add this just to be safe? #}
{{ view_source(doc) }}
{% endif %} |
Yes, a long last line is why it's not enabled in pdoc by default. |
I see. I just added a long non-spaced line with Chrome DevTools and it actually gets too close, but they don't overlay. That looks more than OK for my needs. BTW, I think there are CSS ways of avoiding the long line overflow the right div border (so it splits and continues in the next line). Thanks a lot anyway. |
I'm sure you can tweak line wrapping with CSS, but I don't have the capacity or interest to look into that. Sorry. |
OK. But when I mentioned that in #328 I was not meaning long non-spaced lines. In current pdoc documentation view-source, there are many examples where source code is right-cutted even for spaced lines. Might this be an issue in my browser alone? Nevermind. I'll see if I can solve this experimenting css try-error with template_directory. I have a question though. This template example seems the proper way to do it. The comment above block says: ... but then inside block there is an additional piece of code: " What's that |
Please check out the Jinja2 documentation for templating. :) |
I did check this, but I give up. I don't get the idea of what is safe or unsafe in this context. Anyway, I'll cross my fingers and let it be " Regarding my css experiments:
.codehilite pre {white-space: break-spaces;} But I changed my mind after seeing the effect: at least for Python code, it's a bad idea.
.codehilite pre { overflow: initial; } Not sure about what I am doing, so this could have some collateral effects. To appreciate its usefulness, you'll have to pdocument a long and wide function (with many too-wide or very-indented lines of code), and see how it looks like with default pdoc css (unreadable right side of text). Anyway, thanks a lot for guiding me to solve my problems. |
pdoc does not escape HTML tags in docstrings, this is expected behavior.
I'm perfectly aware of the current layout. It will stay this way. pdoc displays a bit above 100 characters per line without scrolling. For reference, black has a maximum line length of 88 characters1. It is very easy to scroll horizontally on all modern desktop OS and mobile devices. Yes, this is opinionated, but please accept that I'm not going to discuss it any further. Footnotes |
Problem Description
When browsing documentation, the source code details are hidden and docstring appears in its natural place, right below the function definition ... until you click the "view source" option.
After clicking that option, source code appears between function definition and docstring ... so docstring gets displaced down many lines (as many as the code length).
So all the rich docstring format and all links it might contain disappear from our scope (until we close the source code).
Proposal
In my opinion, it might be much better to keep docstring below function definition, and put source code below docstring.
So we can still see the nice docstring in its original place, and use the links to other functions and modules without having to move down.
Alternatives
Can I configure this using templates?
Anyway, I think the default look would improve with this change.
The text was updated successfully, but these errors were encountered: