Created
September 10, 2013 13:13
-
-
Save parente/6509213 to your computer and use it in GitHub Desktop.
TOC in the View menu of IPython Notebook. Tested in 0.9.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| .ui-menu { | |
| width: 300px !important; | |
| } | |
| div.code_cell { | |
| page-break-after: always; | |
| page-break-inside: avoid; | |
| } | |
| .rendered_html h4 { | |
| margin: 0.95em 0em; | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| $([IPython.events]).on('notebook_loaded.Notebook', function(){ | |
| var view_menu = $($('ul#menus > li > ul').get(2)); | |
| var render_toc = function() { | |
| // remove existing toc render | |
| view_menu.find('.toc').remove(); | |
| view_menu.append('<hr class="toc" />'); | |
| IPython.notebook.get_cells().forEach(function(cell, cell_num) { | |
| if(cell.cell_type !== 'heading') return; | |
| var text = cell.get_text(); | |
| if(cell.get_level() > 1) { | |
| text = '└' + text; | |
| } | |
| for(var i=1; i<cell.get_level(); i++) { | |
| text = ' ' + text; | |
| } | |
| var mi = $('<li class="toc"><a href="#">'+text+'</a></li>'); | |
| view_menu.append(mi); | |
| mi.click(function() { | |
| console.log(cell_num); | |
| IPython.notebook.scroll_to_cell(cell_num, 250); | |
| }); | |
| }); | |
| view_menu.data('menu').refresh(); | |
| }; | |
| $([IPython.events]).on('selected_cell_type_changed.Notebook', function (event, data) { | |
| render_toc(); | |
| }); | |
| render_toc(); | |
| }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment