docutils

Sphinxを理解するためにはdocutilsも読んでおかないといけなさそうなので読 んでみたが、拡張書くだけだったらnodes.pyをおさえておけばいいだけかも

  • __init__.py: 基底クラス、例外クラス、バージョン情報を含む
  • core.py: Contains the Publisher class and publish_*() convenience functions.
  • frontend.py: コマンドラインのインターフェースや、設定ファイルを含むランタイム
  • io.py: IOまわり
  • nodes.py: ドキュメントツリーのクラス
  • statemachine.py: 正規表現ベースの文書フィルタに特化した有限ステートマシン
  • urischemes.py: URIスキーム
  • utils.py: Contains the Reporter system warning class and miscellaneous utilities.
  • languages: Language-specific mappings of terms.
  • parsers: Syntax-specific input parser modules or packages.
  • readers: Context-specific input handlers which understand the data source and manage a parser.
  • transforms: Modules used by readers and writers to modify DPS doctrees.
  • writers: Format-specific output translators.

__init__.py

ApplicationError, DataError, SettingSpec, TransformSpec, Componentとい うクラスが定義されている

languages/

言語の設定関連

statemachine.py

直接インポートするかサブクラス化することで使う。あまりちゃんと読んでない。

writers/

__init__.py

html4css1/

manpage.py

null.py

pep_html/

s5_html/

docutils_xml.py

latex2e/

newlatex2e/

odf_odt/

pseudoxml.py

examples.py

docutilsのクライアントコードの実例

nodes.py

transforms/

__init__.py

components.py

frontmatter.py

misc.py

parts.py

peps.py

references.py

universal.py

writer_aux.py

_string_template_compat.py

frontend.py

parsers/

urischemes.py

core.py

例えばrst2html.pyはcoreのpublish_cmdlineを呼び出しているだけ。

publish_cmdline(writer_name='html', description=description)

Publisherというクラスが重要

TODO:readerとparserの関係がよくわからん。

def set_reader(self, reader_name, parser, parser_name):
    """Set `self.reader` by name."""
    reader_class = readers.get_reader_class(reader_name)
    self.reader = reader_class(parser, parser_name)
    self.parser = self.reader.parser

publishが主な処理の流れ

self.set_io()
self.document = self.reader.read(self.source, self.parser,
                                 self.settings)
self.apply_transforms()
output = self.writer.write(self.document, self.destination)
self.writer.assemble_parts()

publish_cmdlineもpublish_fileもこれを呼んでるだけ。プログラミングの時に使うのが publish_programmaticallyらしい。

io.py

readers/

__init__.py

Readerクラスが定義されていて、これはscanしてparseする役割をもっている。 readで呼び出す

def read(self, source, parser, settings):
    self.source = source
    if not self.parser:
        self.parser = parser
    self.settings = settings
    self.input = self.source.read()
    self.parse()
    return self.document

doctree.py

Reader for existing document trees.

わからん

pep.py

PEPのReader

python/

pythonのソース用のReader

standalone.py

Standalone file Reader for the reStructuredText markup syntax.

utils.py

色々ユーティリティ系

ReporterクラスはGOFのオブザーバーパターンの実装

オプション関係もここ