使用numpy样式记录 Python 模块并使用sphinx和numpydoc扩展生成 html 文档,我偶然发现了一个关于项目符号列表的错误(或功能?)。
In reStructuredText (and sphinx/numpydoc), a single-lined paragraph
- with an immediately following
- bullet list
- is allowed,
but if you have a "long" paragraph,
which may be spanning several lines,
- a following bullet list
- results in an `ERROR: Unexpected indentation`.
With a blank line added between the "long" paragraph, which again
may span multiple lines, and the following list,
- bullet lists
- work fine again.
根据reStructuredText 参考,项目符号列表前后需要一个空行。
因此我想知道:为什么第一个版本可以工作(而它不应该),与(不工作的)第二个版本有什么不同?
编辑:
在生成的 html 中,第一个和最后一个版本在外观上有所不同。如果需要没有前导空行的项目符号列表的外观(html 中的空间更少),可以使用快速修复
to escape every line break by a backslash.\
This way there's effectively only a single long line,
- which allows bullet lists
- even after long paragraphs.
这避免了解析错误,但仍然没有回答为什么 :-)