From a0e1abe2066ece9ade05938258bc4aafce78ac20 Mon Sep 17 00:00:00 2001 From: milde Date: Fri, 6 Jan 2012 12:08:43 +0000 Subject: [PATCH] Store source and line in the "raw" node generated by raw-derived roles. This is already done for nodes generated by raw directives and required for error reporting by writers. git-svn-id: http://svn.code.sf.net/p/docutils/code/trunk/docutils@7308 929543f6-e4f2-0310-98a6-ba3bd3dd1d04 --- docutils/parsers/rst/directives/parts.py | 5 ++--- docutils/parsers/rst/roles.py | 2 ++ docutils/parsers/rst/states.py | 6 +++--- docutils/utils/__init__.py | 2 +- 4 files changed, 8 insertions(+), 7 deletions(-) diff --git a/docutils/parsers/rst/directives/parts.py b/docutils/parsers/rst/directives/parts.py index 55a4dd5ed..2eb1efddd 100644 --- a/docutils/parsers/rst/directives/parts.py +++ b/docutils/parsers/rst/directives/parts.py @@ -64,9 +64,8 @@ class Contents(Directive): topic = nodes.topic(classes=['contents']) topic['classes'] += self.options.get('class', []) # the latex2e writer needs source and line for a warning: - src, srcline = self.state_machine.get_source_and_line() - topic.source = src - topic.line = srcline - 1 + topic.source, topic.line = self.state_machine.get_source_and_line() + topic.line -= 1 if 'local' in self.options: topic['classes'].append('local') if title: diff --git a/docutils/parsers/rst/roles.py b/docutils/parsers/rst/roles.py index 9b510fd30..a90080109 100644 --- a/docutils/parsers/rst/roles.py +++ b/docutils/parsers/rst/roles.py @@ -309,6 +309,8 @@ def raw_role(role, rawtext, text, lineno, inliner, options={}, content=[]): return [prb], [msg] set_classes(options) node = nodes.raw(rawtext, utils.unescape(text, 1), **options) + node.source, node.line = inliner.reporter.get_source_and_line() + node.line -= 1 return [node], [] raw_role.options = {'format': directives.unchanged} diff --git a/docutils/parsers/rst/states.py b/docutils/parsers/rst/states.py index f671ad1d6..0c1bdbbe7 100644 --- a/docutils/parsers/rst/states.py +++ b/docutils/parsers/rst/states.py @@ -227,9 +227,9 @@ class RSTState(StateWS): self.document = memo.document self.parent = self.state_machine.node # enable the reporter to determine source and source-line - if not hasattr(self.reporter, 'locator'): - self.reporter.locator = self.state_machine.get_source_and_line - # print "adding locator to reporter", self.state_machine.input_offset + if not hasattr(self.reporter, 'get_source_and_line'): + self.reporter.get_source_and_line = self.state_machine.get_source_and_line + # print "adding get_source_and_line to reporter", self.state_machine.input_offset def goto_line(self, abs_line_offset): diff --git a/docutils/utils/__init__.py b/docutils/utils/__init__.py index ed3abfd21..c0113e30d 100644 --- a/docutils/utils/__init__.py +++ b/docutils/utils/__init__.py @@ -169,7 +169,7 @@ class Reporter: # assert source is not None, "node has line- but no source-argument" if not 'source' in attributes: # 'line' is absolute line number try: # look up (source, line-in-source) - source, line = self.locator(attributes.get('line')) + source, line = self.get_source_and_line(attributes.get('line')) # print "locator lookup", kwargs.get('line'), "->", source, line except AttributeError: source, line = None, None -- 2.11.4.GIT