Skip to content

Commit

Permalink
Fix #2045
Browse files Browse the repository at this point in the history
  • Loading branch information
sgugger committed May 7, 2019
1 parent 599aff8 commit 21faa5d
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
10 changes: 7 additions & 3 deletions fastai/gen_doc/nbdoc.py
@@ -1,6 +1,6 @@
"`gen_doc.nbdoc` generates notebook documentation from module functions and links to correct places"

import inspect,importlib,enum,os,re
import inspect,importlib,enum,os,re,nbconvert
from IPython.core.display import display, Markdown, HTML
from nbconvert import HTMLExporter
from IPython.core import page
Expand All @@ -12,7 +12,7 @@
from .nbtest import get_pytest_html
from ..utils.ipython import IS_IN_COLAB

__all__ = ['get_fn_link', 'link_docstring', 'show_doc', 'get_ft_names',
__all__ = ['get_fn_link', 'link_docstring', 'show_doc', 'get_ft_names', 'md2thml'

This comment has been minimized.

Copy link
@daniel-rios

daniel-rios Sep 6, 2019

I think there is typo: md2thml to md2html

This comment has been minimized.

Copy link
@sgugger

sgugger Sep 6, 2019

Author Contributor

Yes, it's been fixed in a later commit.

'get_exports', 'show_video', 'show_video_from_youtube', 'import_mod', 'get_source_link',
'is_enum', 'jekyll_note', 'jekyll_warn', 'jekyll_important', 'doc']

Expand Down Expand Up @@ -123,6 +123,10 @@ def show_doc(elt, doc_string:bool=True, full_name:str=None, arg_comments:dict=No
if markdown: display(Markdown(doc))
else: return doc

def md2html(md):
if nbconvert.__version__ < '5.5.0': return HTMLExporter().markdown2html(md)
else: return HTMLExporter().markdown2html(defaultdict(lambda: defaultdict(dict)), md)

def doc(elt):
"Show `show_doc` info in preview window along with link to full docs."
global use_relative_links
Expand All @@ -131,7 +135,7 @@ def doc(elt):
md = show_doc(elt, markdown=False)
if is_fastai_class(elt):
md += f'\n\n<a href="{get_fn_link(elt)}" target="_blank" rel="noreferrer noopener">Show in docs</a>'
output = HTMLExporter().markdown2html(md)
output = md2html(md)
use_relative_links = True
if IS_IN_COLAB: get_ipython().run_cell_magic(u'html', u'', output)
else:
Expand Down
4 changes: 2 additions & 2 deletions fastai/gen_doc/nbtest.py
Expand Up @@ -25,7 +25,7 @@ def show_test(elt)->str:
def doctest(elt):
"Inline notebook popup for `show_test`"
md = build_tests_markdown(elt)
output = HTMLExporter().markdown2html(md)
output = nbdoc.md2html(md)
try: page.page({'text/html': output})
except: display(Markdown(md))

Expand Down Expand Up @@ -54,7 +54,7 @@ def tests2md(tests, type_label:str):

def get_pytest_html(elt, anchor_id:str)->Tuple[str,str]:
md = build_tests_markdown(elt)
html = HTMLExporter().markdown2html(md).replace('\n','') # nbconverter fails to parse markdown if it has both html and '\n'
html = nbdoc.md2html(md).replace('\n','') # nbconverter fails to parse markdown if it has both html and '\n'
anchor_id = anchor_id.replace('.', '-') + '-pytest'
link, body = get_pytest_card(html, anchor_id)
return link, body
Expand Down

0 comments on commit 21faa5d

Please sign in to comment.