Skip to content

Conversation

@Bibo-Joshi
Copy link
Contributor

@Bibo-Joshi Bibo-Joshi commented Dec 1, 2021

Hi. After #12, I finally got around to play around with this more and would like to propose two additions:

This part was moved to #14
  1. Better support for nitpicky mode. Currently, :paramref: is resolved without checking if the resulting target exists. By checking against the index created in build_index within lookup_params and returning None if the target doesn't exist, we give sphinx a chance to emit a warning about an unresolved reference, if needed. This minimal-effort approach has two downsides: First, the _sphinx_paramlinks_ prefix is still included in the warning, e.g.

    path\to\python-telegram-bot\telegram\ext\_basepersistence.py:docstring of telegram.ext._basepersistence.BasePersistence.insert_bot:1: WARNING: py:paramref reference target not found: _sphinx_paramlinks_bot

    Secondly, I don't know how well it plays with the nitpick_ignore and nitpick_ignore_regex settings (I guess the prefix could mean trouble here)
    Alternatively, one could add an event handler for the warn-missing-reference event, but the built-in logic of that is actually somewhat elaborate. At least for me, adapting this for sphinx-paramlinks is not worth the effort - I can live with the prefix and so far I don't use the nitpick_ignore settings


  1. Add options to a) turn off the insertion of the link symbol after the parameter name and b) to make the parameter name itself the link. This idea came up at Docs improvements: referencing python-telegram-bot/python-telegram-bot#2798 (comment). The reason is that with the link symbol only showing on hover, there is a large gap between parameter name & description/type. But showing the link symbol just all the time also doesn't look too good:

    image

    that built is currently available here

If you like the general idea of those changes, I'm happy to discuss the implementation :) I can also split this PR up into two for the two different parts if you like that better.

Cheers!

@zzzeek
Copy link
Contributor

zzzeek commented Dec 1, 2021

so there is "show the link symbol all the time", which ...is just a CSS change, right? I dont personally like it that way, so I wouldn't want that CSS change by default, if that's how this works. we could perhaps render a style class that refers to the two different approaches in the CSS.

then as far as "make the name the link", how does that look? IIUC the build you have above is showing the link symbol still.

I'm all for options here, so I think this should be just one configuruation parameter link_style:

  • symbol_hover - show a symbol on hover, the default
  • symbol_always - show a symbol always
  • paramname - make the paramname the link
  • None - don't self-link the parameters

what do you think?

two PRs is easier for me to understand the two if it's not too much trouble

@Bibo-Joshi
Copy link
Contributor Author

Bibo-Joshi commented Dec 1, 2021

so there is "show the link symbol all the time", which ...is just a CSS change, right? I dont personally like it that way, so I wouldn't want that CSS change by default, if that's how this works. we could perhaps render a style class that refers to the two different approaches in the CSS.

then as far as "make the name the link", how does that look? IIUC the build you have above is showing the link symbol still.

Sorry, I should have been more explicit. "show the symbol all the time" was my first approach before we had the idea of making the parameter name a link. I did this by manually overriding the CSS file and this PR doesn't change the hover behavior.

The change in the css file just makes sure that if the parameter name is a link, it doesn't change the text color. So except for the cursor changing on hovering the name, there is no visual indication for the link. I can try and provide you with an example built.

I'm all for options here, so I think this should be just one configuruation parameter link_style:

  • symbol_hover - show a symbol on hover, the default
  • symbol_always - show a symbol always
  • paramname - make the paramname the link
  • None - don't self-link the parameters

what do you think?

One parameter with different settings sounds reasonable 👍 I'll see if I implement the symbol_always option, as that's not a priority for me

two PRs is easier for me to understand the two if it's not too much trouble

Sure, no worries. Will do that later tonight or in the next few days

@Bibo-Joshi
Copy link
Contributor Author

I've moved the nitpicky thing to #14 and implemented the new config scheme. I've also added some info to the docs about that and how to customize styling.
I've decided not to provide an option for hovering/not hovering the link symbol, since that can be customized by overriding the CSS file.

Also, here is a small preview of how it reneders with paramlinks_style = 'param_name_and_link_symbol'. The only change I made in the CSS here is to change li > a.paramlink { to a.paramlink { because for some reason the hovering doesn't work otherwise (probably a theme issue …)

@zzzeek
Copy link
Contributor

zzzeek commented Dec 2, 2021

OK, ill try to have alook soon.

@Bibo-Joshi Bibo-Joshi changed the title Better support for nitpicky mode and new settings for links New settings for links Dec 2, 2021
@zzzeek
Copy link
Contributor

zzzeek commented Dec 8, 2021

you're still in my inbox. just have a lot coming in

Copy link
Contributor

@zzzeek zzzeek left a comment

Choose a reason for hiding this comment

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

happy new year! im back. i think this is good, tiny stylistic changes that are not super essential but here we are

@Bibo-Joshi
Copy link
Contributor Author

Happy new year to you as well :) The requested changes make sense, so I pushed some along with adapting the readme.

@zzzeek
Copy link
Contributor

zzzeek commented Jan 1, 2022

OK this looks great. going to squash the commits and reformat README and that's it!

@zzzeek
Copy link
Contributor

zzzeek commented Jan 2, 2022

OK I'm going to force-push some changes here, but also param_name_and_link_symbol is nesting the tags, will see if I can fix that

<a class="paramname reference internal" href="#sqlalchemy.types.TypeDecorator.process_bind_param.params.dialect"><strong>dialect</strong><a class="paramlink headerlink reference internal" href="#sqlalchemy.types.TypeDecorator.process_bind_param.params.dialect">¶</a></a>

@zzzeek
Copy link
Contributor

zzzeek commented Jan 2, 2022

there is also a really weird and subtle recursion overflow happening here if i touch that code at all, i have a vague idea why it's happening but it's really weird. fixing that

Pull requset courtesy Hinrich Mahler.

Closes: sqlalchemyorg#13
@zzzeek
Copy link
Contributor

zzzeek commented Jan 2, 2022

OK note major differences, if you can re-review please:

  • new names for the parameter and the values
  • use of Enum
  • link_style is avaiable from .app, no need for the global
  • changing the reference logic a bit to avoid nested tags, recursion overflow

I've tested a bunch and it seems to work for me, if you can give it a run to make sure it's doing what you need as well, thanks.

@Bibo-Joshi
Copy link
Contributor Author

Bibo-Joshi commented Jan 2, 2022

Ah, I hadn't noticed the nesting thing. Thanks for finding! Enum & .app make it cleaner as well 👍
Tested & works fine for my setup. I added a more user friendly error message in case of a wrong config value and adapted the readme a bit, since plain rst doesn't know the .. versionchanged:: directive of sphinx - GitHub displays it as

image

One comment on HyperlinkStyle.BOTH: If a third option is added at some point, 'both' doesn't really make sense anymore, that's why I had chosen LINK_SYMBOL_AND_NAME. Anyway, that's probably rather unlikely …

PS: I usually just "sqash & merge" PRs, which leaves the history in tact during the review process :)

@zzzeek
Copy link
Contributor

zzzeek commented Jan 2, 2022

yes i thought if another symbol is added, BOTH starts to not make sense. will think about another name, but it starts to look like maybe the parameter should itself be a tuple, but that's probably not worth it. "versionadded" was totally a mistake as I thought i was in sphinx :) .

@zzzeek
Copy link
Contributor

zzzeek commented Jan 2, 2022

OK please give my latest commit one more review and we can merge.

@Bibo-Joshi
Copy link
Contributor Author

LGTM 👌

@zzzeek zzzeek closed this in acedb03 Jan 2, 2022
@zzzeek
Copy link
Contributor

zzzeek commented Jan 2, 2022

great! thanks. will try to look at your next one in the coming week.

@Bibo-Joshi Bibo-Joshi deleted the enhancements branch January 2, 2022 20:02
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