/
fix_sphinx_issue_11147.py
29 lines (22 loc) · 1.07 KB
/
fix_sphinx_issue_11147.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
"""Monkey patches a fix for https://github.com/sphinx-doc/sphinx/pull/11147."""
import inspect
import sphinx.util.nodes
import sphinx.util.docutils
def _monkey_patch_nested_parse_with_titles():
orig_nested_parse_with_titles = sphinx.util.nodes.nested_parse_with_titles
if list(inspect.signature(orig_nested_parse_with_titles).parameters.keys()) != [
"state",
"content",
"node",
]:
# Assume https://github.com/sphinx-doc/sphinx/pull/11147 has been merged.
return
# Note that this is different from the fix in
# https://github.com/sphinx-doc/sphinx/pull/11147, since it is not practical
# to monkey patch all callers to pass in the `content_offset`. Instead, we
# use `switch_source_input`, which makes it unnecessary to pass in
# `content_offset`.
def nested_parse_with_titles(state, content, node):
with sphinx.util.docutils.switch_source_input(state, content):
return orig_nested_parse_with_titles(state, content, node)
sphinx.util.nodes.nested_parse_with_titles = nested_parse_with_titles