diff --git a/spacy/displacy/render.py b/spacy/displacy/render.py index f74222dc2..0ac81b631 100644 --- a/spacy/displacy/render.py +++ b/spacy/displacy/render.py @@ -300,6 +300,8 @@ class DependencyRenderer: self.lang = settings.get("lang", DEFAULT_LANG) render_id = f"{id_prefix}-{i}" svg = self.render_svg(render_id, p["words"], p["arcs"]) + if p.get("title"): + svg = TPL_TITLE.format(title=p.get("title")) + svg rendered.append(svg) if page: content = "".join([TPL_FIGURE.format(content=svg) for svg in rendered]) diff --git a/spacy/tests/test_displacy.py b/spacy/tests/test_displacy.py index 1f138494b..ea0a3cf0e 100644 --- a/spacy/tests/test_displacy.py +++ b/spacy/tests/test_displacy.py @@ -350,6 +350,7 @@ def test_displacy_render_manual_dep(): {"start": 2, "end": 3, "label": "det", "dir": "left"}, {"start": 1, "end": 3, "label": "attr", "dir": "right"}, ], + "title": "Title", } html = displacy.render([parsed_dep], style="dep", manual=True) for word in parsed_dep["words"]: diff --git a/website/docs/api/top-level.mdx b/website/docs/api/top-level.mdx index 47ce810ee..dcbec6a75 100644 --- a/website/docs/api/top-level.mdx +++ b/website/docs/api/top-level.mdx @@ -371,6 +371,7 @@ displaCy's different data formats below. | `words` | List of dictionaries describing a word token (see structure below). ~~List[Dict[str, Any]]~~ | | `arcs` | List of dictionaries describing the relations between words (see structure below). ~~List[Dict[str, Any]]~~ | | _Optional_ | | +| `title` | Title of the visualization. ~~Optional[str]~~ | | `settings` | Dependency Visualizer options (see [here](/api/top-level#displacy_options)). ~~Dict[str, Any]~~ |