From a2d7f8cfd7bca75ec19b471929b8e2306a5aa6d8 Mon Sep 17 00:00:00 2001 From: milde Date: Wed, 8 Feb 2012 19:46:11 +0000 Subject: [PATCH] Use `field_marker` pattern to look for start of a directive option block (fixes [ 3484857 ]). git-svn-id: https://docutils.svn.sourceforge.net/svnroot/docutils/trunk/docutils@7348 929543f6-e4f2-0310-98a6-ba3bd3dd1d04 --- HISTORY.txt | 2 + docutils/parsers/rst/states.py | 4 +- .../test_rst/test_directives/test_admonitions.py | 29 ++++++++++++ .../test_rst/test_directives/test_images.py | 54 +++++++++++++--------- 4 files changed, 65 insertions(+), 24 deletions(-) diff --git a/HISTORY.txt b/HISTORY.txt index cff215732..1efdfa513 100644 --- a/HISTORY.txt +++ b/HISTORY.txt @@ -56,6 +56,8 @@ Changes Since 0.8.1 - Fix [ 3402314 ] allow non-ASCII whitespace, punctuation characters and "international" quotes around inline markup. + - Use `field_marker` pattern to look for start of a + directive option block (fixes [ 3484857 ]). * docutils/parsers/rst/tableparser.py diff --git a/docutils/parsers/rst/states.py b/docutils/parsers/rst/states.py index d208b2041..ff91b0362 100644 --- a/docutils/parsers/rst/states.py +++ b/docutils/parsers/rst/states.py @@ -2142,8 +2142,8 @@ class Body(RSTState): def parse_directive_options(self, option_presets, option_spec, arg_block): options = option_presets.copy() - for i in range(len(arg_block)): - if arg_block[i][:1] == ':': + for i, line in enumerate(arg_block): + if re.match(Body.patterns['field_marker'], line): opt_block = arg_block[i:] arg_block = arg_block[:i] break diff --git a/test/test_parsers/test_rst/test_directives/test_admonitions.py b/test/test_parsers/test_rst/test_directives/test_admonitions.py index c4a01800d..09d16d1c9 100755 --- a/test/test_parsers/test_rst/test_directives/test_admonitions.py +++ b/test/test_parsers/test_rst/test_directives/test_admonitions.py @@ -111,6 +111,35 @@ totest['admonitions'] = [ No blank lines in-between. """], ["""\ +.. note:: Content before options + is possible too. + :class: mynote + +.. note:: :strong:`a role is not an option`. + :name: role not option + +.. note:: a role is + :strong:`not an option`, even if its starts a line. +""", +"""\ + + + + Content before options + is possible too. + + + + a role is not an option + . + + + a role is + + not an option + , even if its starts a line. +"""], +["""\ .. note:: """, """\ diff --git a/test/test_parsers/test_rst/test_directives/test_images.py b/test/test_parsers/test_rst/test_directives/test_images.py index 0fb21a0bf..67d898eb4 100755 --- a/test/test_parsers/test_rst/test_directives/test_images.py +++ b/test/test_parsers/test_rst/test_directives/test_images.py @@ -85,6 +85,8 @@ totest['images'] = [ :width: 200 :scale: 50 """], +# If there are multiple lines in the link block, they are stripped of +# leading and trailing whitespace and joined together: ["""\ .. image:: a/very/long/path/to/ picture.png @@ -96,6 +98,34 @@ totest['images'] = [ """], +# The following two misspellings were detected in Docutils <= 0.8 +# (the option block was started by any line starting with a colon +# which led to problems with named roles in other directives): +["""\ +.. image:: picture.png + :scale 50 +""", +"""\ + + +"""], +["""\ +.. image:: picture.png + :: 50 +""", +"""\ + + +"""], +# a missing leading colon went undetected also in Docutils <= 0.8: +["""\ +.. image:: picture.png + scale: 50 +""", +"""\ + + +"""], ["""\ .. image:: picture.png :width: 200px @@ -175,6 +205,7 @@ totest['images'] = [ """ % DocutilsTestSupport.exception_data(int, None)[1][0]], ["""\ .. image:: picture.png + :height: 100 :scale 50 """, """\ @@ -185,32 +216,11 @@ totest['images'] = [ invalid option block. .. image:: picture.png + :height: 100 :scale 50 """], ["""\ .. image:: picture.png - scale: 50 -""", -"""\ - - -"""], -["""\ -.. image:: picture.png - :: 50 -""", -"""\ - - - - Error in "image" directive: - invalid option block. - - .. image:: picture.png - :: 50 -"""], -["""\ -.. image:: picture.png :sale: 50 """, """\ -- 2.11.4.GIT