Skip to content

Commit 3532c08

Browse files
committed
[toc2] option to skip h1 headings for use as notebook title
rename option, add yaml entry for configurator, limit to h1 rather than just the first heading
1 parent c388b21 commit 3532c08

File tree

4 files changed

+14
-7
lines changed

4 files changed

+14
-7
lines changed

src/jupyter_contrib_nbextensions/nbextensions/toc2/README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ The initial configuration can be given using the IPython-contrib nbextensions fa
2929
- Widening the display area to fit the browser window (may be useful with sidebar option; default: true)
3030
- The numbering of headers (true by default)
3131
- Moving header title and menus on the left (default: true)
32-
- Skipping the first header (useful if you want to display a title): set `skipTitle` to true in the notebook's metadata (default: false)
32+
- Skipping h1 headers, useful if you want to use h1 as unnumbered notebook title (default: false)
3333
- Customization of highlighting the title of currently selected/running sections.
3434
- Customization of background, fonts, border and highlighting colors in the toc window and navigation menus (as third demo).
3535

@@ -103,3 +103,5 @@ This option requires the IPython kernel and is not present with other kernels.
103103
- Updated README to please @KadeG in #871
104104
- @hiiwave, april 2017.
105105
- 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)
106+
- @louisabraham, @jcb91 July 2017. Add support for skipping h1 headings,
107+
enabling their use as unnumbered notebook titles

src/jupyter_contrib_nbextensions/nbextensions/toc2/main.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ define(["require", "jquery", "base/js/namespace", 'services/config',
3333
'navigate_text': '#333333',
3434
'navigate_num': '#000000',
3535
},
36-
'skipTitle': false
36+
skip_h1_title: false,
3737
}
3838

3939
//.....................global variables....

src/jupyter_contrib_nbextensions/nbextensions/toc2/toc2.js

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -534,17 +534,15 @@ var table_of_contents = function (cfg,st) {
534534
var depth = 1; //var depth = ol_depth(ol);
535535
var li= ul;//yes, initialize li with ul!
536536
var all_headers= $("#notebook").find(":header");
537-
var min_lvl=1, lbl_ary= [];
537+
var min_lvl = 1 + Number(Boolean(cfg.skip_h1_title)), lbl_ary = [];
538538
for(; min_lvl <= 6; min_lvl++){ if(all_headers.is('h'+min_lvl)){break;} }
539539
for(var i= min_lvl; i <= 6; i++){ lbl_ary[i - min_lvl]= 0; }
540540

541541
//loop over all headers
542542
all_headers.each(function (i, h) {
543543
var level = parseInt(h.tagName.slice(1), 10) - min_lvl + 1;
544-
// skip title if necessary
545-
if (cfg.skipTitle &&!i){ return; }
546-
// skip below threshold
547-
if (level > cfg.threshold){ return; }
544+
// skip below threshold, or h1 ruled out by cfg.skip_h1_title
545+
if (level < 1 || level > cfg.threshold){ return; }
548546
// skip headings with no ID to link to
549547
if (!h.id){ return; }
550548
// skip toc cell if present

src/jupyter_contrib_nbextensions/nbextensions/toc2/toc2.yaml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,13 @@ Parameters:
1616
min: -1
1717
step: 1
1818
default: 4
19+
20+
- name: toc2.skip_h1_title
21+
description: |
22+
Skip h1 headings from numbering, so that they can serve as a notebook title
23+
input_type: checkbox
24+
default: false
25+
1926
- name: toc2.toc_cell
2027
description: Add a Table of Contents cell at the top of the notebook
2128
input_type: checkbox

0 commit comments

Comments
 (0)