|release| substitution inside a download link

699 views
Skip to first unread message

Christophe de Vienne

unread,
Oct 28, 2010, 9:00:50 AM10/28/10
to sphinx-dev
Hi,

I generate versionned pdf from my documentation (ie I put the release
number in the filename) and would like to put a link on my html
version, like this :

:download:`Version PDF <_build/latex/MyDocumentation-|release|.pdf>.

But ! the |release| part is not replaced by my release number.

Is it fixable ?

Regards,

Christophe

qx guy

unread,
Nov 10, 2010, 7:08:06 AM11/10/10
to sphinx-dev
I have the exact same issue using |version|. I want to include it in
links (which e.g. point from the documentation to online demos which
follow the same version scheme).

I think there is a general issue with inline markup, where the
contents of the markup is not interpreted, and as a consequence macros
are not expanded. This affects probably more than just links. I
wouldn't mind going to some effort to overcome this, e.g. by using
reST directives, I just can't think of how :-/.

If anybody has an idea how to "splice" macros into other reST markup,
I would highly appreciate hearing about this.

Thomas

TP

unread,
Nov 11, 2010, 2:34:03 AM11/11/10
to sphin...@googlegroups.com
> --
> You received this message because you are subscribed to the Google Groups "sphinx-dev" group.
> To post to this group, send email to sphin...@googlegroups.com.
> To unsubscribe from this group, send email to sphinx-dev+...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/sphinx-dev?hl=en.
>
>

Not sure if this is what you mean but since conf.py is just a Python
file, you can do string substitutions in it.

For example, for I happen to do:

rst_prolog="""

.. |versionG| replace:: :guilabel:`%s`

""" % (version,)

because I sometimes need to include the version number in :guilabel:
styled text and :guilabel:`blah-|version|` won't work.

So now I can do:

Right-click :guilabel:`blah-`\ |versionG| to do foo.

As far as links go, you might try this technique in combination with
the sphinx.ext.extlinks – Markup to shorten external links extension.
See http://sphinx.pocoo.org/ext/extlinks.html for details. (Pretty
sure this works for any links not just "external" ones).

Guenter Milde

unread,
Nov 11, 2010, 4:56:15 AM11/11/10
to sphin...@googlegroups.com
On 2010-11-10, qx guy wrote:
> I have the exact same issue using |version|. I want to include it in
> links (which e.g. point from the documentation to online demos which
> follow the same version scheme).

> I think there is a general issue with inline markup, where the
> contents of the markup is not interpreted, and as a consequence macros
> are not expanded. This affects probably more than just links.

Missing support for nested inline markup in reStructuredText is a known
problem:
http://docutils.sourceforge.net/FAQ.html#is-nested-inline-markup-possible

> I wouldn't mind going to some effort to overcome this, e.g. by using
> reST directives, I just can't think of how :-/.

Putting the effort into solving the core problem would IMO be the best
long term solution.

Günter

qx guy

unread,
Nov 17, 2010, 5:54:02 AM11/17/10
to sphinx-dev


On Nov 11, 10:56 am, Guenter Milde <mi...@users.berlios.de> wrote:
> Putting the effort into solving the core problem would IMO be the best
> long term solution.

You mean, becoming a commiter on the docutils project? :).

T.

qx guy

unread,
Nov 17, 2010, 6:16:37 AM11/17/10
to sphinx-dev


On Nov 11, 8:34 am, TP <wing...@gmail.com> wrote:
>   rst_prolog="""
>
>   .. |versionG|  replace:: :guilabel:`%s`
>
>   """ % (version,)
> So now I can do:
>
>   Right-click :guilabel:`blah-`\ |versionG| to do foo.

Thanks for this tip. But I'm not quite getting this particular
example. Wouldn't your text expand to

Right-click :guilabel:`blah-`:guilabel:`10.5`

(if 10.5 were the value of version)?! That's not quite the same
as :guilabel:`blah-10.5`, or is it?!

T.

qx guy

unread,
Nov 17, 2010, 11:17:54 AM11/17/10
to sphinx-dev
> As far as links go, you might try this technique in combination with
> the sphinx.ext.extlinks – Markup to shorten external links extension.
> Seehttp://sphinx.pocoo.org/ext/extlinks.htmlfor details. (Pretty
> sure this works for any links not just "external" ones).

Just to let you know: The hint at the Sphinx extension brought me on
the right track. I solved the issue by implementing a simple, source-
level macro facility through a custom Sphinx extension. The extension
just registers for the 'source-read' event of Sphinx, and does a
string.Template().safe_substitute() on the page contents, with a
predefined map of substitution strings.

This allows me to use these macros in arbitrary places in the reST
documentation, be it running text, links, inline markup, or reST
directives. :-)

Thanks everybody,
T.

TP

unread,
Nov 17, 2010, 11:28:42 PM11/17/10
to sphin...@googlegroups.com
> --
> You received this message because you are subscribed to the Google Groups "sphinx-dev" group.
> To post to this group, send email to sphin...@googlegroups.com.
> To unsubscribe from this group, send email to sphinx-dev+...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/sphinx-dev?hl=en.
>
>

Yes. It's not the same thing, but it **looks** right (which is all
that matters in my case).

-- TP

Rolf Schroder

unread,
Jul 29, 2014, 11:13:51 AM7/29/14
to sphinx...@googlegroups.com, sphin...@googlegroups.com
Just in case somebody is still interested, here is how I  did it. In my conf.py:

rst_prolog = """
    .. |mypdflink| raw:: html

     <a href="Document-%s.pdf">PDF</a>
""" % (version)

and in the rst file:

The latest version of this document can be download as |mypdflink|.
Reply all
Reply to author
Forward
0 new messages