Search code examples
python-sphinxrestructuredtext

Is it possible to combine rst-class and ifconfig?


I am writing on a software documentation. I am using the .. rst-cass:: directive to add specific css classes to different sections which control different styles and features, which works really well. Now I tried to create different versions of the document and therefore tried to combine .. rst-cass:: with .. ifconfig::. My .rst files looked like this:

.. ifconfig::  var==True
      
   .. rst-class:: html-toggle  

.. ifconfig::  var==False
      
   .. rst-class:: grey     

Sectiontitle
============  

When I tried to build this into HTML files, the build process didn´t finish and showed me:

'Losing "%s" attribute: %s' % (att, self[att])

AssertionError: Losing "classes" attribute: ['html-toggle']

Is there any way this can work, or any other way, where to assign CSS classes to sections depending on variables in the conf.py.


Solution

  • Use custom CSS, instead of adding classes to the HTML, and selecting which style sheet to use in your conf.py with a Python expression.

    ifconfig is intended to "include content of the directive only if the Python expression given as an argument is True", not customizing styles.