Skip to content

Commit a24d7b2

Browse files
Wrap table cell content in paragraph node (#128)
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)
1 parent c92b457 commit a24d7b2

File tree

6 files changed

+124
-34
lines changed

6 files changed

+124
-34
lines changed

myst_parser/docutils_renderer.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -528,11 +528,13 @@ def render_table_row(self, token):
528528
with self.current_node_context(row, append=True):
529529
for child in token.children:
530530
entry = nodes.entry()
531+
para = nodes.paragraph("")
531532
style = child.attrGet("style") # i.e. the alignment when using e.g. :--
532533
if style:
533534
entry["classes"].append(style)
534535
with self.current_node_context(entry, append=True):
535-
self.render_children(child)
536+
with self.current_node_context(para, append=True):
537+
self.render_children(child)
536538

537539
def render_math_inline(self, token):
538540
content = token.content

tests/test_renderers/fixtures/sphinx_directives.md

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -285,15 +285,19 @@ table (`sphinx.directives.patches.RSTTable`):
285285
<thead>
286286
<row>
287287
<entry>
288-
a
288+
<paragraph>
289+
a
289290
<entry>
290-
b
291+
<paragraph>
292+
b
291293
<tbody>
292294
<row>
293295
<entry>
294-
1
296+
<paragraph>
297+
1
295298
<entry>
296-
2
299+
<paragraph>
300+
2
297301
.
298302

299303
--------------------------------

tests/test_renderers/fixtures/tables.md

Lines changed: 64 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,19 @@ a|b
1313
<thead>
1414
<row>
1515
<entry>
16-
a
16+
<paragraph>
17+
a
1718
<entry>
18-
b
19+
<paragraph>
20+
b
1921
<tbody>
2022
<row>
2123
<entry>
22-
1
24+
<paragraph>
25+
1
2326
<entry>
24-
2
27+
<paragraph>
28+
2
2529
.
2630

2731
--------------------------
@@ -40,19 +44,25 @@ a | b | c
4044
<thead>
4145
<row>
4246
<entry classes="text-align:left">
43-
a
47+
<paragraph>
48+
a
4449
<entry classes="text-align:center">
45-
b
50+
<paragraph>
51+
b
4652
<entry classes="text-align:right">
47-
c
53+
<paragraph>
54+
c
4855
<tbody>
4956
<row>
5057
<entry classes="text-align:left">
51-
1
58+
<paragraph>
59+
1
5260
<entry classes="text-align:center">
53-
2
61+
<paragraph>
62+
2
5463
<entry classes="text-align:right">
55-
3
64+
<paragraph>
65+
3
5666
.
5767

5868
--------------------------
@@ -70,18 +80,54 @@ Nested syntax:
7080
<thead>
7181
<row>
7282
<entry>
73-
<emphasis>
83+
<paragraph>
84+
<emphasis>
85+
a
86+
<entry>
87+
<paragraph>
88+
<strong>
89+
<emphasis>
90+
b
91+
<tbody>
92+
<row>
93+
<entry>
94+
<paragraph>
95+
<math>
96+
1
97+
<entry>
98+
<paragraph>
99+
<subscript>
100+
x
101+
.
102+
103+
--------------------------
104+
External links:
105+
.
106+
a|b
107+
|-|-|
108+
[link-a](https://www.google.com/)|[link-b](https://www.python.org/)
109+
.
110+
<document source="notset">
111+
<table classes="colwidths-auto">
112+
<tgroup cols="2">
113+
<colspec colwidth="50.0">
114+
<colspec colwidth="50.0">
115+
<thead>
116+
<row>
117+
<entry>
118+
<paragraph>
74119
a
75120
<entry>
76-
<strong>
77-
<emphasis>
78-
b
121+
<paragraph>
122+
b
79123
<tbody>
80124
<row>
81125
<entry>
82-
<math>
83-
1
126+
<paragraph>
127+
<reference refuri="https://www.google.com/">
128+
link-a
84129
<entry>
85-
<subscript>
86-
x
130+
<paragraph>
131+
<reference refuri="https://www.python.org/">
132+
link-b
87133
.

tests/test_sphinx/sourcedirs/basic/content.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ $$c=2$$ (eq:label)
4343
| a | b |
4444
|-----|--:|
4545
| *a* | 2 |
46+
| [link-a](https://google.com) | [link-b](https://python.org) |
4647

4748
this
4849
is

tests/test_sphinx/test_sphinx_builds/test_basic.html

Lines changed: 30 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -104,22 +104,46 @@ <h1>
104104
<thead>
105105
<tr class="row-odd">
106106
<th class="head">
107-
a
107+
<p>
108+
a
109+
</p>
108110
</th>
109111
<th class="text-align:right head">
110-
b
112+
<p>
113+
b
114+
</p>
111115
</th>
112116
</tr>
113117
</thead>
114118
<tbody>
115119
<tr class="row-even">
116120
<td>
117-
<em>
118-
a
119-
</em>
121+
<p>
122+
<em>
123+
a
124+
</em>
125+
</p>
126+
</td>
127+
<td class="text-align:right">
128+
<p>
129+
2
130+
</p>
131+
</td>
132+
</tr>
133+
<tr class="row-odd">
134+
<td>
135+
<p>
136+
<a class="reference external" href="https://google.com">
137+
link-a
138+
</a>
139+
</p>
120140
</td>
121141
<td class="text-align:right">
122-
2
142+
<p>
143+
<a class="reference external" href="https://python.org">
144+
link-b
145+
</a>
146+
</p>
123147
</td>
124148
</tr>
125149
</tbody>

tests/test_sphinx/test_sphinx_builds/test_basic.xml

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -56,16 +56,29 @@
5656
<thead>
5757
<row>
5858
<entry>
59-
a
59+
<paragraph>
60+
a
6061
<entry classes="text-align:right">
61-
b
62+
<paragraph>
63+
b
6264
<tbody>
6365
<row>
6466
<entry>
65-
<emphasis>
66-
a
67+
<paragraph>
68+
<emphasis>
69+
a
70+
<entry classes="text-align:right">
71+
<paragraph>
72+
2
73+
<row>
74+
<entry>
75+
<paragraph>
76+
<reference refuri="https://google.com">
77+
link-a
6778
<entry classes="text-align:right">
68-
2
79+
<paragraph>
80+
<reference refuri="https://python.org">
81+
link-b
6982
<paragraph>
7083
this
7184

0 commit comments

Comments
 (0)