diff --git a/src/nbsphinx.py b/src/nbsphinx.py index e3bd31aa..a9b58527 100644 --- a/src/nbsphinx.py +++ b/src/nbsphinx.py @@ -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 @@ -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, @@ -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: @@ -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: @@ -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')