Richard Grace
Richard Grace

Reputation: 11

RST conditional directives don't work using standard syntax

I've defined a conditional tag in my makefile so I can use the ONLY directive to conditionally remove blocks of text.

Makefile entry:

... set BUILDDIR=_build

sphinx-build -t internal ...

I have a single LINE of information that I need to make disappear for a specific docs build. Here is the instance:

general:
    workspace: "xxx"
    <first indented list items>

.. only:: internal

    xt-team-name: "phoenix"    # for use with XT Grok - exclude this line otherwise **

    <following list items - must stay put>

The 'internal' directive works, BUT it wipes out everything following the single line of text, that I DID NOT want to wipe out for this build. I have no spacebar characters or tab stops after the excluded text line - just a bare newline. I thought the newline would end the conditional operation?

What's the trick to get it to work on just the one piece? Can't move anything - it would disrupt the logic of the preceding and following indented sections of information. Tweaked the example to make it clearer.

Upvotes: 1

Views: 866

Answers (1)

Steve Piercy
Steve Piercy

Reputation: 15045

White space has meaning in reStructuredText.

Indent the content that you want to hide for internal under the only directive.

Do not indent the content that you want to show.

general:
    workspace: "xxx"
    ...

.. only:: internal

    xt-team-name: "phoenix"    # for use with XT Grok - exclude this line otherwise **

<following body of information>

Edit

Upon realizing that you want a list of items, not paragraphs, you can still get this to work with proper indentation.

List of Items

*   One
*   Two

    .. only:: internal

        * Two and one-half (hidden)

*   Three

sphinx-build -b html . _build

sphinx-build -b html . _build

sphinx-build -b html -t internal . _build

enter image description here

Also if you do not want "Two and one-half (hidden)" to be a member of a nested list, but of its parent list, then you can dedent it and its only directive.

Upvotes: 2

Related Questions