Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions nbdev/_nbdev.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,9 @@
"diff_nb_script": "01_sync.ipynb",
"is_enum": "02_showdoc.ipynb",
"is_lib_module": "02_showdoc.ipynb",
"re_digits_first": "02_showdoc.ipynb",
"try_external_doc_link": "02_showdoc.ipynb",
"is_doc_name": "02_showdoc.ipynb",
"doc_link": "02_showdoc.ipynb",
"add_doc_links": "02_showdoc.ipynb",
"get_source_link": "02_showdoc.ipynb",
Expand Down
5 changes: 1 addition & 4 deletions nbdev/export2html.py
Original file line number Diff line number Diff line change
Expand Up @@ -512,13 +512,10 @@ def nbdev_exporter(cls=HTMLExporter, template_file=None):
process_cells = [remove_fake_headers, remove_hidden, remove_empty]
process_cell = [hide_cells, collapse_cells, remove_widget_state, add_jekyll_notes, escape_latex, cite2link]

# Cell
_re_digits = re.compile(r'^\d+\S*?_')

# Cell
def _nb2htmlfname(nb_path, dest=None):
if dest is None: dest = Config().doc_path
return Path(dest)/_re_digits.sub('', nb_path.with_suffix('.html').name)
return Path(dest)/re_digits_first.sub('', nb_path.with_suffix('.html').name)

# Cell
def convert_nb(fname, cls=HTMLExporter, template_file=None, exporter=None, dest=None):
Expand Down
33 changes: 22 additions & 11 deletions nbdev/showdoc.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# AUTOGENERATED! DO NOT EDIT! File to edit: nbs/02_showdoc.ipynb (unless otherwise specified).

__all__ = ['is_enum', 'is_lib_module', 'try_external_doc_link', 'doc_link', 'add_doc_links', 'get_source_link',
'colab_link', 'get_nb_source_link', 'nb_source_link', 'type_repr', 'format_param', 'show_doc',
'parse_nbdev_show_doc', 'nbdev_show_doc', 'md2html', 'get_doc_link', 'doc']
__all__ = ['is_enum', 'is_lib_module', 're_digits_first', 'try_external_doc_link', 'is_doc_name', 'doc_link',
'add_doc_links', 'get_source_link', 'colab_link', 'get_nb_source_link', 'nb_source_link', 'type_repr',
'format_param', 'show_doc', 'parse_nbdev_show_doc', 'nbdev_show_doc', 'md2html', 'get_doc_link', 'doc']

# Cell
from .imports import *
Expand Down Expand Up @@ -30,7 +30,7 @@ def is_lib_module(name):
except: return False

# Cell
_re_digits_first = re.compile('^[0-9]+[a-z]*_')
re_digits_first = re.compile('^[0-9]+[a-z]*_')

# Cell
def try_external_doc_link(name, packages):
Expand All @@ -40,21 +40,28 @@ def try_external_doc_link(name, packages):
mod = importlib.import_module(f"{p}._nbdev")
try_pack = source_nb(name, is_name=True, mod=mod)
if try_pack:
page = _re_digits_first.sub('', try_pack).replace('.ipynb', '')
page = re_digits_first.sub('', try_pack).replace('.ipynb', '')
return f'{mod.doc_url}{page}#{name}'
except ModuleNotFoundError: return None

# Cell
def is_doc_name(name):
"Test if `name` corresponds to a notebook that could be converted to a doc page"
for f in Config().nbs_path.glob(f'*{name}.ipynb'):
if re_digits_first.sub('', f.name) == f'{name}.ipynb': return True
return False

# Cell
def doc_link(name, include_bt=True):
"Create link to documentation for `name`."
cname = f'`{name}`' if include_bt else name
try:
#Link to modulesn
if is_lib_module(name): return f"[{cname}]({Config().doc_baseurl}{name}.html)"
#Link to modules
if is_lib_module(name) and is_doc_name(name): return f"[{cname}]({Config().doc_baseurl}{name}.html)"
#Link to local functions
try_local = source_nb(name, is_name=True)
if try_local:
page = _re_digits_first.sub('', try_local).replace('.ipynb', '')
page = re_digits_first.sub('', try_local).replace('.ipynb', '')
return f'[{cname}]({Config().doc_baseurl}{page}.html#{name})'
##Custom links
mod = get_nbdev_module()
Expand All @@ -81,9 +88,13 @@ def doc_link(name, include_bt=True):
""", re.VERBOSE)

# Cell
def add_doc_links(text):
def add_doc_links(text, elt=None):
"Search for doc links for any item between backticks in `text` and isnter them"
def _replace_link(m): return doc_link(m.group(1) or m.group(2))
def _replace_link(m):
try:
if m.group(2) in inspect.signature(elt).parameters: return f'`{m.group(2)}`'
except: pass
return doc_link(m.group(1) or m.group(2))
return _re_backticks.sub(_replace_link, text)

# Cell
Expand Down Expand Up @@ -253,7 +264,7 @@ def show_doc(elt, doc_string=True, name=None, title_level=None, disp=True, defau
try: monospace = (Config().get('monospace_docstrings') == 'True')
except: monospace = False
# doc links don't work inside markdown pre/code blocks
s = f'```\n{s}\n```' if monospace else add_doc_links(s)
s = f'```\n{s}\n```' if monospace else add_doc_links(s, elt)
doc += s
if disp: display(Markdown(doc))
else: return doc
Expand Down
Loading