diff options
author | Takeshi KOMIYA <i.tkomiya@gmail.com> | 2017-12-17 01:20:18 +0900 |
---|---|---|
committer | Takeshi KOMIYA <i.tkomiya@gmail.com> | 2017-12-17 02:13:11 +0900 |
commit | 299b11f26f98b1f6bf61602ff9955a12b7d1593e (patch) | |
tree | e92e8633763b86464c4da21e03bb9b1271bf7a15 /doc/extdev/markupapi.rst | |
parent | cac965cf77cb69d7807df566bcaa62d31cafd143 (diff) | |
download | sphinx-git-299b11f26f98b1f6bf61602ff9955a12b7d1593e.tar.gz |
Replace AutodocReporter by switch_source_input()
Diffstat (limited to 'doc/extdev/markupapi.rst')
-rw-r--r-- | doc/extdev/markupapi.rst | 22 |
1 files changed, 20 insertions, 2 deletions
diff --git a/doc/extdev/markupapi.rst b/doc/extdev/markupapi.rst index df23f164d..8a18e2306 100644 --- a/doc/extdev/markupapi.rst +++ b/doc/extdev/markupapi.rst @@ -117,12 +117,30 @@ Both APIs parse the content into a given node. They are used like this:: node = docutils.nodes.paragraph() # either - from sphinx.ext.autodoc import AutodocReporter - self.state.memo.reporter = AutodocReporter(self.result, self.state.memo.reporter) # override reporter to avoid errors from "include" directive nested_parse_with_titles(self.state, self.result, node) # or self.state.nested_parse(self.result, 0, node) +.. note:: + + ``sphinx.util.docutils.switch_source_input()`` allows to change a target file + during nested_parse. It is useful to mixture contents. For example, ``sphinx. + ext.autodoc`` uses it to parse docstrings. + + from sphinx.util.docutils import switch_source_input + + # Switch source_input between parsing content. + # Inside this context, all parsing errors and warnings are reported as + # happened in new source_input (in this case, ``self.result``). + with switch_source_input(self.state, self.result): + node = docutils.nodes.paragraph() + self.state.nested_parse(self.result, 0, node) + + .. deprecated:: 1.7 + + Since Sphinx-1.6, ``sphinx.ext.autodoc.AutodocReporter`` is used for this purpose. + For now, it is replaced by ``switch_source_input()``. + If you don't need the wrapping node, you can use any concrete node type and return ``node.children`` from the Directive. |