Skip to content

Commit

Permalink
Add title to image node
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisjsewell committed Mar 30, 2020
1 parent e64898a commit d53a9b5
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 8 deletions.
10 changes: 8 additions & 2 deletions myst_parser/docutils_renderer.py
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,11 @@ def render_children(self, token):
if f"render_{child.type}" in self.rules:
self.rules[f"render_{child.type}"](child)
else:
print(f"no render method for: {child.type}")
self.current_node.append(
self.reporter.warning(
f"No render method for: {child.type}", line=child.map[0]
)
)

def add_line_and_source_path(self, node, token):
"""Copy the line number and document source path to the docutils node."""
Expand Down Expand Up @@ -437,7 +441,9 @@ def render_image(self, token):
# TODO ideally we would render proper markup here,
# this probably requires an upstream change in sphinx
img_node["alt"] = self.renderInlineAsText(token.children)

title = token.attrGet("title")
if title:
img_node["title"] = token.attrGet("title")
self.current_node.append(img_node)

# ### render methods for plugin tokens
Expand Down
4 changes: 3 additions & 1 deletion tests/test_renderers/fixtures/docutil_directives.md
Original file line number Diff line number Diff line change
Expand Up @@ -294,10 +294,12 @@ a
image (`docutils.parsers.rst.directives.images.Image`):
.
```{image} path/to/image
:alt: abc
:name: name
```
.
<document source="notset">
<image uri="path/to/image">
<image alt="abc" ids="name" names="name" uri="path/to/image">
.

--------------------------------
Expand Down
13 changes: 9 additions & 4 deletions tests/test_renderers/fixtures/sphinx_directives.md
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ figure (`sphinx.directives.patches.Figure`):
.
```{figure} path/to/figure
caption
*caption*
legend
```
Expand All @@ -245,7 +245,8 @@ legend
<figure>
<image uri="path/to/figure">
<caption>
caption
<emphasis>
caption
<legend>
<paragraph>
legend
Expand All @@ -265,15 +266,19 @@ foo
--------------------------------
table (`sphinx.directives.patches.RSTTable`):
.
```{table}
```{table} *title*
:name: name
| a | b |
|---|---|
| 1 | 2 |
```
.
<document source="notset">
<table classes="colwidths-auto">
<table classes="colwidths-auto" ids="name" names="name">
<title>
<emphasis>
title
<tgroup cols="2">
<colspec colwidth="50.0">
<colspec colwidth="50.0">
Expand Down
2 changes: 1 addition & 1 deletion tests/test_renderers/fixtures/syntax_elements.md
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ Image with alt and title:
.
<document source="notset">
<paragraph>
<image alt="alt" uri="src">
<image alt="alt" title="title" uri="src">
.

--------------------------
Expand Down

0 comments on commit d53a9b5

Please sign in to comment.