Added links download notebook
@@ -30,6 +30,8 @@ import os
import sys
from shutil import copytree, rmtree
import re
+import nbformat
+from nbformat.v4 import new_markdown_cell
try:
import astropy_helpers
@@ -198,11 +200,30 @@ gammapy_sphinx_ext_activate()
# ---
# notebooks
# make relative links
-def modif_links(folder):
+DOWNLOAD_CELL = """
+<div class='admonition note'>
+[Download notebook](../_static/notebooks/nbfilename.ipynb)
+
+This is a *fixed-text* formatted version of a Jupyter notebook. """
+if on_rtd:
+ DOWNLOAD_CELL += """
+ You may download the whole HTML documentation for this version of gammapy
+ using the link at the bottom of this page and execute the notebooks
+ in your local desktop inside the `_static/notebooks/` folder.
+ """
+DOWNLOAD_CELL += """</div>"""
+
url_docs = setup_cfg.get('url_docs')
- for file in os.listdir(folder):
- filepath = os.path.join(folder, file)
+
+def modif_links(folder):
+ for filename in os.listdir(folder):
+ filepath = os.path.join(folder, filename)
if os.path.isfile(filepath) and filepath[-6:] == '.ipynb':
+ if folder=='notebooks':
+ strcell = DOWNLOAD_CELL.replace('nbfilename.ipynb', filename)
+ nb = nbformat.read(filepath, as_version=nbformat.NO_CONVERT)
+ nb.cells.insert(0, new_markdown_cell(strcell))
+ nbformat.write(nb, filepath)
with open(filepath, "r") as f:
txt = f.read()
if folder=='notebooks':
