diff --git a/spacy/displacy/__init__.py b/spacy/displacy/__init__.py index f5216ccfc..e84ba376d 100644 --- a/spacy/displacy/__init__.py +++ b/spacy/displacy/__init__.py @@ -28,8 +28,12 @@ def render(docs, style='dep', page=False, minify=False, jupyter=False, options={ elif style is 'ent': renderer = EntityRenderer(options=options) parsed = [parse_ents(doc, options) for doc in docs] - _html['parsed'] = renderer.render(parsed, page=page, minify=minify) - return _html['parsed'] + _html['parsed'] = renderer.render(parsed, page=page, minify=minify).strip() + html = _html['parsed'] + if jupyter: # return HTML rendered by IPython display() + from IPython.core.display import display, HTML + return display(HTML(html)) + return html def serve(docs, style='dep', page=True, minify=False, options={}, port=5000): diff --git a/spacy/displacy/templates.py b/spacy/displacy/templates.py index 5cbcba98d..bdbdee459 100644 --- a/spacy/displacy/templates.py +++ b/spacy/displacy/templates.py @@ -2,8 +2,11 @@ from __future__ import unicode_literals +# setting explicit height and max-width: none on the SVG is required for +# Jupyter to render it properly in a cell + TPL_DEP_SVG = """ -{content} +{content} """