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
164 views
in Technique[技术] by (71.8m points)

python - End literal block in list item

I have a list item in my rst file that I would like to put a literal block into, but I am unable to get the literal block to end properly.

This is my rst:

1. Item 1 (not literal)
2. Item 2::

    MyCode.example()

    Description of the code shown above (not literal)

I would like the paragraph starting with Description to be outside the literal block above it, but still part of list item #2. The only workaround I have been able to come up with is this:

1. Item 1 (not literal)
2. Item 2:

    ::

        MyCode.example()

    Description of the code shown above (not literal)

This allows the non-literal text to return to the previous level of indentation, making everything look just the way I want it to. However, I would like to have the :: in the first line of the list item.

Is it possible to end the literal block explicitly in a way that would allow the :: to stay in the first line of the list item?

See Question&Answers more detail:os

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

1 Reply

0 votes
by (71.8m points)

Yes. Whitespace is tricky. You have one extra leading space in your code and the line starting with "Description". Try this:

1. Item 1 (not literal)
2. Item 2::

       MyCode.example()

   Description of the code shown above (not literal)

Note that the first letters of the item and description vertically align and code blocks are indented 4 spaces.

Bonus tip: I like to add a space between numbered items and its period so that it is starts at column 5. This makes it easier to indent paragraphs to 4 spaces (and code blocks 8 spaces) in my editor. And in case I have more than 9 items, then the indentation looks nicer for items 10-99.


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

...