Hi,

reST parser does not refers config values. So you need to pass it to the parser.
Sphinx uses a transform component to do that:
https://github.com/sphinx-doc/sphinx/blob/816a06564de5cfdd23df57d1b3291c0ccc8dacda/sphinx/transforms/__init__.py#L100-L118

BTW, we have `rst_prolog` config value to generate reST source. So it
is easy way to pass the values.
How about such hack?

def update_rst_prolog(app, config):
    # Update rst_prolog using config values
    rst_prolog = config.rst_prolog or ''
    if config.myVar:
        rst_prolog += '.. |myVar| replace:: %s' % config.myVar

    config.rst_prolog = rst_prolog

def setup(app):
    # You need to handle config-inited event to obtain determined config values.
    app.connect('config-inited', update_rst_prolog)

Thanks,
Takeshi KOMIYA

2020年1月17日(金) 18:52 DexterMagnific <[email protected]>:
>
> Dear all,
>
> I'd like to pass custom variables through the command line with -D. For this 
> I use the following code:
>
>
> def setup(app):
>     app.add_config_value('myVar', value, True)
>
>
> Now I'd like to reference them in my .rst file using |myVar|, just like for 
> |version| but I cannot make it work.
>
>
> Can you tell me how can I achieve this ?
>
> Thanks.
>
> --
> You received this message because you are subscribed to the Google Groups 
> "sphinx-users" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to [email protected].
> To view this discussion on the web visit 
> https://groups.google.com/d/msgid/sphinx-users/2ded30c4-0231-4d0c-8b3b-69318d654a08%40googlegroups.com.

-- 
You received this message because you are subscribed to the Google Groups 
"sphinx-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/sphinx-users/CAFmkQAO33vHgUDDQ7aP5mX8yQuZRVh1i_-aibAdr5iW_0HrXng%40mail.gmail.com.

Reply via email to