From dc6ff0076ae0a3a9f958b9e336f5eb2aab72b30e 2012-11-19 10:55:32 From: Ivan Djokic Date: 2012-11-19 10:55:32 Subject: [PATCH] Added an option to disable syntax highlighting in code blocks. Simply add the -p or --plain_output tag to the command. This is a fix for issue #21 --- diff --git a/converters/base.py b/converters/base.py index 38c6921..bea6758 100755 --- a/converters/base.py +++ b/converters/base.py @@ -90,8 +90,9 @@ class Converter(object): # they have specific requirements. display_data_priority = ['pdf', 'svg', 'png', 'jpg', 'text'] - def __init__(self, infile): + def __init__(self, infile, highlight): self.infile = infile + self.highlight = highlight self.infile_dir, infile_root = os.path.split(infile) infile_root = os.path.splitext(infile_root)[0] self.clean_name = clean_filename(infile_root) diff --git a/converters/html.py b/converters/html.py index 0809949..ffee07c 100755 --- a/converters/html.py +++ b/converters/html.py @@ -102,7 +102,7 @@ class ConverterHTML(Converter): '
In [%s]:
' % n ) lines.append('
') - lines.append(highlight(cell.input)) + lines.append(highlight(cell.input) if self.highlight else cell.input) lines.append('
') # input_area lines.append('') # input diff --git a/nbconvert.py b/nbconvert.py index 01cef7b..5b7e6e8 100755 --- a/nbconvert.py +++ b/nbconvert.py @@ -45,7 +45,7 @@ known_formats = ', '.join([key + " (default)" if key == default_format else key for key in converters]) -def main(infile, format='rst', preamble=None, exclude=None): +def main(infile, highlight, format='rst', preamble=None, exclude=None): """Convert a notebook to html in one step""" try: ConverterClass = converters[format] @@ -53,7 +53,7 @@ def main(infile, format='rst', preamble=None, exclude=None): raise SystemExit("Unknown format '%s', " % format + "known formats are: " + known_formats) - converter = ConverterClass(infile) + converter = ConverterClass(infile, highlight) converter.render() #----------------------------------------------------------------------------- @@ -77,9 +77,10 @@ if __name__ == '__main__': help='Path to a user-specified preamble file') parser.add_argument('-e', '--exclude', default='', help='Comma-separated list of cells to exclude') - + parser.add_argument('-p', '--plain_output', action='store_false', + help='Plain output which will contain no syntax highlighting.') args = parser.parse_args() exclude_cells = [s.strip() for s in args.exclude.split(',')] - - main(infile=args.infile[0], format=args.format, - preamble=args.preamble, exclude=exclude_cells) + + main(infile=args.infile[0], highlight=args.plain_output, + format=args.format, preamble=args.preamble, exclude=exclude_cells)