8000 ENH: Add CSS classes for backrefs by larsoner · Pull Request #581 · sphinx-gallery/sphinx-gallery · GitHub
[go: up one dir, main page]

Skip to content

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

Merged
merged 5 commits into from
Jan 6, 2020
Merged

Conversation

larsoner
Copy link
Contributor
@larsoner larsoner commented Dec 28, 2019

Adds classes for sphx-glr-backref-* (see updated configuration page) and sets the default CSS to:

a.sphx-glr-backref-instance {
  text-decoration: none;
}

Closes #580

@codecov-io
Copy link
codecov-io commented Dec 28, 2019

Codecov Report

Merging #581 into master will increase coverage by 0.02%.
The diff coverage is 100%.

Impacted file tree graph

@@            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
Impacted Files Coverage Δ
sphinx_gallery/docs_resolv.py 89.27% <100%> (+0.58%) ⬆️
sphinx_gallery/tests/test_full.py 100% <100%> (ø) ⬆️
sphinx_gallery/tests/test_backreferences.py 100% <100%> (ø) ⬆️
sphinx_gallery/backreferences.py 97.12% <100%> (+0.15%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 5f4dec8...72aa36c. Read the comment docs.

@larsoner
Copy link
Contributor Author

Updated documentation that hopefully reflects the code changes:

https://1184-25860190-gh.circle-artifacts.com/0/rtd_html/configuration.html#stylizing-the-code-links-using-css

This is ready for review/merge from my end @lucyleeow

@lucyleeow
Copy link
Contributor

I'm on vacation atm but I will get onto this soon!

@larsoner
Copy link
Contributor Author

Tweaked slightly, including changing a very long .. note:: to a new section, which makes it a bit more readable:

https://1185-25860190-gh.circle-artifacts.com/0/rtd_html/configuration.html#stylizing-the-code-links-using-css


a[class^="sphx-glr-backref-module-"] {
text-decoration: none;
background-color: rgba(0, 0, 0, 0) !important;
Copy link
Contributor

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 :-))

Copy link
Contributor Author

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

@larsoner
Copy link
Contributor Author

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.

@lucyleeow
Copy link
Contributor

(ping @glemaitre this should fix the pandas df appearance problem we talked about)

@larsoner
Copy link
Contributor Author
larsoner commented Jan 5, 2020

Travis failures are due to matplotlib/matplotlib#16083 and can be ignored

@larsoner
Copy link
Contributor Author
larsoner commented Jan 5, 2020

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;
}

https://17384-1301584-gh.circle-artifacts.com/0/dev/auto_tutorials/intro/plot_10_overview.html#sphx-glr-auto-tutorials-intro-plot-10-overview-py

@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

Copy link
Contributor
@lucyleeow lucyleeow left a 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)?

Comment on lines +74 to +75
for level in remainder[1:].split('.'):
obj = getattr(obj, level)
Copy link
Contributor

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?

Copy link
Contributor Author

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'>

Copy link
Contributor

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?

Copy link
Contributor Author

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

Copy link
Contributor

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)

Copy link
Contributor

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.

Copy link
Contributor Author

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 :)

Copy link
Contributor

Choose a reason for hiding this comment

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

Copy link
Contributor

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!

Copy link
Contributor Author

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 :)

@larsoner
Copy link
Contributor Author
larsoner commented Jan 6, 2020

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)?

It is altering the CSS of the code blocks themselves. For example:

Screenshot from 2020-01-06 12-02-21

@lucyleeow
Copy link
Contributor
lucyleeow commented Jan 6, 2020

I mean the output - can you change what the output looks like - e.g. of _repr_html_ (raw html) captured in output blocks

@larsoner
Copy link
Contributor Author
larsoner commented Jan 6, 2020

Ahh right I meant to ref #580 not #544 -- fixed

@lucyleeow
Copy link
Contributor

Oh sorry, my fault! You referred to #528 initially and I edited to #544 because I assumed that is what you meant!!! My bad!

@lucyleeow lucyleeow merged commit 775ca82 into sphinx-gallery:master Jan 6, 2020
@larsoner larsoner deleted the classes branch January 6, 2020 17:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

greedy backreferences
4 participants
0