Skip to content

Commit 3fff201

Browse files
committed
[collapsible_headings] indent heading collapse controls by level
1 parent 800af8d commit 3fff201

File tree

3 files changed

+45
-1
lines changed

3 files changed

+45
-1
lines changed

src/jupyter_contrib_nbextensions/nbextensions/collapsible_headings/collapsible_headings.yaml

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,86 +6,107 @@ Description: "Allows notebook to have collapsible sections, separated by heading
66
Link: readme.md
77
Icon: icon.png
88
Parameters:
9+
910
- name: collapsible_headings.add_button
1011
description: Add a toolbar button to collapse the closest header cell
1112
input_type: checkbox
1213
default: false
14+
1315
- name: collapsible_headings.add_all_cells_button
1416
description: Add a toolbar button to collapse/uncollapse all header cells
1517
input_type: checkbox
1618
default: false
19+
1720
- name: collapsible_headings.add_insert_header_buttons
1821
description: Add toolbar buttons to insert heading cells above/below the selected cell
1922
input_type: checkbox
2023
default: false
24+
2125
- name: collapsible_headings.use_toggle_controls
2226
description: Add a control in each heading cell's input prompt to collapse/uncollapse it
2327
input_type: checkbox
2428
default: true
29+
2530
- name: collapsible_headings.toggle_color
2631
description: Color for the toggle control icon
2732
input_type: color
2833
default: '#aaaaaa'
34+
2935
- name: collapsible_headings.toggle_closed_icon
3036
description: font-awesome class for the toggle control icon on collapsed headings
3137
default: fa-caret-right
38+
3239
- name: collapsible_headings.toggle_open_icon
3340
description: font-awesome class for the toggle control icon on uncollapsed (expanded) headings
3441
default: fa-caret-down
42+
3543
- name: collapsible_headings.make_toggle_controls_buttons
3644
description: "Make the toggle control into a button (if false, it's just an icon)"
3745
input_type: checkbox
3846
default: false
47+
3948
- name: collapsible_headings.size_toggle_controls_by_level
4049
description: Adjust the size of the toggle controls to match their heading levels
4150
input_type: checkbox
4251
default: true
52+
4353
- name: collapsible_headings.show_section_brackets
4454
description: show Mathematica-style brackets around each collapsible section
4555
input_type: checkbox
4656
default: false
57+
4758
- name: collapsible_headings.section_bracket_width
4859
description: 'Width, in pixels, of the Mathematica-style brackets around sections'
4960
input_type: number
5061
min: 2
5162
max: 100
5263
default: 10
64+
5365
- name: collapsible_headings.show_ellipsis
5466
description: show a gray bracketed ellipsis at the end of collapsed heading cells
5567
input_type: checkbox
5668
default: true
69+
5770
- name: collapsible_headings.use_shortcuts
5871
description: Add command-mode keyboard shortcuts to collapse/uncollapse the selected heading cell
5972
input_type: checkbox
6073
default: true
74+
6175
- name: collapsible_headings.shortcuts.collapse
6276
description: Command-mode shortcut to collapse the selected heading cell
6377
input_type: hotkey
6478
default: left
79+
6580
- name: collapsible_headings.shortcuts.uncollapse
6681
description: Command-mode shortcut to uncollapse (expand) the selected heading cell
6782
input_type: hotkey
6883
default: right
84+
6985
- name: collapsible_headings.shortcuts.collapse_all
7086
description: Command-mode shortcut to collapse all heading cells
7187
input_type: hotkey
7288
default: ctrl-shift-left
89+
7390
- name: collapsible_headings.shortcuts.uncollapse_all
7491
description: Command-mode shortcut to uncollapse (expand) all heading cells
7592
input_type: hotkey
7693
default: ctrl-shift-right
94+
7795
- name: collapsible_headings.shortcuts.select
7896
description: Command-mode shortcut to select all cells in the selected heading cell's section
7997
input_type: hotkey
8098
default: shift-right
99+
81100
- name: collapsible_headings.shortcuts.insert_above
82101
description: Command-mode shortcut to insert a heading cell above the selected cell
83102
input_type: hotkey
84103
default: shift-a
104+
85105
- name: collapsible_headings.shortcuts.insert_below
86106
description: Command-mode shortcut to insert a heading cell below the selected cell's section
87107
input_type: hotkey
88108
default: shift-b
109+
89110
- name: collapsible_headings.select_reveals
90111
description: "By default, selecting a whole section also expands the section to reveal its last cell. Set this option to false to disable the expansion."
91112
input_type: checkbox
@@ -98,3 +119,11 @@ Parameters:
98119
behaviour, see ToC2's configuration
99120
input_type: checkbox
100121
default: false
122+
123+
- name: collapsible_headings.indent_px
124+
description: |
125+
Shift the collapsible heading controls left by this many pixels per level,
126+
such that more significant headings (lower levels) appear further to the
127+
left
128+
input_type: number
129+
default: 8

src/jupyter_contrib_nbextensions/nbextensions/collapsible_headings/main.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
show_ellipsis : true,
4444
select_reveals : true,
4545
collapse_to_match_toc: false,
46+
indent_px: 8,
4647
};
4748

4849
// ------------------------------------------------------------------------
@@ -861,6 +862,19 @@
861862
$.extend(true, params, options);
862863
// bind/unbind toc-collapse handler
863864
events[params.collapse_to_match_toc ? 'on' : 'off']('collapse.Toc uncollapse.Toc', callback_toc_collapse);
865+
// add css for indents
866+
if (params.indent_px !== 0) {
867+
var lines = [];
868+
for (var hh = 1; hh <= 6; hh++) {
869+
lines.push(
870+
'.collapsible_headings_toggle .h' + hh +
871+
' { margin-right: ' + ((6 - hh) * params.indent_px) + 'px; }'
872+
);
873+
}
874+
$('<style id="collapsible_headings_indent_css"/>')
875+
.html(lines.join('\n'))
876+
.appendTo('head');
877+
}
864878
return params;
865879
}
866880

src/jupyter_contrib_nbextensions/nbextensions/collapsible_headings/readme.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ the nbextensions config page:
4242
cell (disabled by default)
4343
* Collapse/uncollapse sections when ToC2 sections are collapsed/uncollapsed
4444
* A toolbar button to collapse/uncollapse all headings (disabled by default)
45+
* Shift more-significant headings' collapse controls further to the left
4546

4647

4748
css
@@ -121,4 +122,4 @@ associated `inliner.tpl` template, provided as part of the
121122
To convert to html embedding collapsible headings functionality, use `html_ch`
122123
exporter, with a command like
123124

124-
jupyter nbconvert --to html_ch FILE.ipynb
125+
jupyter nbconvert --to html_ch FILE.ipynb

0 commit comments

Comments
 (0)