Customizing the Notebook interface with JavaScript

In [1]:
%%javascript

// This function allows us to add buttons
// to the Notebook toolbar.
IPython.toolbar.add_buttons_group([
{

    // The button's label.
    'label': 'Renumber all code cells',

    // The button's icon.
    // See a list of Font-Awesome icons here:
    // http://fortawesome.github.io/Font-Awesome/icons/
    'icon': 'fa-list-ol',

    // The callback function called when the button is pressed.
    'callback': function () {

        // We retrieve the lists of all cells.
        var cells = IPython.notebook.get_cells();

        // We only keep the code cells.
        cells = cells.filter(function(c)
            {
                return c instanceof IPython.CodeCell;
            })

        // We set the input prompt of all code cells.
        for (var i = 0; i < cells.length; i++) {
            cells[i].set_input_prompt(i + 1);
        }
    }
}]);