Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

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

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

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:

enter image description here

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:Python34Libsite-packagessphinx_rtd_themestaticcssheme.css), but I can't find the section of the table definition for newline styling

See Question&Answers more detail:os

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

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...