Michael Jones schrieb:
> I've managed to get a result by adding a custom role :highlight: with
> the following (hackey) code:
> 
> from docutils import nodes
> class highlight( nodes.Inline, nodes.TextElement ): pass
> roles.register_generic_role('highlight', highlight )
> 
> import docutils.writers.html4css1
> 
> def visit_highlight(self, node):
>     self.body.append( self.starttag(node, 'span', '', CLASS="highlight") )
> 
> def depart_highlight(self, node):
>     self.body.append('</span>')
> 
> docutils.writers.html4css1.HTMLTranslator.visit_highlight = visit_highlight
> docutils.writers.html4css1.HTMLTranslator.depart_highlight = depart_highlight

While this works, I'd suggest using Sphinx' API here:

def setup(app):
    app.add_node(highlight, html=(visit_highlight, depart_highlight))
    app.add_generic_role('highlight', highlight)

But to be fair, add_generic_role only exists since three minutes ago :)

> However when I use it in the following case:
> 
> :highlight:`some text with further **emphasis**`
> 
> It renders out the asterisks instead of further processing it to <strong> 
> tags.
> 
> I'm not sure if it is possible to have to process the text of the role?

docutils generally don't do nested markup.  I've added some nested markup for
:samp:, i.e. :samp:`abc{def}ghi` where "def" will be italic.  You could look
in the source code for that role to see how I did it.

(It may also be possible to get the rst parser to parse the role contents,
but I haven't yet seen how.)

Georg

--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to