diff --git a/IPython/core/interactiveshell.py b/IPython/core/interactiveshell.py index 835dc8d..54f9897 100644 --- a/IPython/core/interactiveshell.py +++ b/IPython/core/interactiveshell.py @@ -93,12 +93,17 @@ from IPython.utils.contexts import NoOpContext try: import docrepr.sphinxify as sphx - def sphinxify(doc): - with TemporaryDirectory() as dirname: - return { - 'text/html': sphx.sphinxify(doc, dirname), - 'text/plain': doc - } + def sphinxify(oinfo): + wrapped_docstring = sphx.wrap_main_docstring(oinfo) + + def sphinxify_docstring(docstring): + with TemporaryDirectory() as dirname: + return { + "text/html": sphx.sphinxify(wrapped_docstring, dirname), + "text/plain": docstring, + } + + return sphinxify_docstring except ImportError: sphinxify = None @@ -919,7 +924,7 @@ class InteractiveShell(SingletonConfigurable): while p.is_symlink(): p = Path(os.readlink(p)) paths.append(p.resolve()) - + # In Cygwin paths like "c:\..." and '\cygdrive\c\...' are possible if p_venv.parts[1] == "cygdrive": drive_name = p_venv.parts[2] @@ -1765,7 +1770,9 @@ class InteractiveShell(SingletonConfigurable): This function is meant to be called by pdef, pdoc & friends. """ info = self._object_find(oname, namespaces) - docformat = sphinxify if self.sphinxify_docstring else None + docformat = ( + sphinxify(self.object_inspect(oname)) if self.sphinxify_docstring else None + ) if info.found: pmethod = getattr(self.inspector, meth) # TODO: only apply format_screen to the plain/text repr of the mime @@ -1812,7 +1819,11 @@ class InteractiveShell(SingletonConfigurable): with self.builtin_trap: info = self._object_find(oname) if info.found: - docformat = sphinxify if self.sphinxify_docstring else None + docformat = ( + sphinxify(self.object_inspect(oname)) + if self.sphinxify_docstring + else None + ) return self.inspector._get_info( info.obj, oname,