-
Notifications
You must be signed in to change notification settings - Fork 208
ENH: Add CSS classes for backrefs #581
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
Conversation
Codecov Report
@@ Coverage Diff @@
## master #581 +/- ##
==========================================
+ Coverage 97.53% 97.55% +0.02%
==========================================
Files 29 29
Lines 2962 2988 +26
==========================================
+ Hits 2889 2915 +26
Misses 73 73
Continue to review full report at Codecov.
|
Updated documentation that hopefully reflects the code changes: This is ready for review/merge from my end @lucyleeow |
I'm on vacation atm but I will get onto this soon! |
Tweaked slightly, including changing a very long |
|
||
a[class^="sphx-glr-backref-module-"] { | ||
text-decoration: none; | ||
background-color: rgba(0, 0, 0, 0) !important; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why !important
here? It makes it hard to override by package developers, I think (I'm no CSS expert so please bear with me :-))
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is just for building the SG docs, it shouldn't affect actual use of SG by downstream libraries. The one CSS change that will is in gallery.css
Added some reminders for myself to fix things :) In the meantime @emmanuelle feel free to try this branch to see if it fixes your problems. In the next week I'll try it with MNE to try stylizing links slightly differently as well. |
(ping @glemaitre this should fix the pandas df appearance problem we talked about) |
Travis failures are due to matplotlib/matplotlib#16083 and can be ignored |
I've implemented a proof of concept PR for MNE showing how things can be styled differently, with links from MNE being semibold and other links from other modules being standard link weight: /* Sphinx-gallery backreference links */
a[class^="sphx-glr-backref-module-mne"] {
font-weight: 600;
} @lucyleeow feel free to merge if you're happy, and agree that this should fix (or allow setting custom CSS to fix) problems seen by @glemaitre and @emmanuelle |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, though I am no CSS expert. Just the little question.
I'm not sure if this closes #544 though - it only allows you to control the CSS of the backreferences right? You won't be able to alter the CSS of html captured (from code blocks)?
for level in remainder[1:].split('.'): | ||
obj = getattr(obj, level) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Might be missing something but why is a for loop needed here? Won't obj
always be the attribute of the last split level
, when you get out of the for loop?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In some case doing c = a.b.c
did not work but doing c = a.b; c = c.c
did. Can't remember offhand if it had to do with module nesting or class attributes or what...
...but fortunately I was so annoyed by it that I wrote a test to capture it, and if I just do obj = getattr(obj, remainder[1:])
(what I think you're suggesting) I get:
AttributeError: module 'numpy' has no attribute 'random.RandomState'
Which is probably because of this somewhat unexpected behavior:
>>> import numpy
>>> getattr(numpy, 'random.RandomState')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/larsoner/python/numpy/numpy/__init__.py", line 219, in __getattr__
raise AttributeError("module {!r} has no attribute "
AttributeError: module 'numpy' has no attribute 'random.RandomState'
>>> numpy.random.RandomState
<class 'numpy.random.mtrand.RandomState'>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think I am suggesting obj = remainder[1:].split('.')[-1]
- the last loop of the for loop?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Then obj
is a str
rather than the actual object
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Whoops
level = remainder[1:].split('.')[-1]
obj = getattr(obj, level)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to other A93C s. Learn more.
Ah I get it now. Sorry and thanks for explaining.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No problem, hopefully it's not too bad to add your changes from #584 on top once this is in -- then it will be my turn to be confused during review :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@larsoner FYI in case you are interested: https://stackoverflow.com/questions/11975781/why-does-getattr-not-support-consecutive-attribute-retrievals
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Apparently you are allowed to have .
in attribute names!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I hope never to encounter such code :)
I mean the output - can you change what the output looks like - e.g. of |
Adds classes for
sphx-glr-backref-*
(see updated configuration page) and sets the default CSS to:Closes #580