-
Notifications
You must be signed in to change notification settings - Fork 809
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
[toc2] make toc entries collapsible #1031
Conversation
also remove redundant css for hovering over items so they don't flicker :/
also: * rework toc link highlighting to work with new-form ids * remove collapsible_headings' now-redundant toc click handler, since toc's own handler selects the cell, which is enough to get ch to reveal it
* add collapse controls after writing toc cell html, so they don't show up as useless in html saveas page * explicitly write spacing for number labels, so the html doesn't need css file to add it as a :before pseudoelement * write toc cell heading margin as a per-element css rule, so html doesn't need css file * fix removal of execute highlight class
@jcb91 I spent a part of the afternoon yesterday investigating how I could do that, but this is now done and very well done!
Again. Wow! |
Sounds nice, enjoy! 😄
Yes, I saw references to that in comments, and as far as I can tell, it's still an issue when using jquery's string selectors: Jquery will interpret a
Ah, right, I hadn't thought of that! Yes, in that case, I think we should leave them in the css for backward compatibility. They don't need to be in the template though, as they won't be needed for newly-exported versions.
Yes, that sounds like a good plan, to have a setting like "sync toc items' collapsed state with collapsible headings nbextension" in toc2 config. We don't really need a setting for each extension, as then we run into priority problems 😉 I think the simplest way to get it working would be to have collapsible_headings fire an event when collapsing/uncollapsing a heading, something like |
we pass new events, either through Jupyter's events object, or in a non-live notebook, through an ojbect at `window.events`, which we create if necessary.
Having thought about this more, I think I see what you were getting at, in that you might want the sync in one direction but not the other. I've added separate options for each direction. Unfortunately, non-live notebooks don't have the jupyter events module defined, so I've had to add a shim whereby we create an equivalent object at |
@jcb91 All that seems really great! What a nice idea to have define your own |
I have finally reviewed and tested the PR. I just propose some small adaptations:
Really nice @jcb91!. Thanks |
The former is needed for collapse_by_id to be defined in callback_toc2_collapsible_headings, the latter just for consistency/neatness
…tem, not from notebook metadata
Haha great, thanks!
Ok, all of these make sense to me. I've rebased the changes to simplify the now rather-tangled commit history, and made a couple of extra very small changes as part of the rebase:
but then I think we should be good to merge, assuming I haven't broken anything with my rebase 😉 |
Tested this morning. It is great! I would have a further modification. I realized yesterday that the toc links, though working in Chrome/Chromium did not work anymore in Firefox (Linux/last version). This may be related to the point mentioned in some docs :
eg here or here. A possible solution to simulate the click using the mouse event is mentioned here. Since all the links are on the same page, I suggest to the scrollIntoView method to scroll the element with the given id into view.
I have tested with this modification and it works at least on Chrome/Firefox/Gnome web browser, both in live notebook and after html export (just edited the html to load the current I have also updated the README. |
|
Good catch, good fix! 👍
👍 😄
Another good catch, good fix! 👍
This, I'm less certain about, though likely it's partly just that I haven't understood. I've added a few comments with questions for clarifications
Haha, we're so close 😄! |
@@ -69,6 +72,7 @@ padding-left: 20px; | |||
|
|||
.toc ul.toc-item { | |||
list-style-type: none; | |||
display: block; |
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 redundant, display is block anyway
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.
ok
|
||
|
||
|
||
#toc-wrapper ul li span:hover { |
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, this isn't needed li span
is sufficient & more efficient, since every li
is in a ul
anyway, while the >
prevents nested child spans from being selected (fewer css redraws, more efficient, hopefully)
background-color: #DAA520; | ||
} | ||
|
||
#toc-level0 a { | ||
/*color: #333333;*/ /* now specified in js */ | ||
text-decoration: none; | ||
} | ||
#navigate_menu li > span:hover {background-color: #f1f1f1} | ||
#navigate_menu ul li span:hover {background-color: #f1f1f1} |
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.
see above
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.
ok corrected
.toc-item li li li > span { padding-left:2em } | ||
.toc-item li li li li > span { padding-left:3em } | ||
.toc-item li li li li li > span { padding-left:4em } | ||
.toc-item li li li li li li > span { padding-left:5em } |
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 are we adding extra padding, and why separately for various nesting levels?! If desired (is the regular indenting not sufficient?), could this not be handled by adjusting the ul
's padding?
Also note that this has set margin & padding for all li
elements to 0 - I guess that was unintentional, and should have been .toc-item li
?
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.
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.
thanks!
#navigate_menu-level0 {padding-left: 10px;} | ||
#navigate_menu-level0 ul {padding-left: 10px;} | ||
#navigate_menu-level0 {padding-left: 0px;} | ||
#navigate_menu-level0 ul {padding-left: 0px;} |
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'm not familiar with any of the navigate_menu stuff (haven't had it enabled), but now that I've tried it, it seems a bit weird, and is coming out resizable. Perhaps it deserves altering to make it look like all the other notebook menus?
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.
although, any such modification should probably go into another, separate PR 😅
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.
Yes!
I think this is almost ready now. All local tests work fine. Let us merge and see if everything is also ok on the live version. Thanks to @jcb91 for his great work. |
Fixes #1024
Note, in order to make this work neatly, I have also:
.
,[
, etc. In addition, this prevents potential confusion between e.g. sections 1.13 and 11.3, which would previously have both have been translated to the id as113
.sourcedata-toc-modified-id
. Use the toc.js-specified click handler to ensure that we actually select the modified idI'm reasonably confident this all works ok from my limited testing, but I'd definitely welcome others' testing, and in particular, anything @jfbercher might have to say :)