I think I would move the definitions of all of these helper functions out of the `if localenv['sphinx_docs']:` block, mostly to save the extra level of indentation.