Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
371 views
in Technique[技术] by (71.8m points)

restructuredtext - Add a class to a table in Sphinx?

I have a table in rst, and I want to add a class to it, when compiling to HTML with Sphinx. According to the docs, adding a .. class:: directive before the table should add the class to the table, but instead it adds a definition list.

The table code is:

.. class:: special

== == ==
a  b  c
1  2  3
== == ==

which results in:

<dl class="class">
<dt id="special">
<em class="property">class </em><code class="descname">special</code><a class="headerlink" href="#special" title="Permalink to this definition">?</a></dt>
<dd></dd></dl>

<table border="1" class="docutils">
<colgroup>
<col width="33%" />
<col width="33%" />
<col width="33%" />
</colgroup>
<tbody valign="top">
<tr class="row-odd"><td>a</td>
<td>b</td>
<td>c</td>
</tr>
<tr class="row-even"><td>1</td>
<td>2</td>
<td>3</td>
</tr>
</tbody>
</table>

What am I doing wrong? I'm using Sphinx 1.3.1

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

The Sphinx default domain is Python and it contains a class directive which shadows the original Docutils directive with the same name.

To make it work, use rst-class instead:

.. rst-class:: special

== == ==
a  b  c
1  2  3
== == ==

See http://www.sphinx-doc.org/en/master/usage/restructuredtext/basics.html#id2.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...