Hi Andrea,
At first, the sample code I posted before is wrong. Sorry.
Below code works well.
```
import docutils.nodes
def role_fn(name, rawtext, text, lineno, inliner, options={}, content=[]):
ref = docutils.nodes.reference(rawtext, text, internal=True,
refname=text)
return [ref], []
def setup(app):
app.add_role('myref', role_fn)
```
For your purpose, you can customize ``role_fn` implementation.
For example, you can add css class name for reference object as:
docutils.nodes.references(rawtext, text, internal=True, refname=text,
classes=['my-class-foo'])
Please try it ;)
Regards,
--
Takayuki SHIMIZUKAWA
http://about.me/shimizukawa
On Thu, Apr 14, 2016 at 6:59 PM Andrea Cassioli <[email protected]>
wrote:
> I am still struggling with this issue. In my understanding the following
> code
>
> app.add_role('code_ref', XRefRole(lowercase=True,
> innernodeclass=nodes.literal, warn_dangling=True))
>
>
>
> should create a new role named `code_ref` that uses a literal node to
> display links. Sphinx process the following
>
>
> .. _xxx:
>
> Section
> ===========
>
>
> :code_ref:`xxx`
>
>
>
>
>
> with no errors, but the link is broken.
>
> What am I missing?
>
> On Saturday, April 9, 2016 at 4:29:39 PM UTC+2, Andrea Cassioli wrote:
>
>> Hi,
>> I am struggling to find a way to do the following:
>>
>> - I would like to have a special role :myref: to link to specific
>> sections
>> - the new role should use a different layout, say show text in verbatim
>> - the new role should also have a class attribute so that it can be
>> customize using CSS
>>
>> What is a neat way to do this?
>>
> --
> 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 post to this group, send email to [email protected].
> Visit this group at https://groups.google.com/group/sphinx-users.
> For more options, visit https://groups.google.com/d/optout.
>
--
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 post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/sphinx-users.
For more options, visit https://groups.google.com/d/optout.