Substitution in Admonitions

2019-02-25 18:19发布

问题:

How can I do a substitution in an admonition?

For example:

|p| account

.. note::

    **Been using |p| separately and now integrating?**

In my sphinx conf.py I define a replacement rule which gets appended to the rst file prior to interpretation (at least that is how I understand it):

rst_epilog = '.. |p| replace:: Labnext'

My first substitution in the paragraph works without fail. However the substitution in the note directive isn't applied. Any work arounds?

Thanks,

Mike

回答1:

The substitution in the note works if you remove the strong emphasis (double asterisks). Nesting of inline markup is not supported.

References:

  • http://sphinx-doc.org/rest.html#inline-markup
  • http://docutils.sourceforge.net/docs/ref/rst/restructuredtext.html#inline-markup
  • http://docutils.sourceforge.net/FAQ.html#is-nested-inline-markup-possible

Here is a workaround if you need to keep the strong emphasis:

  1. In conf.py, use the following definition:

    rst_epilog = '.. |p| replace:: **Labnext**'
    
  2. In your .rst file, use this markup:

    .. note::
    
      **Been using** |p| **separately and now integrating?**