%%javascript
var kernel = IPython.notebook.kernel;
var body = document.body,  
    attribs = body.attributes;
var command = "theNotebook = " + "'"+attribs['data-notebook-name'].value+"'";
kernel.execute(command);

if "theNotebook" in locals():
    a = theNotebook
else:
    a = None
a

"""
Explanation: 2A.soft - Convert a notebook into a document
A couple of tricks to convert notebook such as convert a notebook into RST or HTML, get the notebook name.
First, let's retrieve the notebook name (see How to I get the current IPython Notebook name):
End of explanation
"""


import sys
if sys.platform.startswith("win"):
    from pyquickhelper.helpgen.utils_pywin32 import import_pywin32
    import_pywin32()

"""
Explanation: On Windows, you might need to execute the following trick (see Pywin32 does not find its DLL).
End of explanation
"""


from nbconvert import HTMLExporter
exportHtml = HTMLExporter()
if a is not None:
    body,resources = exportHtml.from_filename(theNotebook)
    with open("conv_notebook.html", "w", encoding="utf8") as f: 
        f.write(body)

"""
Explanation: Then, we call the following code:
End of explanation
"""


from nbconvert import RSTExporter
exportRst = RSTExporter()
if a is not None:
    body,resources = exportRst.from_filename(theNotebook)
    with open("conv_notebook.rst", "w", encoding="utf8") as f: 
        f.write(body)

"""
Explanation: We can do it with the RST format (see RSTExporter).
End of explanation
"""


from IPython.display import FileLink
FileLink("conv_notebook.rst")

"""
Explanation: Finally, if you want to retrieve the download a local file such as the RST conversion for example:
<!--RST ..index:: FileLink !RST-->
End of explanation
"""


FileLink("conv_notebook.html")

"""
Explanation: And the second link:
End of explanation
"""


