剖析器 API

docutils 文件描述 剖析器如下

剖析器分析輸入文件並建立節點樹狀結構表示法。

在 Sphinx 中,剖析器模組的功能與 docutils 相同。剖析器透過擴充功能使用應用程式 API 註冊到 Sphinx;Sphinx.add_source_suffix()Sphinx.add_source_parser()

來源後綴是從檔案後綴到檔案類型的對應。例如,.rst 檔案對應到 'restructuredtext' 類型。Sphinx 使用檔案類型從已註冊清單中尋找剖析器。在搜尋時,Sphinx 參考 Parser.supported 屬性,並選取屬性中包含檔案類型的剖析器。

使用者可以使用 source_suffix 覆寫來源後綴對應,如下所示

# a mapping from file suffix to file types
source_suffix = {
    '.rst': 'restructuredtext',
    '.md': 'markdown',
}

您應該指出您的剖析器支援的檔案類型。這將允許使用者適當地設定其設定。

class sphinx.parsers.Parser[來源]

來源剖析器的基底類別。

額外的剖析器應繼承此類別,而不是 docutils.parsers.Parser。與 docutils.parsers.Parser 相比,此類別提高了對 Sphinx API 的可存取性。

子類別可以存取 sphinx 核心執行時期物件(app、config 和 env)。

set_application(app: Sphinx) None[來源]

將從 Sphinx 呼叫 set_application 以設定 app 和其他實例變數

參數:

app (sphinx.application.Sphinx) – Sphinx 應用程式物件

config: Config

設定物件

env: BuildEnvironment

環境物件