2012-11-17 37 views
3

我正在編寫一個Sphinx擴展,我需要知道當前頁面的源文件位置,以提取它的一些版本控制系統信息。我如何在我的事件處理程序/我應該使用哪個事件處理程序中獲取這些信息?在Sphinx擴展中獲取源文件的第一個文件路徑

例子:

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) 

回答

1

它可以用一個小的變化來完成的事件處理程序在你的例子:

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)  
+0

完美的作品,謝謝! –

相關問題