How do I create a global role/roles in Sphinx?

前端 未结 2 1078
闹比i
闹比i 2020-12-05 07:36

This is a followup of \"ReST Strikethrough\" ReST strikethrough but in a Sphinx rather than ReST context. My question is whether there is a central place in sphinx where to

相关标签:
2条回答
  • 2020-12-05 08:02

    It seems that rst_prolog that is set in the conf.py file is the central place that I was looking for. Rst_prolog is "A string of reStructuredText that will be included at the beginning of every source file that is read". In my case, I simply added the following to conf.py:

    rst_prolog = """
    .. role:: test2
    """
    

    Note also that for my purpose, the role directive without a class attibute works just fine.

    Obviously, as Chris has pointed out, an rst_prolog that accomplishes many things could be achieved by including a global.rst file. [There may be issues with its relative path, however. Maybe better to use rst_prolog = open('global.rst', 'r').read() --untested]

    0 讨论(0)
  • 2020-12-05 08:02

    From the example at documenting your project using sphinx, you can use include to substitute a global.rst file, which contains all your role directives, into your other files. From this site:

    The syntax:

    .. include:: myfile.rst
    

    Will "inline" the given file (myfile.rst). A common convention I use is create a global .rst file called global.rst and include that at the top of every page. Very useful for links to common images or common files links, etc.

    0 讨论(0)
提交回复
热议问题