Skip to content

Commit

Permalink
Wrap table cell content in paragraph node (#128)
Browse files Browse the repository at this point in the history
This is required by docutils/sphinx, which expects inline content to be within a block level parent. For example, for URL references (as noted in #127)
  • Loading branch information
martinagvilas committed Apr 15, 2020
1 parent c92b457 commit a24d7b2
Show file tree
Hide file tree
Showing 6 changed files with 124 additions and 34 deletions.
4 changes: 3 additions & 1 deletion myst_parser/docutils_renderer.py
Original file line number Diff line number Diff line change
Expand Up @@ -528,11 +528,13 @@ def render_table_row(self, token):
with self.current_node_context(row, append=True):
for child in token.children:
entry = nodes.entry()
para = nodes.paragraph("")
style = child.attrGet("style") # i.e. the alignment when using e.g. :--
if style:
entry["classes"].append(style)
with self.current_node_context(entry, append=True):
self.render_children(child)
with self.current_node_context(para, append=True):
self.render_children(child)

def render_math_inline(self, token):
content = token.content
Expand Down
12 changes: 8 additions & 4 deletions tests/test_renderers/fixtures/sphinx_directives.md
Original file line number Diff line number Diff line change
Expand Up @@ -285,15 +285,19 @@ table (`sphinx.directives.patches.RSTTable`):
<thead>
<row>
<entry>
a
<paragraph>
a
<entry>
b
<paragraph>
b
<tbody>
<row>
<entry>
1
<paragraph>
1
<entry>
2
<paragraph>
2
.

--------------------------------
Expand Down
82 changes: 64 additions & 18 deletions tests/test_renderers/fixtures/tables.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,19 @@ a|b
<thead>
<row>
<entry>
a
<paragraph>
a
<entry>
b
<paragraph>
b
<tbody>
<row>
<entry>
1
<paragraph>
1
<entry>
2
<paragraph>
2
.

--------------------------
Expand All @@ -40,19 +44,25 @@ a | b | c
<thead>
<row>
<entry classes="text-align:left">
a
<paragraph>
a
<entry classes="text-align:center">
b
<paragraph>
b
<entry classes="text-align:right">
c
<paragraph>
c
<tbody>
<row>
<entry classes="text-align:left">
1
<paragraph>
1
<entry classes="text-align:center">
2
<paragraph>
2
<entry classes="text-align:right">
3
<paragraph>
3
.

--------------------------
Expand All @@ -70,18 +80,54 @@ Nested syntax:
<thead>
<row>
<entry>
<emphasis>
<paragraph>
<emphasis>
a
<entry>
<paragraph>
<strong>
<emphasis>
b
<tbody>
<row>
<entry>
<paragraph>
<math>
1
<entry>
<paragraph>
<subscript>
x
.

--------------------------
External links:
.
a|b
|-|-|
[link-a](https://www.google.com/)|[link-b](https://www.python.org/)
.
<document source="notset">
<table classes="colwidths-auto">
<tgroup cols="2">
<colspec colwidth="50.0">
<colspec colwidth="50.0">
<thead>
<row>
<entry>
<paragraph>
a
<entry>
<strong>
<emphasis>
b
<paragraph>
b
<tbody>
<row>
<entry>
<math>
1
<paragraph>
<reference refuri="https://www.google.com/">
link-a
<entry>
<subscript>
x
<paragraph>
<reference refuri="https://www.python.org/">
link-b
.
1 change: 1 addition & 0 deletions tests/test_sphinx/sourcedirs/basic/content.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ $$c=2$$ (eq:label)
| a | b |
|-----|--:|
| *a* | 2 |
| [link-a](https://google.com) | [link-b](https://python.org) |

this
is
Expand Down
36 changes: 30 additions & 6 deletions tests/test_sphinx/test_sphinx_builds/test_basic.html
Original file line number Diff line number Diff line change
Expand Up @@ -104,22 +104,46 @@ <h1>
<thead>
<tr class="row-odd">
<th class="head">
a
<p>
a
</p>
</th>
<th class="text-align:right head">
b
<p>
b
</p>
</th>
</tr>
</thead>
<tbody>
<tr class="row-even">
<td>
<em>
a
</em>
<p>
<em>
a
</em>
</p>
</td>
<td class="text-align:right">
<p>
2
</p>
</td>
</tr>
<tr class="row-odd">
<td>
<p>
<a class="reference external" href="https://google.com">
link-a
</a>
</p>
</td>
<td class="text-align:right">
2
<p>
<a class="reference external" href="https://python.org">
link-b
</a>
</p>
</td>
</tr>
</tbody>
Expand Down
23 changes: 18 additions & 5 deletions tests/test_sphinx/test_sphinx_builds/test_basic.xml
Original file line number Diff line number Diff line change
Expand Up @@ -56,16 +56,29 @@
<thead>
<row>
<entry>
a
<paragraph>
a
<entry classes="text-align:right">
b
<paragraph>
b
<tbody>
<row>
<entry>
<emphasis>
a
<paragraph>
<emphasis>
a
<entry classes="text-align:right">
<paragraph>
2
<row>
<entry>
<paragraph>
<reference refuri="https://google.com">
link-a
<entry classes="text-align:right">
2
<paragraph>
<reference refuri="https://python.org">
link-b
<paragraph>
this

Expand Down

0 comments on commit a24d7b2

Please sign in to comment.