Skip to content
Permalink
Browse files

update notebooks

  • Loading branch information...
sdpython committed Sep 26, 2015
1 parent 215ec62 commit e000fb69860be1120d95d5be37c2b50172ced468
Showing with 114 additions and 20 deletions.
  1. +114 −20 _doc/notebooks/custom_notebooks.ipynb
@@ -9,7 +9,7 @@
},
{
"cell_type": "code",
"execution_count": 4,
"execution_count": 1,
"metadata": {
"collapsed": false
},
@@ -19,36 +19,109 @@
"text/html": [
"<div id=\"my_id_menu_nb\">run previous cell, wait for 2 seconds</div>\n",
"<script>\n",
"var update_menu = function() {\n",
" var els = document.getElementsByClassName(\"sphinxsidebar\");\n",
" var level;\n",
" if (els.length > 0) level = \"h2\";\n",
" else level = \"h3\";\n",
" var anchors = document.getElementsByTagName(level);\n",
" var menu = document.getElementById(\"my_id_menu_nb\");\n",
" var i;\n",
" var text_menu = \"<ul>\";\n",
"function repeat_indent_string(n){\n",
" var a = \"\" ;\n",
" for ( ; n > 0 ; --n) {\n",
" a += \" \";\n",
" }\n",
" return a;\n",
"}\n",
"var update_menu_string = function(begin, lfirst, llast, sformat, send) {\n",
" var anchors = document.getElementsByClassName(\"section\");\n",
" if (anchors.length == 0) {\n",
" anchors = document.getElementsByClassName(\"text_cell_render rendered_html\");\n",
" }\n",
" var i,t;\n",
" var text_menu = begin;\n",
" var text_memo = \"<pre>\\nlength:\" + anchors.length + \"\\n\";\n",
" var ind = \"\";\n",
" var memo_level = 1;\n",
" var href;\n",
" var tags = [];\n",
" for (i = lfirst; i <= llast; i++) {\n",
" tags.push(\"h\" + i);\n",
" }\n",
"\n",
" for (i = 0; i < anchors.length; i++) {\n",
"var title = anchors[i].textContent;\n",
"title = title.substring(0,title.length-1);\n",
"if (anchors[i].hasAttribute(\"id\"))\n",
" href = anchors[i].id;\n",
"else\n",
" href = anchors[i].parentNode.id;\n",
"text_menu += '<li><a href=\"#' + href + '\">' + title + '</a></li>';\n",
" text_memo += \"**\" + anchors[i].id + \"--\\n\";\n",
" \n",
" var child = null;\n",
" for(t = 0; t < tags.length; t++) {\n",
" var r = anchors[i].getElementsByTagName(tags[t]);\n",
" if (r.length > 0) {\n",
"child = r[0];\n",
"break;\n",
" }\n",
" }\n",
" if (child == null){\n",
" text_memo += \"null\\n\";\n",
" continue;\n",
" }\n",
" \n",
" if (anchors[i].hasAttribute(\"id\")) {\n",
" // when converted in RST\n",
" href = anchors[i].id;\n",
" text_memo += \"#1-\" + href;\n",
" // passer à child suivant (le chercher)\n",
" }\n",
" else if (child.hasAttribute(\"id\")) {\n",
" // in a notebook\n",
" href = child.id;\n",
" text_memo += \"#2-\" + href;\n",
" }\n",
" else {\n",
" text_memo += \"#3-\" + \"*\" + \"\\n\";\n",
" continue;\n",
" }\n",
" var title = child.textContent;\n",
" var level = parseInt(child.tagName.substring(1,2));\n",
" \n",
" text_memo += \"--\" + level + \"?\" + lfirst + \"--\" + title + \"\\n\";\n",
" \n",
" if ((level < lfirst) || (level > llast)) {\n",
" continue ;\n",
" }\n",
" if (title.endsWith('¶')) {\n",
" title = title.substring(0,title.length-1).replace(\"<\", \"&lt;\").replace(\">\", \"&gt;\").replace(\"&\", \"&amp;\")\n",
" }\n",
" \n",
" if (title.length == 0) {\n",
" continue;\n",
" }\n",
" while (level > memo_level) {\n",
" text_menu += \"<ul>\\n\";\n",
" memo_level += 1;\n",
" }\n",
" while (level < memo_level) {\n",
" text_menu += \"</ul>\\n\";\n",
" memo_level -= 1;\n",
" }\n",
" text_menu += repeat_indent_string(level-2) + sformat.replace(\"__HREF__\", href).replace(\"__TITLE__\", title);\n",
" }\n",
" while (1 < memo_level) {\n",
" text_menu += \"</ul>\\n\";\n",
" memo_level -= 1;\n",
" }\n",
" text_menu += \"</ul>\"\n",
" text_menu += send;\n",
" //text_menu += \"\\n\" + text_memo;\n",
" return text_menu;\n",
"};\n",
"var update_menu = function() {\n",
" var sbegin = \"\";\n",
" var sformat = '<li><a href=\"#__HREF__\">__TITLE__</a></li>';\n",
" var send = \"\";\n",
" var text_menu = update_menu_string(sbegin, 2, 4, sformat, send);\n",
" var menu = document.getElementById(\"my_id_menu_nb\");\n",
" menu.innerHTML=text_menu;\n",
"};\n",
"window.setTimeout(update_menu,2000);\n",
"</script>"
" </script>"
],
"text/plain": [
"<IPython.core.display.HTML object>"
]
},
"execution_count": 4,
"execution_count": 1,
"metadata": {},
"output_type": "execute_result"
}
@@ -97,6 +170,27 @@
"### Other section"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"text"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Section level 2"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### level 3"
]
},
{
"cell_type": "code",
"execution_count": null,

0 comments on commit e000fb6

Please sign in to comment.
You can’t perform that action at this time.