0

I'm writing a simple extension for Sphinx/JupyterBook for a directive called examplenum that will add a new title starting with "Example", then will automatically add the correct section and example number to the end of the title. For instance, if it is the second examplenum in section 4.6, then the directive will insert the title "Example 4.6.2" into the document.

I'm very new to Sphinx directives. I was able to figure out how to add a title and increment the number of the example, but I can't figure out how to include the section number. Here's my run function:

    def run(self):
        env = self.env
        example_id = env.new_serialno('examplenum') + 1
        example_sect = nodes.section()
        example_sect['ids'] = "Example"
        label = "Example {number}".format(number = example_id)
        example_sect += nodes.title(text=label)
        return [example_sect]

Any help would be appreciated.

0 Answers0