Show More
@@ -20,30 +20,77 b' Authors:' | |||
|
20 | 20 | # Imports |
|
21 | 21 | #----------------------------------------------------------------------------- |
|
22 | 22 | |
|
23 | # Third-party | |
|
24 | try: | |
|
25 | from docutils.core import publish_string | |
|
26 | except ImportError: | |
|
27 | # html paging won't be available, but we don't raise any errors. It's a | |
|
28 | # purely optional feature. | |
|
29 | pass | |
|
30 | ||
|
31 | # Our own | |
|
23 | 32 | from IPython.core.interactiveshell import InteractiveShell |
|
24 | 33 | |
|
25 | 34 | #----------------------------------------------------------------------------- |
|
26 | 35 | # Classes and functions |
|
27 | 36 | #----------------------------------------------------------------------------- |
|
28 | 37 | |
|
29 |
def page(strng, start=0, screen_lines=0, pager_cmd=None |
|
|
38 | def page(strng, start=0, screen_lines=0, pager_cmd=None, | |
|
39 | html=None, auto_html=False): | |
|
30 | 40 | """Print a string, piping through a pager. |
|
31 | 41 | |
|
32 | 42 | This version ignores the screen_lines and pager_cmd arguments and uses |
|
33 | 43 | IPython's payload system instead. |
|
44 | ||
|
45 | Parameters | |
|
46 | ---------- | |
|
47 | strng : str | |
|
48 | Text to page. | |
|
49 | ||
|
50 | start : int | |
|
51 | Starting line at which to place the display. | |
|
52 | ||
|
53 | html : str, optional | |
|
54 | If given, an html string to send as well. | |
|
55 | ||
|
56 | auto_html : bool, optional | |
|
57 | If true, the input string is assumed to be valid reStructuredText and is | |
|
58 | converted to HTML with docutils. Note that if docutils is not found, | |
|
59 | this option is silently ignored. | |
|
60 | ||
|
61 | Note | |
|
62 | ---- | |
|
63 | ||
|
64 | Only one of the ``html`` and ``auto_html`` options can be given, not | |
|
65 | both. | |
|
34 | 66 | """ |
|
35 | 67 | |
|
36 | 68 | # Some routines may auto-compute start offsets incorrectly and pass a |
|
37 | 69 | # negative value. Offset to 0 for robustness. |
|
38 | 70 | start = max(0, start) |
|
39 | 71 | shell = InteractiveShell.instance() |
|
72 | ||
|
73 | if auto_html: | |
|
74 | try: | |
|
75 | # These defaults ensure user configuration variables for docutils | |
|
76 | # are not loaded, only our config is used here. | |
|
77 | defaults = {'file_insertion_enabled': 0, | |
|
78 | 'raw_enabled': 0, | |
|
79 | '_disable_config': 1} | |
|
80 | html = publish_string(strng, writer_name='html', | |
|
81 | settings_overrides=defaults) | |
|
82 | except: | |
|
83 | pass | |
|
84 | ||
|
40 | 85 | payload = dict( |
|
41 | 86 | source='IPython.zmq.page.page', |
|
42 |
|
|
|
87 | text=strng, | |
|
88 | html=html, | |
|
43 | 89 | start_line_number=start |
|
44 | ) | |
|
90 | ) | |
|
45 | 91 | shell.payload_manager.write_payload(payload) |
|
46 | 92 | |
|
93 | ||
|
47 | 94 | def install_payload_page(): |
|
48 | 95 | """Install this version of page as IPython.core.page.page.""" |
|
49 | 96 | from IPython.core import page as corepage |
@@ -430,7 +430,7 b' class IPythonWidget(FrontendWidget):' | |||
|
430 | 430 | self.exit_requested.emit() |
|
431 | 431 | |
|
432 | 432 | def _handle_payload_page(self, item): |
|
433 |
self._page(item[' |
|
|
433 | self._page(item['text']) | |
|
434 | 434 | |
|
435 | 435 | #------ Trait change handlers --------------------------------------------- |
|
436 | 436 |
@@ -539,7 +539,7 b' class ZMQInteractiveShell(InteractiveShell):' | |||
|
539 | 539 | def magic_guiref(self, arg_s): |
|
540 | 540 | """Show a basic reference about the GUI console.""" |
|
541 | 541 | from IPython.core.usage import gui_reference |
|
542 | page.page(gui_reference) | |
|
542 | page.page(gui_reference, auto_html=True) | |
|
543 | 543 | |
|
544 | 544 | |
|
545 | 545 | InteractiveShellABC.register(ZMQInteractiveShell) |
General Comments 0
You need to be logged in to leave comments.
Login now