On 2015-08-06 11:56, Matthew Woehlke wrote:
> I've implemented a custom reST role in my setup. I'd like to be able to
> parse inline markup within the role text.
> 
> Right now I am just creating an inline node. Presumably I would want to
> pass the role text to something that would parse it for markup and give
> me back a node subtree that I would add instead.

Okay, this is what I came up with. It seems to work... anyone know if
I'm missing something that this is going to mangle my documents or kill
kittens or something?

    def add_class_role(name, rawtext, text, lineno, inliner,
                       options={},  content=[]):
        # Prepare context for nested parsing
        memo = Struct(document=inliner.document,
                      reporter=inliner.reporter,
                      language=inliner.language)

        # Create parent node
        options['classes'] = [class_name]
        parent = nodes.inline(rawtext, '', **options)

        # Parse role text for markup and add to parent
        processed, messages = inliner.parse(text, lineno, memo, parent)
        parent += processed

        # Return parent node, and any messages from nested parsing
        return [parent], messages

-- 
Matthew

-- 
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 http://groups.google.com/group/sphinx-users.
For more options, visit https://groups.google.com/d/optout.

Reply via email to