Hello everybody,
I am struggling with a simple thing (but I want to do it properly)...
I want to create a custom internal hyperlinking role :yref:`target`,
where target is transformed to yield name of an existing label
(target2, created either manually or automatically) somewhere else in
the document (class name or such), so in the end it will be as if
writing :ref:`target <target2>`. This target2 should be then resolved
automatically.
So far, I do the following in conf.py:
1. I create a class inheriting from XRefRole, overriding process_link:
class YXRefRole(XRefRole):
def process_link(self, env, refnode, has_explicit_title, title,
target):
# the logic here would be more complex; for now, we want to
simulate :ref:`[[target]] <prefix.target>`
return '[['+title+']]','prefix.'+target
2. Then I create a thin wrapper function to use that class:
def yref_role(type,rawtext,text,lineno,inliner,options={},content=[]):
# I know this has to instantiate the class over and over, but that
is not an issue now
return YXRefRole()
('yref',rawtext,text,lineno,inliner,options,content)
3. Finally, the role is registered:
from docutils.parsers.rst import roles
roles.register_canonical_role('yref', yref_role)
The result is that the title is really replaced (I see [[target]] in
bold in the resulting HTML), but the hyperlink is not created and I
don't see any warning about unresolvable reference...
What is the last piece that I am missing?
Thanks a lot! V.
--
You received this message because you are subscribed to the Google Groups
"sphinx-dev" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/sphinx-dev?hl=en.