well known pain, I did similar prototype a month ago to introspect templates in python/django:
https://github.com/235/django-template-introspection
it shows for each html tag the templates which include it (processing chain) and corresponding views in python code that rendered them