{"cells": [{"cell_type": "markdown", "metadata": {}, "source": ["# Example of a notebook with a javascript menu"]}, {"cell_type": "markdown", "metadata": {}, "source": ["It is sometimes difficult to navigate through long notebooks. Regular ways to navigate in a HTML page are not available when the cursor is stuck in a cell. Here is a simple trick with two sections. Links remains at the same place anytime just by adding HTML in the notebook.\n", "\n", "\n", "
\n", "\n", "[Section 1](#Section-1) -- [Section 2](#Section-2) -- [This is the end](#This-is-the-end.)\n", "\n", "
\n", "\n", "The code in the markdown cell looks like the following, it is a mix between HTML and markdown. The combination is not perfect but that works somehow. The outcome can be shown on the left."]}, {"cell_type": "raw", "metadata": {}, "source": ["
\n", "\n", "[Section 1](#Section-1) -- [Section 2](#Section-2) -- [This is the end](#This-is-the-end.)\n", "\n", "
"]}, {"cell_type": "markdown", "metadata": {}, "source": ["This trick does not work very well with IPython 3+. So I created a simple function which automaticallt adds a menu to all sections within the notebook."]}, {"cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [{"data": {"text/html": ["
run previous cell, wait for 2 seconds
\n", ""], "text/plain": [""]}, "execution_count": 2, "metadata": {}, "output_type": "execute_result"}], "source": ["from jyquickhelper import add_notebook_menu\n", "add_notebook_menu(menu_id=\"main_menu\")"]}, {"cell_type": "markdown", "metadata": {}, "source": ["### Section 1"]}, {"cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [{"name": "stdout", "output_type": "stream", "text": ["line 0\n", "line 1\n", "line 2\n", "line 3\n", "line 4\n", "line 5\n", "line 6\n", "line 7\n", "line 8\n", "line 9\n", "line 10\n", "line 11\n", "line 12\n", "line 13\n", "line 14\n", "line 15\n", "line 16\n", "line 17\n", "line 18\n", "line 19\n", "line 20\n", "line 21\n", "line 22\n", "line 23\n", "line 24\n", "line 25\n", "line 26\n", "line 27\n", "line 28\n", "line 29\n"]}], "source": ["for i in range(0,30):\n", " # just making space\n", " print (\"line\",i)"]}, {"cell_type": "markdown", "metadata": {}, "source": ["### Section 2"]}, {"cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [{"name": "stdout", "output_type": "stream", "text": ["line2 0\n", "line2 1\n", "line2 2\n", "line2 3\n", "line2 4\n", "line2 5\n", "line2 6\n", "line2 7\n", "line2 8\n", "line2 9\n", "line2 10\n", "line2 11\n", "line2 12\n", "line2 13\n", "line2 14\n", "line2 15\n", "line2 16\n", "line2 17\n", "line2 18\n", "line2 19\n", "line2 20\n", "line2 21\n", "line2 22\n", "line2 23\n", "line2 24\n", "line2 25\n", "line2 26\n", "line2 27\n", "line2 28\n", "line2 29\n"]}], "source": ["for i in range(0,30):\n", " # making space again\n", " print(\"line2\",i)"]}, {"cell_type": "markdown", "metadata": {}, "source": ["### This is the end."]}, {"cell_type": "markdown", "metadata": {}, "source": ["We end up by using some functionalities from pyquickhelper."]}, {"cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [{"data": {"application/javascript": ["var kernel = IPython.notebook.kernel;\n", "var body = document.body, attribs = body.attributes;\n", "var command = \"theNotebook = \" + \"'\"+attribs['data-notebook-name'].value+\"'\";\n", "kernel.execute(command);"], "text/plain": [""]}, "metadata": {}, "output_type": "display_data"}, {"data": {"application/javascript": ["var kernel = IPython.notebook.kernel;\n", "var body = document.body, attribs = body.attributes;\n", "var command = \"theNotebook = \" + \"'\"+attribs['data-notebook-name'].value+\"'\";\n", "kernel.execute(command);"], "text/plain": [""]}, "execution_count": 5, "metadata": {}, "output_type": "execute_result"}], "source": ["from jyquickhelper import set_notebook_name_theNotebook\n", "set_notebook_name_theNotebook()"]}, {"cell_type": "code", "execution_count": 5, "metadata": {}, "outputs": [{"data": {"text/plain": ["'exemple_of_fix_menu.ipynb'"]}, "execution_count": 6, "metadata": {}, "output_type": "execute_result"}], "source": ["theNotebook"]}, {"cell_type": "code", "execution_count": 6, "metadata": {}, "outputs": [{"data": {"text/html": ["
run previous cell, wait for 2 seconds
\n", ""], "text/plain": [""]}, "execution_count": 7, "metadata": {}, "output_type": "execute_result"}], "source": ["from jyquickhelper import add_notebook_menu\n", "add_notebook_menu()"]}, {"cell_type": "code", "execution_count": 7, "metadata": {}, "outputs": [], "source": []}, {"cell_type": "code", "execution_count": 8, "metadata": {}, "outputs": [], "source": []}], "metadata": {"kernelspec": {"display_name": "Python 3", "language": "python", "name": "python3"}, "language_info": {"codemirror_mode": {"name": "ipython", "version": 3}, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.7.2"}}, "nbformat": 4, "nbformat_minor": 4}