An IPython console lexer for IPython code-blocks and doctests, such as: .. code-block:: rst .. code-block:: ipythonconsole In [1]: a = 'foo' In [2]: a Out[2]: 'foo' In [3]: print a foo In [4]: 1 / 0
| 209 | IPythonPartialTracebackLexer, **options) |
| 210 | |
| 211 | class IPythonConsoleLexer(Lexer): |
| 212 | """ |
| 213 | An IPython console lexer for IPython code-blocks and doctests, such as: |
| 214 | |
| 215 | .. code-block:: rst |
| 216 | |
| 217 | .. code-block:: ipythonconsole |
| 218 | |
| 219 | In [1]: a = 'foo' |
| 220 | |
| 221 | In [2]: a |
| 222 | Out[2]: 'foo' |
| 223 | |
| 224 | In [3]: print a |
| 225 | foo |
| 226 | |
| 227 | In [4]: 1 / 0 |
| 228 | |
| 229 | |
| 230 | Support is also provided for IPython exceptions: |
| 231 | |
| 232 | .. code-block:: rst |
| 233 | |
| 234 | .. code-block:: ipythonconsole |
| 235 | |
| 236 | In [1]: raise Exception |
| 237 | |
| 238 | --------------------------------------------------------------------------- |
| 239 | Exception Traceback (most recent call last) |
| 240 | <ipython-input-1-fca2ab0ca76b> in <module> |
| 241 | ----> 1 raise Exception |
| 242 | |
| 243 | Exception: |
| 244 | |
| 245 | """ |
| 246 | name = 'IPython console session' |
| 247 | aliases = ['ipythonconsole'] |
| 248 | mimetypes = ['text/x-ipython-console'] |
| 249 | |
| 250 | # The regexps used to determine what is input and what is output. |
| 251 | # The default prompts for IPython are: |
| 252 | # |
| 253 | # in = 'In [#]: ' |
| 254 | # continuation = ' .D.: ' |
| 255 | # template = 'Out[#]: ' |
| 256 | # |
| 257 | # Where '#' is the 'prompt number' or 'execution count' and 'D' |
| 258 | # D is a number of dots matching the width of the execution count |
| 259 | # |
| 260 | in1_regex = r'In \[[0-9]+\]: ' |
| 261 | in2_regex = r' \.\.+\.: ' |
| 262 | out_regex = r'Out\[[0-9]+\]: ' |
| 263 | |
| 264 | #: The regex to determine when a traceback starts. |
| 265 | ipytb_start = re.compile(r'^(\^C)?(-+\n)|^( File)(.*)(, line )(\d+\n)') |
| 266 | |
| 267 | def __init__(self, **options): |
| 268 | """Initialize the IPython console lexer. |