Add Jupyter notebook support (see #1058)

This commit is contained in:
ines 2017-05-14 18:39:01 +02:00
parent c31792aaec
commit a04550605a
2 changed files with 10 additions and 3 deletions

View File

@ -28,8 +28,12 @@ def render(docs, style='dep', page=False, minify=False, jupyter=False, options={
elif style is 'ent': elif style is 'ent':
renderer = EntityRenderer(options=options) renderer = EntityRenderer(options=options)
parsed = [parse_ents(doc, options) for doc in docs] parsed = [parse_ents(doc, options) for doc in docs]
_html['parsed'] = renderer.render(parsed, page=page, minify=minify) _html['parsed'] = renderer.render(parsed, page=page, minify=minify).strip()
return _html['parsed'] 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): def serve(docs, style='dep', page=True, minify=False, options={}, port=5000):

View File

@ -2,8 +2,11 @@
from __future__ import unicode_literals 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 = """ TPL_DEP_SVG = """
<svg xmlns="http://www.w3.org/2000/svg" id="{id}" class="displacy" width="{width}" height="{height}" style="color: {color}; background: {bg}; font-family: {font}">{content}</svg> <svg xmlns="http://www.w3.org/2000/svg" id="{id}" class="displacy" width="{width}" height="{height}" style="max-width: none; height: {height}px; color: {color}; background: {bg}; font-family: {font}">{content}</svg>
""" """