From c45c890a4502977d0b461e1d3587d25356d79424 2010-09-13 02:14:16 From: Fernando Perez Date: 2010-09-13 02:14:16 Subject: [PATCH] Provide html support for page() in the payload version. %guiref now uses it. --- diff --git a/IPython/core/payloadpage.py b/IPython/core/payloadpage.py old mode 100644 new mode 100755 index 2ec73e2..363eddb --- a/IPython/core/payloadpage.py +++ b/IPython/core/payloadpage.py @@ -20,30 +20,77 @@ Authors: # Imports #----------------------------------------------------------------------------- +# Third-party +try: + from docutils.core import publish_string +except ImportError: + # html paging won't be available, but we don't raise any errors. It's a + # purely optional feature. + pass + +# Our own from IPython.core.interactiveshell import InteractiveShell #----------------------------------------------------------------------------- # Classes and functions #----------------------------------------------------------------------------- -def page(strng, start=0, screen_lines=0, pager_cmd=None): +def page(strng, start=0, screen_lines=0, pager_cmd=None, + html=None, auto_html=False): """Print a string, piping through a pager. This version ignores the screen_lines and pager_cmd arguments and uses IPython's payload system instead. + + Parameters + ---------- + strng : str + Text to page. + + start : int + Starting line at which to place the display. + + html : str, optional + If given, an html string to send as well. + + auto_html : bool, optional + If true, the input string is assumed to be valid reStructuredText and is + converted to HTML with docutils. Note that if docutils is not found, + this option is silently ignored. + + Note + ---- + + Only one of the ``html`` and ``auto_html`` options can be given, not + both. """ # Some routines may auto-compute start offsets incorrectly and pass a # negative value. Offset to 0 for robustness. start = max(0, start) shell = InteractiveShell.instance() + + if auto_html: + try: + # These defaults ensure user configuration variables for docutils + # are not loaded, only our config is used here. + defaults = {'file_insertion_enabled': 0, + 'raw_enabled': 0, + '_disable_config': 1} + html = publish_string(strng, writer_name='html', + settings_overrides=defaults) + except: + pass + payload = dict( source='IPython.zmq.page.page', - data=strng, + text=strng, + html=html, start_line_number=start - ) + ) shell.payload_manager.write_payload(payload) + def install_payload_page(): """Install this version of page as IPython.core.page.page.""" from IPython.core import page as corepage diff --git a/IPython/frontend/qt/console/ipython_widget.py b/IPython/frontend/qt/console/ipython_widget.py index 8ec67ee..94c7159 100644 --- a/IPython/frontend/qt/console/ipython_widget.py +++ b/IPython/frontend/qt/console/ipython_widget.py @@ -430,7 +430,7 @@ class IPythonWidget(FrontendWidget): self.exit_requested.emit() def _handle_payload_page(self, item): - self._page(item['data']) + self._page(item['text']) #------ Trait change handlers --------------------------------------------- diff --git a/IPython/zmq/zmqshell.py b/IPython/zmq/zmqshell.py index d705e64..37e8e7d 100644 --- a/IPython/zmq/zmqshell.py +++ b/IPython/zmq/zmqshell.py @@ -539,7 +539,7 @@ class ZMQInteractiveShell(InteractiveShell): def magic_guiref(self, arg_s): """Show a basic reference about the GUI console.""" from IPython.core.usage import gui_reference - page.page(gui_reference) + page.page(gui_reference, auto_html=True) InteractiveShellABC.register(ZMQInteractiveShell)