From 75b63aee7d7b2d3c6049e4972b50271d0e409563 2013-07-17 22:27:48 From: Jonathan Frederic Date: 2013-07-17 22:27:48 Subject: [PATCH] Fix, ansi2latex style-less code support Allow ansi2latex function to recognize ansi codes without styles --- diff --git a/IPython/nbconvert/filters/ansi.py b/IPython/nbconvert/filters/ansi.py index 3177bd2..7ea9ecc 100644 --- a/IPython/nbconvert/filters/ansi.py +++ b/IPython/nbconvert/filters/ansi.py @@ -111,12 +111,22 @@ def single_ansi2latex(code): Return latex code and number of open brackets. """ for color in coloransi.color_templates: - colcode = getattr(coloransi.TermColors,color[0]) + + #Make sure to get the color code (which is a part of the overall style) + # i.e. 0;31 is valid + # 31 is also valid, and means the same thing + #coloransi.color_templates stores the longer of the two formats %d;%d + #Get the short format so we can parse that too. Short format only exist + #if no other formating is applied (the other number must be a 0)! + style_code = getattr(coloransi.TermColors, color[0]) + color_code = style_code.split(';')[1] + is_normal = style_code.split(';')[0] == '0' + # regular fonts - if code == colcode: + if (code == style_code) or (is_normal and code == color_code): return '\\'+color[0].lower()+'{', 1 # bold fonts - if code == colcode[:3]+str(1)+colcode[3:]: + if code == style_code[:3]+str(1)+style_code[3:]: return '\\textbf{\\textcolor{'+color[0].lower()+'}{', 2 return '', 0