Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

0.2.0 Release #15

Merged
merged 11 commits into from
Apr 25, 2016
Prev Previous commit
Next Next commit
Updated readme.
  • Loading branch information
kirbs- committed Apr 11, 2016
commit ff03e813e98b9442fd74e794a5d798045fba27bc
31 changes: 28 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@

Release: ![Travis release build](https://travis-ci.org/kirbs-/hide_code.svg?branch=master) Dev: ![Dev Build Status](https://travis-ci.org/kirbs-/hide_code.svg?branch=dev)

## hide_code now supports HTML & PDF exporting!

## Introduction
hide_code is an extension for Jupyter/IPython notebooks to selectively hide code and prompts. Make a notebook a code free document for exporting or presenting with a single click by pressing ![hide_code toggle](/images/button.png)
hide_code is an extension for Jupyter/IPython notebooks to selectively hide code and prompts. Make a notebook a code free document for presenting with a single click by pressing ![hide_code toggle](/images/button.png)

###### Normal
![image1.1](/images/1.1.png)
Expand All @@ -17,11 +19,32 @@ Or customize each cell by selecting "Hide code" from the Cell Toolbar dropdown.
![image2](/images/2.png)

###### Normal
![image3.q](/images/3.1.png)
![image3.1](/images/3.1.png)

###### Hide code enabled
![image3.2](/images/3.2.png)

## Exporting
Exported file output is saved in Jupyter's current working directory with the notebook's file name + '.html' or '.pdf'. **Exporting to PDF via notebook requires [wkhtmltopdf](http://wkhtmltopdf.org/)!**

This feature continues to evolve. Items on the road map incude:
* saving to a different file loaction.
* saving as a different file name.
* support for custom CSS.
* single click exporting with all code and prompts hidden (similar to how the toolbar button.

### Via notebook
To export via HTML or PDF button ![image4.1](/images/4.1.png) you must set each cell's hide prompt and hide code selection.

### Via nbconvert command line
To export via nbconvert command line, nbconvert 4.2 or later is required. Hide_code adds two export options to nbconvert, hide_code_html and hide_code_pdf.

Note: PDF exporting via command line uses nbconvert's built in PDF exporter.

`jupyter nbconvert --to hide_code_html notebook_to_convert.ipynb`

`jupyter nbconvert --to hide_code_pdf notebook_to_convert.ipynb`

## Installation
### Via pip
`pip install hide_code`
Expand All @@ -40,5 +63,7 @@ hc.install(dir)
```

## Requirements
* Jupyter notebook 4+
* Jupyter notebook 4.x+
* Jupyter nbconvert 4.2+ if using nbconvert command line
* pdfkit & [wkhtmltopdf](http://wkhtmltopdf.org/)
* Python 2.7+ if installing with pip
4 changes: 2 additions & 2 deletions hide_code/hide_code.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,14 +90,14 @@ function ($, celltoolbar){
}
},
{
'label' : 'Export html',
'label' : 'Export to HTML',
'icon' : 'fa-file-text-o',
'callback' : function (){
window.open(document.URL + "/export/html")
}
},
{
'label' : 'Export PDF',
'label' : 'Export to PDF',
'icon' : 'fa-file-pdf-o',
'callback' : function (){
window.open(document.URL + "/export/pdf")
Expand Down
49 changes: 32 additions & 17 deletions hide_code/hide_code.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from traitlets.config import Config
from .hide_code_html_exporter import HideCodeHTMLExporter
import pdfkit
from notebook.services.config import ConfigManager

notebook_dir = ""
base_url = ""
Expand Down Expand Up @@ -105,24 +106,38 @@ def install(nb_path=None, server_config=True, DEBUG=False):
if server_config:
print("Attempting to configure default profile to auto-load hide_code export handlers.")
try:
with open(path.join(current_dir, "auto-load-server-extension.txt"), 'r') as auto:
auto_load_ext_text = auto.read();
auto_loaded = False
config_dir = j_path.jupyter_config_dir()

with open(path.join(config_dir, 'jupyter_notebook_config.py'), 'r') as nb_config:
if auto_load_ext_text in nb_config.read():
auto_loaded = True
print("jupyter_notebook_config.py already configured to auto-load hide_code export handlers.")

if not auto_loaded:
with open(path.join(config_dir, 'jupyter_notebook_config.py'), 'a') as ipython_config:
ipython_config.write(auto_load_ext_text)
print('Configured default_profile to auto-load hide_code server extensions.')
# Activate the Python server extension
server_cm = ConfigManager(config_dir=j_path.jupyter_config_dir())
cfg = server_cm.get('jupyter_notebook_config')
server_extensions = (cfg.setdefault('NotebookApp', {})
.setdefault('server_extensions', [])
)
extension = 'hide_code.hide_code'
if extension not in server_extensions:
cfg['NotebookApp']['server_extensions'] += [extension]
server_cm.update('jupyter_notebook_config', cfg)
print('Configured jupyter to auto-load hide_code server extensions.')
else:
print("jupyter_notebook_config already configured to auto-load export handlers.")

# with open(path.join(current_dir, "auto-load-server-extension.txt"), 'r') as auto:
# auto_load_ext_text = auto.read();
# auto_loaded = False
# config_dir = j_path.jupyter_config_dir()

# with open(path.join(config_dir, 'jupyter_notebook_config.py'), 'r') as nb_config:
# if auto_load_ext_text in nb_config.read():
# auto_loaded = True
# print("jupyter_notebook_config.py already configured to auto-load hide_code export handlers.")

# if not auto_loaded:
# with open(path.join(config_dir, 'jupyter_notebook_config.py'), 'a') as ipython_config:
# ipython_config.write(auto_load_ext_text)
# print('Configured default_profile to auto-load hide_code server extensions.')
except:
print('Unable to install server extension into ' + j_path.jupyter_config_path(),)
print('jupyter_notebook_config.py may not exist.')
print('Try running \'jupyter notebook --generate-config\' and reinstall hide_code.')
print('Unable to install server extension.') # + j_path.jupyter_config_path(),)
# print('jupyter_notebook_config.py may not exist.')
# print('Try running \'jupyter notebook --generate-config\' and reinstall hide_code.')


def get_site_package_dir():
Expand Down
11 changes: 10 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,18 @@ def _post_install(dir):


class install(_install):
description = 'Installs hide_code.js and hide_code export handlers server extension.'
# user_options = [{'auto-load=', None, 'Do not auto-load server extensions.'}]

# def initialize_options(self):
# self.auto_load = True

# def finalize_options(self):
# _install.finalize_options()

def run(self):
_install.run(self)
self.execute(_post_install, (self.install_lib,), msg="Running post install task...")
self.execute(_post_install, (self.install_lib, ), msg="Running post install task...")



Expand Down