From 308fb2914a6528e44cffb9a697bac9d185e14fc3 Mon Sep 17 00:00:00 2001 From: Matthias Geier Date: Wed, 21 Mar 2018 17:55:19 +0100 Subject: [PATCH] Don't remove empty cells by default Fixes #720. --- nbconvert/preprocessors/regexremove.py | 14 ++++++-------- nbconvert/preprocessors/tests/test_regexremove.py | 4 ++-- 2 files changed, 8 insertions(+), 10 deletions(-) diff --git a/nbconvert/preprocessors/regexremove.py b/nbconvert/preprocessors/regexremove.py index 7c185df52..91154cf28 100644 --- a/nbconvert/preprocessors/regexremove.py +++ b/nbconvert/preprocessors/regexremove.py @@ -20,16 +20,14 @@ class RegexRemovePreprocessor(Preprocessor): of unicode strings. If the contents match any of the patterns, the cell is removed from the notebook. - By default, `patterns = [r'\Z']` which matches the empty string such that - strictly empty cells are removed. To modify the list of matched patterns, + To modify the list of matched patterns, modify the patterns traitlet. For example, execute the following command - to convert a notebook to html and remove cells containing only whitespace: + to convert a notebook to html and remove cells containing only whitespace:: - > jupyter nbconvert --RegexRemovePreprocessor.enabled=True \ - --RegexRemovePreprocessor.patterns="['\\s*\\Z']" mynotebook.ipynb + jupyter nbconvert --RegexRemovePreprocessor.patterns="['\\s*\\Z']" mynotebook.ipynb - The first command line argument enables the preprocessor and the second - sets the list of patterns to '\\s*\\Z' which matches an arbitrary number + The command line argument + sets the list of patterns to ``'\\s*\\Z'`` which matches an arbitrary number of whitespace characters followed by the end of the string. See https://regex101.com/ for an interactive guide to regular expressions @@ -38,7 +36,7 @@ class RegexRemovePreprocessor(Preprocessor): documentation in python. """ - patterns = List(Unicode(), default_value=[r'\Z']).tag(config=True) + patterns = List(Unicode(), default_value=[]).tag(config=True) def check_conditions(self, cell): """ diff --git a/nbconvert/preprocessors/tests/test_regexremove.py b/nbconvert/preprocessors/tests/test_regexremove.py index 1024a7fca..3f7bc2903 100644 --- a/nbconvert/preprocessors/tests/test_regexremove.py +++ b/nbconvert/preprocessors/tests/test_regexremove.py @@ -44,9 +44,9 @@ def test_output(self): 'disallow_tab_newline': [r'\t\Z', r'\n\Z'] } expected_cell_count = { - 'default': 5, # only strictly empty cells + 'default': 6, # nothing is removed 'disallow_whitespace': 2, # all "empty" cells are removed - 'disallow_tab_newline': 3, # all "empty" cells but the single space + 'disallow_tab_newline': 4, # cells with tab and newline are removed 'none': 6, } for method in ['default', 'disallow_whitespace', 'disallow_tab_newline', 'none']: