module helper_in_notebook

Short summary

module jyquickhelper.helper_in_notebook

Functions to call from the notebook

source on GitHub

Functions

function

truncated documentation

_add_notebook_menu_js

add_notebook_menu

Adds javascript and HTML to the notebook which gathers all in the notebook and builds a menu.

load_extension

install an extension, checks first it exists, if not displays an exception with the list of them

set_notebook_name_theNotebook

This function must be called from the notebook you want to know the name. It relies on a javascript piece of code. …

Documentation

Functions to call from the notebook

source on GitHub

jyquickhelper.helper_in_notebook._add_notebook_menu_js()
jyquickhelper.helper_in_notebook.add_notebook_menu(menu_id='my_id_menu_nb', raw=False, format='html', header=None, first_level=2, last_level=4, keep_item=None)

Adds javascript and HTML to the notebook which gathers all in the notebook and builds a menu.

Parameters:
  • menu_id – menu_id

  • raw – raw HTML and Javascript

  • formathtml or rst

  • header – title of the menu (None for None)

  • first_level – first level to consider

  • last_level – last level to consider

  • keep_item – None or integer (starts at 0), reduce the number of displayed items to 1 and its descendant

Returns:

HTML object

In a notebook, it is easier to do by using a magic command %%html for the HTML and another one %%javascript for the Javascript. This function returns a full text with HTML and javascript.

If the format is RST, the menu can be copied/pasted in a text cell.

On the notebook, the instruction would work:

var anchors = document.getElementsByClassName("anchor-link");

But it fails during the conversion from a notebook to format RST.

source on GitHub

jyquickhelper.helper_in_notebook.load_extension(name)

install an extension, checks first it exists, if not displays an exception with the list of them

Parameters:

name – extension name

source on GitHub

jyquickhelper.helper_in_notebook.set_notebook_name_theNotebook(name='theNotebook', display=True)

This function must be called from the notebook you want to know the name. It relies on a javascript piece of code. It populates the variable theNotebook with the notebook name.

Parameters:
  • name – name of the variable to create

  • display – calls display or returns a javascript object

Returns:

None or Javascript

This solution was found at How to I get the current IPython Notebook name.

The function can be called in a cell. The variable theNotebook will be available in the next cells.

Try function store_notebook_path() if this one does not work.

source on GitHub