@@ -26,20 +26,19 @@ def _non_empty_keys(d:dict): return L([k for k,v in d.items() if v != inspect._e
2626def _bold (s ): return f'**{ s } **' if s .strip () else s
2727
2828# %% ../nbs/09_API/08_showdoc.ipynb 7
29- def _escape_pipe (s ): return re .sub (r'(\\)?\|' , '\|' , s )
29+ def _escape_markdown (s ):
30+ for c in '|^' : s = re .sub (rf'\\?\{ c } ' , f'\{ c } ' , s )
31+ return s .replace ('\n ' , '<br>' )
3032
3133# %% ../nbs/09_API/08_showdoc.ipynb 9
32- def _escape_fn (s ): return re .sub (r'(?<!\\)\^\[' , '\^[' , s )
33-
34- # %% ../nbs/09_API/08_showdoc.ipynb 11
3534def _maybe_nm (o ):
3635 if (o == inspect ._empty ): return ''
37- else : return o .__name__ if hasattr (o , '__name__' ) else _escape_fn ( _escape_pipe ( str (o ) ))
36+ else : return o .__name__ if hasattr (o , '__name__' ) else _escape_markdown ( str (o ))
3837
39- # %% ../nbs/09_API/08_showdoc.ipynb 13
38+ # %% ../nbs/09_API/08_showdoc.ipynb 11
4039def _list2row (l :list ): return '| ' + ' | ' .join ([_maybe_nm (o ) for o in l ]) + ' |'
4140
42- # %% ../nbs/09_API/08_showdoc.ipynb 15
41+ # %% ../nbs/09_API/08_showdoc.ipynb 13
4342class DocmentTbl :
4443 # this is the column order we want these items to appear
4544 _map = OrderedDict ({'anno' :'Type' , 'default' :'Default' , 'docment' :'Details' })
@@ -109,7 +108,12 @@ def __eq__(self,other): return self.__str__() == str(other).strip()
109108 __str__ = _repr_markdown_
110109 __repr__ = basic_repr ()
111110
112- # %% ../nbs/09_API/08_showdoc.ipynb 30
111+ # %% ../nbs/09_API/08_showdoc.ipynb 28
112+ def _docstring (sym ):
113+ npdoc = parse_docstring (sym )
114+ return '\n \n ' .join ([npdoc ['Summary' ], npdoc ['Extended' ]]).strip ()
115+
116+ # %% ../nbs/09_API/08_showdoc.ipynb 29
113117def _fullname (o ):
114118 module ,name = getattr (o , "__module__" , None ),qual_name (o )
115119 return name if module is None or module in ('__main__' ,'builtins' ) else module + '.' + name
@@ -124,13 +128,13 @@ def __init__(self, sym, name:str|None=None, title_level:int=3):
124128 self .isfunc = inspect .isfunction (sym )
125129 try : self .sig = signature_ex (sym , eval_str = True )
126130 except (ValueError ,TypeError ): self .sig = None
127- self .docs = docstring (sym )
131+ self .docs = _docstring (sym )
128132 self .dm = DocmentTbl (sym )
129133 self .fn = _fullname (sym )
130134
131135 __repr__ = basic_repr ()
132136
133- # %% ../nbs/09_API/08_showdoc.ipynb 31
137+ # %% ../nbs/09_API/08_showdoc.ipynb 30
134138def _f_name (o ): return f'<function { o .__name__ } >' if isinstance (o , FunctionType ) else None
135139def _fmt_anno (o ): return inspect .formatannotation (o ).strip ("'" ).replace (' ' ,'' )
136140
@@ -143,7 +147,7 @@ def _show_param(param):
143147 if default is not inspect ._empty : res += f'={ _f_name (default ) or repr (default )} '
144148 return res
145149
146- # %% ../nbs/09_API/08_showdoc.ipynb 33
150+ # %% ../nbs/09_API/08_showdoc.ipynb 32
147151def _fmt_sig (sig ):
148152 if sig is None : return ''
149153 p = {k :v for k ,v in sig .parameters .items ()}
@@ -156,7 +160,7 @@ def _wrap_sig(s):
156160 indent = pad + ' ' * (s .find ('(' ) + 1 )
157161 return fill (s , width = 80 , initial_indent = pad , subsequent_indent = indent )
158162
159- # %% ../nbs/09_API/08_showdoc.ipynb 35
163+ # %% ../nbs/09_API/08_showdoc.ipynb 34
160164def _ext_link (url , txt , xtra = "" ): return f'[{ txt } ]({ url } ){{target="_blank" { xtra } }}'
161165
162166class BasicMarkdownRenderer (ShowDocRenderer ):
@@ -174,7 +178,7 @@ def _repr_markdown_(self):
174178 return doc
175179 __repr__ = __str__ = _repr_markdown_
176180
177- # %% ../nbs/09_API/08_showdoc.ipynb 36
181+ # %% ../nbs/09_API/08_showdoc.ipynb 35
178182def show_doc (sym , # Symbol to document
179183 renderer = None , # Optional renderer (defaults to markdown)
180184 name :str | None = None , # Optionally override displayed name of `sym`
@@ -188,7 +192,7 @@ def show_doc(sym, # Symbol to document
188192 if isinstance (sym , TypeDispatch ): pass
189193 else :return renderer (sym or show_doc , name = name , title_level = title_level )
190194
191- # %% ../nbs/09_API/08_showdoc.ipynb 52
195+ # %% ../nbs/09_API/08_showdoc.ipynb 51
192196def _html_link (url , txt ): return f'<a href="{ url } " target="_blank" rel="noreferrer noopener">{ txt } </a>'
193197
194198class BasicHtmlRenderer (ShowDocRenderer ):
@@ -208,17 +212,17 @@ def doc(self):
208212 if docs is not None : res += '\n <p>' + _html_link (docs , "Show in docs" ) + '</p>'
209213 display (HTML (res ))
210214
211- # %% ../nbs/09_API/08_showdoc.ipynb 53
215+ # %% ../nbs/09_API/08_showdoc.ipynb 52
212216def doc (elt ):
213217 "Show `show_doc` info along with link to docs"
214218 BasicHtmlRenderer (elt ).doc ()
215219
216- # %% ../nbs/09_API/08_showdoc.ipynb 59
220+ # %% ../nbs/09_API/08_showdoc.ipynb 58
217221def showdoc_nm (tree ):
218222 "Get the fully qualified name for showdoc."
219223 return ifnone (patch_name (tree ), tree .name )
220224
221- # %% ../nbs/09_API/08_showdoc.ipynb 63
225+ # %% ../nbs/09_API/08_showdoc.ipynb 62
222226def colab_link (path ):
223227 "Get a link to the notebook at `path` on Colab"
224228 from IPython .display import Markdown
0 commit comments