summaryrefslogtreecommitdiff
path: root/sphinx/util/docutils.py
diff options
context:
space:
mode:
Diffstat (limited to 'sphinx/util/docutils.py')
-rw-r--r--sphinx/util/docutils.py28
1 files changed, 24 insertions, 4 deletions
diff --git a/sphinx/util/docutils.py b/sphinx/util/docutils.py
index bbf32da1d..b6ddd2dd8 100644
--- a/sphinx/util/docutils.py
+++ b/sphinx/util/docutils.py
@@ -18,8 +18,9 @@ from contextlib import contextmanager
import docutils
from docutils.languages import get_language
-from docutils.utils import Reporter
+from docutils.statemachine import ViewList
from docutils.parsers.rst import directives, roles, convert_directive_function
+from docutils.utils import Reporter
from sphinx.errors import ExtensionError
from sphinx.locale import __
@@ -33,6 +34,7 @@ if False:
from typing import Any, Callable, Iterator, List, Tuple # NOQA
from docutils import nodes # NOQA
from sphinx.environment import BuildEnvironment # NOQA
+ from sphinx.io import SphinxFileInput # NOQA
__version_info__ = tuple(LooseVersion(docutils.__version__).version)
@@ -167,16 +169,34 @@ class WarningStream(object):
class LoggingReporter(Reporter):
+ @classmethod
+ def from_reporter(cls, reporter):
+ # type: (Reporter) -> LoggingReporter
+ """Create an instance of LoggingReporter from other reporter object."""
+ return cls(reporter.source, reporter.report_level, reporter.halt_level,
+ reporter.debug_flag, reporter.error_handler)
+
def __init__(self, source, report_level, halt_level,
debug=False, error_handler='backslashreplace'):
# type: (unicode, int, int, bool, unicode) -> None
stream = WarningStream()
Reporter.__init__(self, source, report_level, halt_level,
stream, debug, error_handler=error_handler)
+ self.source_and_line = None # type: SphinxFileInput
+
+ def set_source(self, source):
+ # type: (SphinxFileInput) -> None
+ self.source_and_line = source
+
+ def system_message(self, *args, **kwargs):
+ # type: (Any, Any) -> Any
+ if kwargs.get('line') and isinstance(self.source_and_line, ViewList):
+ # replace source parameter if source is set
+ source, lineno = self.source_and_line.info(kwargs.get('line'))
+ kwargs['source'] = source
+ kwargs['line'] = lineno
- def set_conditions(self, category, report_level, halt_level, debug=False):
- # type: (unicode, int, int, bool) -> None
- Reporter.set_conditions(self, category, report_level, halt_level, debug=debug)
+ return Reporter.system_message(self, *args, **kwargs)
def is_html5_writer_available():