我正在使用Sphinx來生成我的項目的文檔。如何使用Python以編程方式生成Sphinx文檔的一部分
在這個項目中,我描述了可用命令在yaml文件列表,一旦加載,導致字典的形式{command-name : command-description}
例如:
commands = {"copy" : "Copy the highlighted text in the clipboard",
"paste" : "Paste the clipboard text to cursor location",
...}
我想知道的,是如果在獅身人面像中有一種方法在make html
週期內加載yaml文件,請將某些reStructuredText格式(例如definition list)中的python字典轉換幷包含在我的html輸出中。
我希望我的.rst
文件看起來像:
Available commands
==================
The commands available in bla-bla-bla...
.. magic-directive-that-execute-python-code::
:maybe python code or name of python file here:
,並在內部轉換爲:被轉換爲HTML之前
Available commands
==================
The commands available in bla-bla-bla...
copy
Copy the highlighted text in the clipboard
paste
Paste the clipboard text to cursor location
。
這不是一個正確的答案,所以我把它作爲評論。據我所知,沒有辦法直接用sphinx解析yaml文件,但我認爲你可以使用pyyaml並修改你的sphinx Makefile。 –
寫YAML代碼有什麼意義?爲什麼不直接在Python模塊中編寫描述並使用Sphinx的autodoc?爲什麼做一些比http://sphinx.pocoo.org/ext/autodoc.html更復雜的東西? –
@ S.Lott - 基本思想是DNRY:在yml文件中定義命令(並可由用戶覆蓋)。上面的例子被簡化爲使問題更容易理解,但實際的yml文件實際上包含解析器的額外信息,如參數數量,可能的標誌,驗證回調等等。它看起來很愚蠢(和文檔中潛在的錯誤來源)在yml文件和模塊docstring中重複相同的信息。 – mac