##// END OF EJS Templates
More updates to comments and docstrings.
chebee7i -
Show More
@@ -217,10 +217,8 b' class IPythonConsoleLexer(Lexer):'
217 aliases = ['ipythoncon']
217 aliases = ['ipythoncon']
218 mimetypes = ['text/x-ipython-console']
218 mimetypes = ['text/x-ipython-console']
219
219
220 # The regexps used to determine what is input and what is output. The
220 # The regexps used to determine what is input and what is output.
221 # input regex should be consistent with and also be the combination of
221 # The default prompts for IPython are:
222 # the values of the `in_template` and `in2_templates`. For example, the
223 # defaults prompts are:
224 #
222 #
225 # c.PromptManager.in_template = 'In [\#]: '
223 # c.PromptManager.in_template = 'In [\#]: '
226 # c.PromptManager.in2_template = ' .\D.: '
224 # c.PromptManager.in2_template = ' .\D.: '
@@ -322,11 +320,24 b' class IPythonConsoleLexer(Lexer):'
322 self.buffer = u''
320 self.buffer = u''
323 self.insertions = []
321 self.insertions = []
324
322
325 def get_modecode(self, line):
323 def get_mci(self, line):
326 """
324 """
327 Returns the next mode and code to be added to the next mode's buffer.
325 Parses the line and returns a 3-tuple: (mode, code, insertion).
328
326
329 The next mode depends on current mode and contents of line.
327 `mode` is the next mode (or state) of the lexer, and is always equal
328 to 'input', 'output', or 'tb'.
329
330 `code` is a portion of the line that should be added to the buffer
331 corresponding to the next mode and eventually lexed by another lexer.
332 For example, `code` could be Python code if `mode` were 'input'.
333
334 `insertion` is a 3-tuple (index, token, text) representing an
335 unprocessed "token" that will be inserted into the stream of tokens
336 that are created from the buffer once we change modes. This is usually
337 the input or output prompt.
338
339 In general, the next mode depends on current mode and on the contents
340 of `line`.
330
341
331 """
342 """
332 # To reduce the number of regex match checks, we have multiple
343 # To reduce the number of regex match checks, we have multiple
@@ -436,7 +447,7 b' class IPythonConsoleLexer(Lexer):'
436 self.reset()
447 self.reset()
437 for match in line_re.finditer(text):
448 for match in line_re.finditer(text):
438 line = match.group()
449 line = match.group()
439 mode, code, insertion = self.get_modecode(line)
450 mode, code, insertion = self.get_mci(line)
440
451
441 if mode != self.mode:
452 if mode != self.mode:
442 # Yield buffered tokens before transitioning to new mode.
453 # Yield buffered tokens before transitioning to new mode.
@@ -27,19 +27,21 b' available at :module:`IPython.nbconvert.utils.lexers`. These include:'
27 Previously, the :class:`IPythonConsoleLexer` class was available at
27 Previously, the :class:`IPythonConsoleLexer` class was available at
28 :module:`IPython.sphinxext.ipython_console_hightlight`. It was inserted
28 :module:`IPython.sphinxext.ipython_console_hightlight`. It was inserted
29 into Pygments' list of available lexers under the name `ipython`. It should
29 into Pygments' list of available lexers under the name `ipython`. It should
30 be mentioned that this name is inaccurate. An IPython console session
30 be mentioned that this name is inaccurate, since an IPython console session
31 is not the same as IPython code (which itself is a superset of the Python
31 is not the same as IPython code (which itself is a superset of the Python
32 language).
32 language).
33
33
34 Now, the Sphinx extension inserts two console lexers into Pygment's list of
34 Now, the Sphinx extension inserts two console lexers into Pygments' list of
35 available lexers. Both are IPyLexer instances under the names: `ipython` and
35 available lexers. Both are IPyLexer instances under the names: `ipython` and
36 `ipython3`. As mentioned above, these names are misleading, but they are kept
36 `ipython3`. Although the names can be confusing (as mentioned above), their
37 for backwards compatibility and typical usage. If a project needs to make
37 continued use is, in part, to maintain backwards compatibility and to
38 Pygments aware of more than just the IPyLexer class, then one should not
38 aid typical usage. If a project needs to make Pygments aware of more than just
39 make the IPyLexer class available under the name `ipython` and use `ipy` or
39 the IPyLexer class, then one should not make the IPyLexer class available under
40 some other non-conflicting value.
40 the name `ipython` and use `ipy` or some other non-conflicting value.
41
41
42 Code blocks such as::
42 Code blocks such as:
43
44 .. code-block:: rst
43
45
44 .. code-block:: ipython
46 .. code-block:: ipython
45
47
@@ -47,7 +49,9 b' Code blocks such as::'
47 Out[1]: 4
49 Out[1]: 4
48
50
49 will continue to work as before, but now, they will also properly highlight
51 will continue to work as before, but now, they will also properly highlight
50 tracebacks. For pure IPython code, the same lexer will work::
52 tracebacks. For pure IPython code, the same lexer will also work:
53
54 .. code-block:: rst
51
55
52 .. code-block:: ipython
56 .. code-block:: ipython
53
57
@@ -55,4 +59,4 b' tracebacks. For pure IPython code, the same lexer will work::'
55 !echo $x
59 !echo $x
56
60
57 Since the first line of the block did not begin with a standard IPython console
61 Since the first line of the block did not begin with a standard IPython console
58 prompt, the entire block is assumed to be IPython code instead.
62 prompt, the entire block is assumed to consist of IPython code instead.
General Comments 0
You need to be logged in to leave comments. Login now