From 63ddaad12fec53441a09ff35dfc54d0fabdb5c0e Mon Sep 17 00:00:00 2001 From: Juergen Hasch Date: Tue, 18 Mar 2014 21:39:15 +0100 Subject: [PATCH] Add check to folding preprocessor Only do folding when there is metadata info. --- usability/codefolding/codefoldingpreprocessor.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/usability/codefolding/codefoldingpreprocessor.py b/usability/codefolding/codefoldingpreprocessor.py index eb11b6d..0ac592e 100644 --- a/usability/codefolding/codefoldingpreprocessor.py +++ b/usability/codefolding/codefoldingpreprocessor.py @@ -22,12 +22,13 @@ class CodeFoldingPreprocessor(Preprocessor): lines = f.readlines() if folded[0] == 0 and lines[0][0] == '#': - self.log.info("folded: %s, %s" % (folded[0],lines[0][0])) + # fold when first line is a comment return lines[0].rstrip('\n') + '<->\n' fold_indent = 0 fold = False fcell = "" for i,l in enumerate(lines): + # fold indent level indent = len(l)-len(l.lstrip(' ')) if indent <= fold_indent: fold = False @@ -57,5 +58,6 @@ class CodeFoldingPreprocessor(Preprocessor): if hasattr(cell, "input") and cell.cell_type == "code": if hasattr(cell['metadata'], 'code_folding'): folded = cell['metadata']['code_folding'] - cell.input = self.fold_cell(cell.input, folded) + if len(folded) > 0: + cell.input = self.fold_cell(cell.input, folded) return cell, resources