最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

documentation - Sphinx "only" directive with lists? - Stack Overflow

programmeradmin0浏览0评论

When using reStructuredText in Sphinx, how can I have optional list items using the only directive?

As an example:

foo bar:

- a
- b
.. only:: Internal

   - c
- d

The problem with above is that it creates a separate <p> for both - c and - d when generating html. Anyone know how I can have all of these contained within a single <ul> in generated html? Thanks!

When using reStructuredText in Sphinx, how can I have optional list items using the only directive?

As an example:

foo bar:

- a
- b
.. only:: Internal

   - c
- d

The problem with above is that it creates a separate <p> for both - c and - d when generating html. Anyone know how I can have all of these contained within a single <ul> in generated html? Thanks!

Share Improve this question edited Feb 6 at 19:00 mzjn 51k15 gold badges134 silver badges260 bronze badges asked Feb 6 at 16:03 kotakotakotakotakotakota 7828 silver badges26 bronze badges 1
  • I'd use two complete lists, one for internal the other for external, and use ifconfig. – Steve Piercy Commented Feb 7 at 6:57
Add a comment  | 

1 Answer 1

Reset to default 1

You cannot place a directive directly between list items. Any text or rST syntax construct at this place breaks the list in two.

The workaround used by Docutils for the "class" directive and internal hyperlink targets is to apply nested "class" directives and targets to the following document tree element 1.

Example: to apply a class value to list item "c", append the "class" directive to the content of item "b":

foo bar:

- a
- b

  .. class:: internal
- c
- d
  • The empty line before the "class" directive is required -- otherwise it would be interpreted as continuation line of the preceding paragraph. Empty lines between list items are optional.

  • In Sphinx, use "rstclass" instead of "class".

You may try whether Sphinx uses the same concept for the "only" directive. Alternatively, you can use the strip_elements_with_classes Docutils configuration option to remove the "classified" item.

发布评论

评论列表(0)

  1. 暂无评论