2

I define the following table in restructuredtext:

+-------------------------+--------------------+
| Label                   |Description         |
+=========================+====================+
| foo                     |Two options:        |
|                         |                    |
|                         |* Thing 1           |
|                         |* Thing 2           |
+-------------------------+--------------------+
| bar                     |Bar does something. |
+-------------------------+--------------------+

When this gets rendered in html (using Sphinx), the "Two options:" text gets wrapped in a paragraph tag. The "Bar does something." text does not get rendered with a paragraph tag. When the stylesheets are applied, this results in the cell text looking different:

enter image description here

Is there a way to force the same behavior for both cases?

kldavis4
  • 2,177
  • 1
  • 22
  • 33
  • "Two options:" is a paragraph and "Bar does something" is a table cell. But what is wrong with the output? What do you mean by "same behaviour"? – Humbalan Sep 07 '16 at 15:55
  • The problem is "Two options:" and "Bar does something" render differently because one has a paragraph tag around it and the other does not. You can see in the attached image, the one without the paragraph tag is smaller. This makes the tables render funny, so that multiline cells have larger text than single line cells. If there was a way to force the single line cells to render as paragraphs, it would resolve the issue for me. – kldavis4 Sep 07 '16 at 17:14
  • What Sphinx theme do you use? Possibly related: http://stackoverflow.com/q/39285425/407651. – mzjn Sep 07 '16 at 18:37
  • Thanks for your response. I am using a custom theme based on alabaster. – kldavis4 Sep 07 '16 at 19:05
  • OK, then I guess that you may need to add or update some CSS rule(s) in that theme. – mzjn Sep 08 '16 at 09:41
  • Is it a CSS issue? The html being generated is actually different, so I currently need different rules to get the same content. If the html was not different, then I could apply the same CSS rule and get consistent results. – kldavis4 Sep 08 '16 at 14:40
  • What happens if you use the stock alabaster theme without any customizations? – mzjn Sep 09 '16 at 07:04
  • I switched to alabaster and then basic and classic and they all generate the same html as my custom theme. – kldavis4 Sep 09 '16 at 19:50
  • 1
    Too bad no one has an answer for this. Everyone seems to misunderstand the question. Frustrating! This might have changed in newer Sphinx version, I get `

    ` that wraps single line text inside table cells.

    – Moberg Feb 08 '22 at 11:29
  • @Moberg if you are getting the paragraph tag now for single line text, it sounds like the issue has been resolved with the newer version of Sphinx. – kldavis4 Feb 08 '22 at 15:12

1 Answers1

1

Sphinx' way to change CSS declarations: add in your conf.py a line

templates_path = ['my_template_path']

and add in my_template_path a file layout.html. There you can override the css classes of your theme which define the layout of the table contents. The class names depend on your theme. Try to find it out with the developers features of you browser. In my theme the definition of the first paragraph is class="first". Here I overwrite it with

td > p.first { margin: 0; }

The list ul has class="last simple", overwritten by

td > ul.last.simple { margin: 0; }

The layout.html should have the form

{% extends "!layout.html" %}
<style type="text/css">

/* Add class definitions here */

</style>

Hope that helps. Some more explanations here and in this stackoverflow-thread.

Community
  • 1
  • 1
Humbalan
  • 677
  • 3
  • 14