csv-table formatting in Python docstrings (Sphinx) - multiple lines in one cell

匿名 (未验证) 提交于 2019-12-03 00:59:01

问题:

I'm using Sphinx to document a Python project.

There seems to be a bit of inconsistency with the .. csv-table:: directive.

The main issue is a new line in a cell. And my questionable mental health.

The following code:

.. csv-table::     :header: Header1, Header2, Header3      A, B, "These lines appear as one line,      even though they are written in two lines."     C, D, "| These lines appear as two lines,      | but they are indented, and my OCD will simply not allow it."     E, F, "| If I continue this line in another line,     it will appear in a new line."     G, H, "If there is a blank line between the two lines,      there will be a blank line between the lines." 

Will render as:

I have searched through the entire reStructuredText manual, but could not find a way to solve it.

Is there any way to write two lines in one cell that will appear as the 2nd row, but without the indentation?

The theme is sphinx_rtd_theme.

I found the theme.css file (C:\Python34\Lib\site-packages\sphinx_rtd_theme\static\css\theme.css), but I can't find the section of the table definition for newline styling

回答1:

Line blocks have a left margin value in the sphinx_rtd_theme. One way to get rid of them is to create a custom CSS file which imports the theme's style rules and add a rule for line blocks within tables without that margin. Assuming the standard file and path names of a Sphinx project:

Create a _static/css/mystyle.css file in your Sphinx project with the following content:

@import "theme.css";  table.docutils div.line-block {     margin-left: 0; } 

Add the following option to the conf.py:

html_style = 'css/mystyle.css' 

Rebuild the Sphinx project.



标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!