Reputation: 83706
I am writing a Sphinx extension and I need to know the current page's .rst
source file location to extract some version control system information of it. How can I get this information in my event handler / which event handler I should use?
Example:
def on_html_page_context(app, pagename, templatename, context, doctree):
if doctree:
print doctree.source
def setup(app):
app.require_sphinx('1.0')
app.connect('html-page-context', on_html_page_context)
Upvotes: 4
Views: 790
Reputation: 51062
It can be done with a small change to the event handler in your example:
def on_html_page_context(app, pagename, templatename, context, doctree):
if doctree:
print doctree.attributes['source'] # Path to .rst file
def setup(app):
app.connect('html-page-context', on_html_page_context)
Upvotes: 2