Custom directive with header and internal list reStrcuturedText

Basically what I'm trying to do is copy this style (from the word doc), but using rst.

enter image description here

I thought that I might need a custom directive that could include the title and style of the internal flags.

Ideally, I would like to do something like:

.. handson:: The title - Check one - Check two 

The bulltet elements inside the handson block will be in the style of flags, but in the rest of the document there will be only regular markers.

I took a look at the user directive, but I'm not sure if this is the best way to handle this. I also use rst2pdf if this affects the results.

+1
source share
1 answer

If you don’t want to follow the path of creating a custom directive, you can use the normal warning block and β€œfake” checkboxes. Your markup can be standard reStructuredText:

 .. admonition:: The title - Check one - Check two 

Then you can include some custom CSS markup in your reStructuredText file in the target list items in the declarations:

 .. raw:: html <style> .admonition ul { list-style-type: none; } .admonition li:before { content: "\2610"; } </style> 

Here, CSS targets any element of a list element that is a child of any element with a warning class and replaces the marker points of the element with simulated flags using the Unicode voting symbol , ☐.

Docutils applies an additional class to general warnings , which is a concatenation of the "warning" and the warning header. So in the example above, we could be more specific with the element that we are targeting with the CSS rule:

 .admonition-the-title ul { /* ... */ } 

This can be used to target one alert inside your document.

Credit goes to these two answers to the SO question. How do I create a checklist in reStructuredText (reST)?

Obviously, the above goals output HTML. However, I did not use rst2pdf, so I can not comment on how you need to change this to work with this program. Hope someone else answers this. As far as I know, rst2pdf supports a cascading style mechanism , so it should be simple (for those who know the syntax of the rst2pdf stylesheet) to add an extra role .. raw:: pdf and change the list styles specified.

+1
source

Source: https://habr.com/ru/post/949573/


All Articles