Skip to content

Commit 9553817

Browse files
authored
Merge pull request #1124 from jcb91/t2_0
[toc2] configurable titles; dialog-alterable metadata settings
2 parents e4c3c76 + 4e5b0e5 commit 9553817

File tree

6 files changed

+394
-394
lines changed

6 files changed

+394
-394
lines changed

src/jupyter_contrib_nbextensions/nbextensions/toc2/README.md

Lines changed: 29 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@
44

55
The toc2 extension enables to collect all running headers and display them in a floating window, as a sidebar or with a navigation menu. The extension is also draggable, resizable, collapsable, dockable and features automatic numerotation with unique links ids, and an optional toc cell. Sections of currently selected/edited or running cells are highlighted in the toc. Some minor diplay tweaks are also available (moving header tile/menus, widening cells); Finally, the toc can preserved when exporting to html.
66

7-
#### First demo: Floating toc window and SideBar, toc auto-update, section numbering
7+
### First demo: Floating toc window and SideBar, toc auto-update, section numbering
88
![](demo.gif)
99

10-
##### Second demo: Save as html with toc / Navigation menu
10+
### Second demo: Save as html with toc / Navigation menu
1111
![](demo2.gif)
1212

1313
### Third demo: Notebook scrolling and Collapsing sections
@@ -33,23 +33,35 @@ The state of these two toggles is memorized and restored on reload.
3333

3434
![](image.png)
3535

36+
3637
## Configuration
37-
The initial configuration can be given using the IPython-contrib nbextensions facility. It includes:
3838

39-
- Display Table of Contents as a sidebar (otherwise as a floating window; default: true)
39+
The initial configuration can be set using the
40+
[jupyter_nbextensions_configurator](https://github.com/Jupyter-contrib/jupyter_nbextensions_configurator)
41+
facility, included with
42+
[jupyter_contrib_nbextnensions](https://github.com/ipython-contrib/jupyter_contrib_nbextensions).
43+
Configurable options include:
44+
45+
- Display Table of Contents as a sidebar (otherwise as a floating window; default: true)
46+
- Title of the sidebar/window (default: `Contents`)
4047
- The maximum depth of headers to display on toc (with a default of 4)
4148
- The state of the toc cell (default: false, ie not present)
49+
- Title of the toc cell sidebar/window (default: `Table of Contents`)
4250
- Add a navigation menu (default: true)
43-
- Widening the display area to fit the browser window (may be useful with sidebar option; default: true)
51+
- Widening the display area to fit the browser window (may be useful with sidebar option; default: true)
4452
- The numbering of headers (true by default)
4553
- Moving header title and menus on the left (default: true)
46-
- Marking toc item of first header displayed on viewport when scrolling the notebook (default: true)
54+
- Marking toc item of first header displayed on viewport when scrolling the notebook (default: true)
4755
- Skipping h1 headers, useful if you want to use h1 as unnumbered notebook title (default: false)
48-
- Customization of highlighting the title of currently selected/running sections.
56+
- Customization of highlighting the title of currently selected/running sections.
4957
- Customization of background, fonts, border and highlighting colors in the toc window and navigation menus (as third demo).
5058
- Collapse/uncollapse ToC2 sections when collapsible_headings is used to collapse/uncollapse notebook sections (default: false).
5159

52-
The differents states and position of the floating window have reasonable defaults and can be modfied per notebook).
60+
Some config settings are stored in notebook metadata, so that they can be
61+
altered per-notebook, as well as setting the default in the configurator.
62+
The differents states and position of the floating window have reasonable
63+
defaults and can be modfied per notebook.
64+
5365

5466
#### Demo with dark theme
5567
![](demo_dark.png)
@@ -121,6 +133,12 @@ This option requires the IPython kernel and is not present with other kernels.
121133
- Support customization of background, fonts, border and highlighting colors in the toc window and navigation menus with PR [#969](https://github.com/ipython-contrib/jupyter_contrib_nbextensions/pull/969)
122134
- @jfbercher, @louisabraham, @jcb91 July 2017. Add support for skipping h1
123135
headings, enabling their use as unnumbered notebook titles
124-
- @jcb91 with minor contributions by @jfbercher. August 2017. Make toc entries collapsible #1031 with optional synchronization with `collapsible_headings` + some small other tweaks.
125-
- @jcb91 August 2017. Use amd structure for toc2.js
126-
- @jfbercher August 2017. Add a mark to the currently displayed section in the table of contents window as user scrolls the notebook, cf #944.
136+
- @jcb91 with minor contributions by @jfbercher. August 2017. Make toc entries collapsible #1031 with optional synchronization with `collapsible_headings` + some small other tweaks.
137+
- @jcb91 August 2017. Use amd structure for toc2.js
138+
- @jfbercher August 2017. Add a mark to the currently displayed section in the table of contents window as user scrolls the notebook, cf #944.
139+
- @jcb91 October 2017,
140+
+ correct toc tree construction
141+
+ simplify toc cell processing
142+
+ constrain draggable toc to the body
143+
+ various bits of cleanup
144+
+ add settings dialog for per-notebook metadata-stored settings

src/jupyter_contrib_nbextensions/nbextensions/toc2/main.css

Lines changed: 58 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
/*extracted from https://gist.github.com/magican/5574556*/
1+
/*
22
3+
originally extracted from https://gist.github.com/magican/5574556
34
4-
/*
5-
Most colors definded here will be used on export, but can be overwritted in
6-
the livenotebook by modyfying notebook.json or selecting a color in the
7-
nbextension-configurator
5+
Most colors defined here are overridden by javascript which adds css based on
6+
values in the server config file notebook.json, which can be edited directly,
7+
or colors can be selected in the nbextensions_configurator
88
*/
99

1010

@@ -55,7 +55,6 @@ padding-left: 20px;
5555
}
5656

5757
.toc {
58-
max-height: 500px;
5958
padding: 0px;
6059
overflow-y: auto;
6160
font-weight: normal;
@@ -64,38 +63,52 @@ padding-left: 20px;
6463
overflow-x: auto;
6564
}
6665

66+
.text_cell .toc {
67+
margin-top: 1em;
68+
}
69+
6770
.toc ul.toc-item {
6871
list-style-type: none;
6972
padding: 0;
7073
margin: 0;
7174
}
7275

73-
.float-wrapper {
76+
#toc-wrapper {
77+
z-index: 90;
7478
position: fixed !important;
75-
top: 120px;
76-
max-width:600px;
77-
right: 20px;
78-
border: thin solid rgba(0, 0, 0, 0.38);
79-
border-radius: 5px;
80-
padding:10px;
79+
display: flex;
80+
flex-direction: column;
81+
overflow: hidden;
82+
padding: 10px;
83+
border-style: solid;
84+
border-width: thin;
8185
background-color: #fff; /* default - alterable via nbextension-configurator */
86+
}
87+
88+
#toc-wrapper .toc {
89+
flex-grow: 1;
90+
}
91+
92+
.float-wrapper {
93+
border-color: rgba(0, 0, 0, 0.38);
94+
border-radius: 5px;
8295
opacity: .8;
83-
z-index: 100;
84-
overflow: hidden;
8596
}
8697

8798
.sidebar-wrapper {
88-
height: 100%;
89-
left: 5px;
90-
padding: 10px;
91-
position: fixed !important;
99+
top: 0;
100+
bottom: 0;
92101
width: 212px;
93-
max-width: 28%;
94-
background-color: #fff; /* default - alterable via nbextension-configurator */
95-
border-style: solid;
96102
border-color: #eeeeee; /* default - alterable via nbextension-configurator */
97-
opacity: .99;
98-
overflow: hidden;
103+
}
104+
105+
.sidebar-wrapper .ui-resizable-se {
106+
display: none;
107+
}
108+
109+
.sidebar-wrapper .ui-resizable-e {
110+
position: absolute;
111+
top: calc(50% - 8px);
99112
}
100113

101114
#toc-wrapper.closed {
@@ -110,32 +123,28 @@ padding-left: 20px;
110123
font-size: 18px;
111124
font-weight: bold;
112125
}
113-
#toc-wrapper .hide-btn {
114-
font-size: 14px;
115-
font-family: monospace;
126+
127+
.sidebar-wrapper .hide-btn {
128+
display:none;
116129
}
117130

118-
#toc-wrapper .reload-btn {
119-
font-size: 14px;
120-
font-family: monospace;
131+
#toc-wrapper .hide-btn:before {
132+
content: "\f147";
121133
}
122134

123-
#toc-wrapper .number_sections-btn {
135+
#toc-wrapper.closed .hide-btn:before {
136+
content: "\f196";
137+
}
138+
139+
#toc-header .fa {
124140
font-size: 14px;
125-
font-family: monospace;
141+
text-decoration: none;
126142
}
127143

128144
/* on scroll style */
129145
.highlight_on_scroll {
130146
border-left: solid 4px blue;
131147
}
132-
/* don't waste so much screen space... */
133-
134-
/*
135-
.toc .toc-item .toc-item {
136-
padding-left: 1em;
137-
}
138-
*/
139148

140149
.toc-item li { margin:0; padding:0; color:black }
141150
.toc-item li > span { display:block }
@@ -146,12 +155,8 @@ padding-left: 20px;
146155
.toc-item li li li li li > span { padding-left:4em }
147156
.toc-item li li li li li li > span { padding-left:5em }
148157

149-
.toc-item-num {
150-
font-style: normal;
151-
}
152158

153159
#toc-wrapper .toc-item-num {
154-
font-style: normal;
155160
font-family: Georgia, Times New Roman, Times, serif;
156161
color: black; /* default - alterable via nbextension-configurator */
157162
}
@@ -163,6 +168,16 @@ and updated using the nbextension-configurator
163168
.toc-item-highlight-execute {background-color: red}
164169
.toc-item-highlight-execute.toc-item-highlight-select {background-color: Gold} */
165170

171+
#toc-header .fa ,
166172
.toc-item .fa-fw:first-child {
167173
cursor: pointer;
168174
}
175+
176+
#toc-header,
177+
.modal-header {
178+
cursor: move;
179+
}
180+
181+
.tocSkip {
182+
display: none;
183+
}

src/jupyter_contrib_nbextensions/nbextensions/toc2/main.js

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -49,18 +49,16 @@ define([
4949
number_sections: true,
5050
sideBar: true,
5151
skip_h1_title: false,
52+
title_cell: 'Table of Contents',
53+
title_sidebar: 'Contents',
5254
toc_cell: false,
5355
toc_position: {},
54-
toc_section_display: 'block',
56+
toc_section_display: true,
5557
toc_window_display: false,
5658
};
5759
// add per-notebook settings into global config object
5860
$.extend(true, cfg, metadata_settings);
5961

60-
//.....................global variables....
61-
var st={}
62-
st.oldTocHeight = undefined
63-
6462
var read_config = function (cfg, callback) {
6563
IPython.notebook.config.loaded.then(function () {
6664
// config may be specified at system level or at document level.
@@ -116,7 +114,7 @@ define([
116114
// ----------------------------------------------------------------------
117115

118116
function toggleToc() {
119-
toggle_toc(cfg, st)
117+
toggle_toc(cfg)
120118
}
121119

122120
var toc_button = function() {
@@ -210,12 +208,12 @@ define([
210208
var toc_init = function() {
211209
// read configuration, then call toc
212210
cfg = read_config(cfg, function() {
213-
table_of_contents(cfg, st);
211+
table_of_contents(cfg);
214212
}); // called after config is stable
215213
// event: render toc for each markdown cell modification
216214
events.on("rendered.MarkdownCell",
217215
function(evt, data) {
218-
table_of_contents(cfg, st); // recompute the toc
216+
table_of_contents(cfg); // recompute the toc
219217
rehighlight_running_cells() // re-highlight running cells
220218
highlight_toc_item(evt, data); // and of course the one currently rendered
221219
});

0 commit comments

Comments
 (0)