Search code examples
pythonpython-sphinxdocutils

Sphinx Using Domain Data/Indices


i was following the Tutorial for the “recipe” extension (https://www.sphinx-doc.org/en/master/development/tutorials/recipe.html).

I am a little confused as the compiled html side doesn't show the ingredients defined in the contains option. Does anyone has an idea what I might have missed from the docs?

Is there any way using sphinx to show the data e.g. self.data["recipe_ingredients"][name] or print the list of the IngredientIndies from RecipeDomain.indices?

I added my code to: https://github.com/jonassorgenfrei/LUMACH-SphinxDemo

And was expecting that the recipe section shows the ingredients: https://jonassorgenfrei.github.io/LUMACH-SphinxDemo/recipes.html


Solution

  • I think i found what i was looking for, i implemented the transform_content method for class RecipeDirective(ObjectDescription) and was able to add the Ingredient information in this step to the content:

    def transform_content(self, contentnode: addnodes.desc_content) -> None:
        if "contains" in self.options:
            paragraph_node = nodes.paragraph(text="Ingredients: {}".format(self.options.get("contains")))
            contentnode.insert(0, paragraph_node)
    

    But not sure if this is the best approach.