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

Add options for inputs, outputs and prompts to be excluded #185

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 26 additions & 3 deletions src/nbsphinx.py
Original file line number Diff line number Diff line change
Expand Up @@ -520,7 +520,10 @@ class Exporter(nbconvert.RSTExporter):
"""

def __init__(self, execute='auto', kernel_name='', execute_arguments=[],
allow_errors=False, timeout=30, codecell_lexer='none'):
allow_errors=False, timeout=30, codecell_lexer='none',
exclude_input = False, exclude_input_prompt = False,
exclude_output_prompt = False):

"""Initialize the Exporter."""
self._execute = execute
self._kernel_name = kernel_name
Expand All @@ -529,10 +532,18 @@ def __init__(self, execute='auto', kernel_name='', execute_arguments=[],
self._timeout = timeout
self._codecell_lexer = codecell_lexer
loader = jinja2.DictLoader({'nbsphinx-rst.tpl': RST_TEMPLATE})
self._exclude_input = exclude_input
self._exclude_input_prompt = exclude_input_prompt
self._exclude_output_prompt = exclude_output_prompt

super(Exporter, self).__init__(
template_file='nbsphinx-rst.tpl', extra_loaders=[loader],
config=traitlets.config.Config(
{'HighlightMagicsPreprocessor': {'enabled': True}}),
{'HighlightMagicsPreprocessor': {'enabled': True},
'TemplateExporter':{
"exclude_input": exclude_input,
"exclude_input_prompt": exclude_input_prompt,
"exclude_output_prompt": exclude_output_prompt}}),
filters={
'convert_pandoc': convert_pandoc,
'markdown2rst': markdown2rst,
Expand Down Expand Up @@ -647,6 +658,10 @@ def parse(self, inputstring, document):
allow_errors=env.config.nbsphinx_allow_errors,
timeout=env.config.nbsphinx_timeout,
codecell_lexer=env.config.nbsphinx_codecell_lexer,

exclude_input = env.config.nbsphinx_exclude_input,
exclude_input_prompt = env.config.nbsphinx_exclude_input_prompt,
exclude_output_prompt = env.config.nbsphinx_exclude_output_prompt,
)

try:
Expand Down Expand Up @@ -778,7 +793,10 @@ def run(self):

# Optional output prompt
if execution_count:
text = 'Out[{}]:'.format(execution_count)
if self.state.document.settings.env.config.nbsphinx_exclude_output_prompt:
text = ''
else:
text = 'Out[{}]:'.format(execution_count)
container += CodeNode.create(text, classes=['prompt'])
latex_prompt = text + ' '
else:
Expand Down Expand Up @@ -1441,6 +1459,11 @@ def setup(app):
app.add_config_value('nbsphinx_allow_errors', False, rebuild='')
app.add_config_value('nbsphinx_timeout', 30, rebuild='')
app.add_config_value('nbsphinx_codecell_lexer', 'none', rebuild='env')
#hide or display input, output,....
app.add_config_value('nbsphinx_exclude_input', False, rebuild='env')
app.add_config_value('nbsphinx_exclude_input_prompt', False, rebuild='env')
app.add_config_value('nbsphinx_exclude_output_prompt', False, rebuild='env')

# Default value is set in builder_inited():
app.add_config_value('nbsphinx_prompt_width', None, rebuild='html')
app.add_config_value('nbsphinx_responsive_width', '540px', rebuild='html')
Expand Down