" for cell in split_row(line)] for line in lines[2:]]
+
+ return f'''
+
{' '.join(header)}
+ {''.join(f'
{" ".join(row)}
' for row in rows)}
+
'''
+
# %% ../nbs/api/08_showdoc.ipynb
def _html_link(url, txt): return f'{txt}'
class BasicHtmlRenderer(ShowDocRenderer):
- "Simple HTML renderer for `show_doc`"
+ "HTML renderer for `show_doc`"
def _repr_html_(self):
doc = '\n'
+ src = NbdevLookup().code(self.fn)
+ if src:
+ doc += f'
{_html_link(src, "source")}
\n'
doc += f'{self.nm}\n'
- doc += f'
{self.nm}{_fmt_sig(self.sig)}
'
- if self.docs: doc += f"
{self.docs}
"
+ sig = _fmt_sig(self.sig) if self.sig else ''
+ # Escape < and > characters in the signature
+ sig = sig.replace('<', '<').replace('>', '>')
+ doc += f'
{self.nm} {sig}
'
+ if self.docs:
+ doc += f"
{self.docs}
"
+ if self.dm.has_docment:
+ doc += _create_html_table(str(self.dm))
return doc
def doc(self):
"Show `show_doc` info along with link to docs"
from IPython.display import display,HTML
res = self._repr_html_()
- docs = NbdevLookup().doc(self.fn)
- if docs is not None: res += '\n
' +_html_link(docs, "Show in docs") + '
'
display(HTML(res))
# %% ../nbs/api/08_showdoc.ipynb
diff --git a/nbs/api/08_showdoc.ipynb b/nbs/api/08_showdoc.ipynb
index 76452eea0..4fbbd7e2a 100644
--- a/nbs/api/08_showdoc.ipynb
+++ b/nbs/api/08_showdoc.ipynb
@@ -957,6 +957,31 @@
"You can replace the default markdown show_doc renderer with custom renderers. For instance, nbdev comes with a simple example for rendering with raw HTML."
]
},
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "id": "9a6c4f96",
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "#| export\n",
+ "def _create_html_table(table_str):\n",
+ " def split_row(row):\n",
+ " return re.findall(r'\\|(?:(?:\\\\.|[^|\\\\])*)', row)\n",
+ " \n",
+ " def unescape_cell(cell): \n",
+ " return cell.strip(' *|').replace(r'\\|', '|')\n",
+ " \n",
+ " lines = table_str.strip().split('\\n')\n",
+ " header = [f\"
{unescape_cell(cell)}
\" for cell in split_row(lines[0])]\n",
+ " rows = [[f\"
{unescape_cell(cell)}
\" for cell in split_row(line)] for line in lines[2:]]\n",
+ " \n",
+ " return f'''
\\n'\n",
" doc += f'{self.nm}\\n'\n",
- " doc += f'
{self.nm}{_fmt_sig(self.sig)}
'\n",
- " if self.docs: doc += f\"
{self.docs}
\"\n",
+ " sig = _fmt_sig(self.sig) if self.sig else ''\n",
+ " # Escape < and > characters in the signature\n",
+ " sig = sig.replace('<', '<').replace('>', '>')\n",
+ " doc += f'
{self.nm} {sig}
'\n",
+ " if self.docs:\n",
+ " doc += f\"
{self.docs}
\"\n",
+ " if self.dm.has_docment:\n",
+ " doc += _create_html_table(str(self.dm))\n",
" return doc\n",
"\n",
" def doc(self):\n",
" \"Show `show_doc` info along with link to docs\"\n",
" from IPython.display import display,HTML\n",
" res = self._repr_html_()\n",
- " docs = NbdevLookup().doc(self.fn)\n",
- " if docs is not None: res += '\\n