djangofont-awesomepython-sphinxread-the-docs

Sphinx Readthedocs theme Font-awesome integration


I know this may be a very silly question, but I've not managed to find anything online about a potential solution.

I am using Sphinx 1.4 and the sphinx_rtd_theme to generate some documentation for my Django project. I've been trying to find a way to use font-awesome icons in the .rst files but have found no way to do it. I've had a look at the sphinx_rtd_theme source files and the fa-* icons are included in the theme.css file. However, I'm unaware of a way actually to have them included.

Is it a directive, interpreted text or anything similar? I've tried icon, fonticon and fa as either of the above and none worked.

Any help would be appreciated.

I know I can potentially use raw HTML, but I'd like to avoid that if at all possible.


Solution

  • You can use Sphinx's rst-class directive, as follows:

    .. rst-class:: fa fa-fontawesome
    
       the font awsome flag will be attached to this paragraph
    

    rst-class will set the class attribute for the next element as specified.

    The following code renders only the icon:

    .. rst-class:: fa fa-font-awesome
    
       |
    

    Of course, you can also use custom classes to further style the element.