Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
Message from discussion How to add rel attribute to sphinx reference in HTML output?
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Axial  
View profile  
 More options Oct 31 2012, 9:46 pm
From: Axial <holger.sp...@gmail.com>
Date: Wed, 31 Oct 2012 18:46:21 -0700 (PDT)
Local: Wed, Oct 31 2012 9:46 pm
Subject: How to add rel attribute to sphinx reference in HTML output?

I have a simple extension for Sphinx (my version in use is
Sphinx-1.1.3-py2.6). Very much like this<http://www.doughellmann.com/articles/how-tos/sphinx-custom-roles/inde...> excellent
example by Doug Hellmann.
My question is: How can I add a *rel='bar'* attribute to the final HTML for
the **tag?

There seems to be a few ways to do this, but I couldn't find a simple one.
Advise and tips are appreciated.

The reference nodes are created in this fashion:

node = nodes.reference(rawtext, utils.unescape(text),
            internal=False,
            refuri=ref,
            classes=['foocss'],
            rel='bar',
            **options)

However, the *rel='bar'* attribute gets stripped out from the final HTML
markup (note: it make is fine into the starttag). Hunting through the
source got me to *sphinx/writers/html.py* and the *HTMLTranslator* class.
Here is part of the visit_reference method:

# overwrittendef visit_reference(self, node):
    atts = {'class': 'reference'}

    <snip>

    if 'reftitle' in node:
        atts['title'] = node['reftitle']
    self.body.append(self.starttag(node, 'a', '', **atts))

Additional attributes are not handled. Maybe they could be replaced in
others parts. I couldn't find anything useful in that respect.

So, I could:

   - create a custom node which reimplements all the functionality of the
   reference node. A fair bit of work for a small addition.
   - Overwrite the *visit_reference* method in *sphinx/writers/html.py*.
   Quicker, but bad in terms of future Sphinx updates.
   - Add the rel attribute with jQuery to the link tag after the fact.
   Well, not pretty either.

I'm sure I'm missing the obvious and elegant solution.
Note that I've posted the same question on stackoverflow.com<http://stackoverflow.com/questions/13168702/how-to-add-rel-attribute-...> with
a bit more information.
Just casting the net a bit wider since this seems to be the appropriate
forum.

Thanks for reading.


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.