diff options
| author | grubert <grubert@929543f6-e4f2-0310-98a6-ba3bd3dd1d04> | 2011-04-29 23:20:54 +0000 |
|---|---|---|
| committer | grubert <grubert@929543f6-e4f2-0310-98a6-ba3bd3dd1d04> | 2011-04-29 23:20:54 +0000 |
| commit | 36a070a390e613ac0e3eb6c115f3d91de5397eed (patch) | |
| tree | e7dd136e3421899b8d73c8103ebd45408f863cbc | |
| parent | 996407ca15e037f6b563f602f030d4c238ef8b4f (diff) | |
| download | docutils-36a070a390e613ac0e3eb6c115f3d91de5397eed.tar.gz | |
* docutils/parsers/rst/directives/misc.py:
- Fix [ 1830389 ] Replace not breaking on getting system_messages from
nested_parse
git-svn-id: http://svn.code.sf.net/p/docutils/code/trunk@7021 929543f6-e4f2-0310-98a6-ba3bd3dd1d04
| -rw-r--r-- | docutils/HISTORY.txt | 4 | ||||
| -rw-r--r-- | docutils/docutils/parsers/rst/directives/misc.py | 34 | ||||
| -rw-r--r-- | docutils/docutils/parsers/rst/states.py | 5 | ||||
| -rwxr-xr-x | docutils/test/test_parsers/test_rst/test_directives/test_replace.py | 11 | ||||
| -rw-r--r-- | docutils/test/test_parsers/test_rst/test_directives/test_replace_fr.py | 19 |
5 files changed, 32 insertions, 41 deletions
diff --git a/docutils/HISTORY.txt b/docutils/HISTORY.txt index 39909cd69..8cbf970ae 100644 --- a/docutils/HISTORY.txt +++ b/docutils/HISTORY.txt @@ -80,6 +80,10 @@ Changes Since 0.7 - exclude combining chars from column_width (partial fix for [ 2926161 ]) +* docutils/parsers/rst/directives/misc.py: + + - Fix [ 1830389 ] Replace not breaking on getting system_messages from + nested_parse Release 0.7 (2010-07-07) ======================== diff --git a/docutils/docutils/parsers/rst/directives/misc.py b/docutils/docutils/parsers/rst/directives/misc.py index b94d6a73e..12b62b2f9 100644 --- a/docutils/docutils/parsers/rst/directives/misc.py +++ b/docutils/docutils/parsers/rst/directives/misc.py @@ -225,23 +225,23 @@ class Replace(Directive): element = nodes.Element(text) self.state.nested_parse(self.content, self.content_offset, element) - # BUG 1830380 : element might contain [paragraph] + system_message(s) - # BUG 1830380 : could skip embedded messages, but then we loose them - if ( len(element) != 1 - or not isinstance(element[0], nodes.paragraph)): - messages = [] - for node in element: - if isinstance(node, nodes.system_message): - node['backrefs'] = [] - messages.append(node) - error = self.state_machine.reporter.error( - 'Error in "%s" directive: may contain a single paragraph ' - 'only.' % (self.name), line=self.lineno) - messages.append(error) - return messages - else: - return element[0].children - + # element might contain [paragraph] + system_message(s) + node = None + messages = [] + for elem in element: + if not node and isinstance(elem, nodes.paragraph): + node = elem + elif isinstance(elem, nodes.system_message): + elem['backrefs'] = [] + messages.append(elem) + else: + return [ + self.state_machine.reporter.error( + 'Error in "%s" directive: may contain a single paragraph ' + 'only.' % (self.name), line=self.lineno) ] + if node: + return messages + node.children + return messages class Unicode(Directive): diff --git a/docutils/docutils/parsers/rst/states.py b/docutils/docutils/parsers/rst/states.py index bf2f2b14d..ef9b9a0a4 100644 --- a/docutils/docutils/parsers/rst/states.py +++ b/docutils/docutils/parsers/rst/states.py @@ -421,7 +421,6 @@ class RSTState(StateWS): textnodes, messages = self.inline_text(text, lineno) p = nodes.paragraph(data, '', *textnodes) p.source, p.line = self.state_machine.get_source_and_line(lineno) - # BUG 1830380: nodes and system_messages concattenated ? return [p] + messages, literalnext def inline_text(self, text, lineno): @@ -2091,7 +2090,6 @@ class Body(RSTState): source=src, line=srcline) msg_node += nodes.literal_block(block_text, block_text) result = [msg_node] - # BUG 1830380: returns a list of system_messages, not nodes assert isinstance(result, list), \ 'Directive "%s" must return a list of nodes.' % type_name for i in range(len(result)): @@ -2642,13 +2640,12 @@ class Text(RSTState): def blank(self, match, context, next_state): """End of paragraph.""" - # BUG 1830380: self.paragraph returns [ node, system_message(s) ], literalnext + # NOTE: self.paragraph returns [ node, system_message(s) ], literalnext paragraph, literalnext = self.paragraph( context, self.state_machine.abs_line_number() - 1) self.parent += paragraph if literalnext: self.parent += self.literal_block() - # BUG 1830380: parent might contain now: [ node-paragraph, system_messages(s), literal_block ] return [], 'Body', [] def eof(self, context): diff --git a/docutils/test/test_parsers/test_rst/test_directives/test_replace.py b/docutils/test/test_parsers/test_rst/test_directives/test_replace.py index 4738fd029..227bb2d7c 100755 --- a/docutils/test/test_parsers/test_rst/test_directives/test_replace.py +++ b/docutils/test/test_parsers/test_rst/test_directives/test_replace.py @@ -96,9 +96,6 @@ I recommend you try |Python|_. ["""\ .. |name| replace:: *error in **inline ``markup """, -# BUG the "Error in "replace" directive: may contain a single paragraph only." -# results from Replace.run gets [paragraph, system_massage(s)] from nestet_parse -# but does not expect. """\ <document source="test data"> <system_message ids="id1" level="2" line="1" source="test data" type="WARNING"> @@ -112,10 +109,10 @@ I recommend you try |Python|_. Inline literal start-string without end-string. <system_message level="3" line="1" source="test data" type="ERROR"> <paragraph> - Error in "replace" directive: may contain a single paragraph only. - <system_message level="2" line="1" source="test data" type="WARNING"> - <paragraph> - Substitution definition "name" empty or invalid. + Substitution definition contains illegal element: + <literal_block xml:space="preserve"> + <problematic ids="id2" refid="id1"> + * <literal_block xml:space="preserve"> .. |name| replace:: *error in **inline ``markup """], diff --git a/docutils/test/test_parsers/test_rst/test_directives/test_replace_fr.py b/docutils/test/test_parsers/test_rst/test_directives/test_replace_fr.py index 68c00fe0b..6847c1c06 100644 --- a/docutils/test/test_parsers/test_rst/test_directives/test_replace_fr.py +++ b/docutils/test/test_parsers/test_rst/test_directives/test_replace_fr.py @@ -43,7 +43,6 @@ Le |Na+| est l'ion sodium. """], ["""\ Test directive containing english role superscript. -BUG 1830380: the ERROR is an ERROR and the WARNING a followup to the ERROR .. |Na+| remplace:: Na\ :sup:`+` @@ -53,25 +52,19 @@ Le |Na+| est l'ion sodium. <document source="test data"> <paragraph> Test directive containing english role superscript. - BUG 1830380: the ERROR is an ERROR and the WARNING a followup to the ERROR - <system_message level="1" line="4" source="test data" type="INFO"> + <system_message level="1" line="3" source="test data" type="INFO"> <paragraph> No role entry for "sup" in module "docutils.parsers.rst.languages.fr". Using English fallback for role "sup". - <system_message level="3" line="4" source="test data" type="ERROR"> - <paragraph> - Error in "remplace" directive: may contain a single paragraph only. - <system_message level="2" line="4" source="test data" type="WARNING"> - <paragraph> - Substitution definition "Na+" empty or invalid. - <literal_block xml:space="preserve"> - .. |Na+| remplace:: Na\\ :sup:`+` + <substitution_definition names="Na+"> + Na + <superscript> + + <paragraph> Le \n\ <substitution_reference refname="Na+"> Na+ - est l\'ion sodium. -"""], + est l\'ion sodium."""], ] |
