aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMartin Vilcans <martin@librador.com>2011-11-22 20:28:08 +0100
committerMartin Vilcans <martin@librador.com>2011-11-22 20:30:53 +0100
commit179bd424ee8b5a01584cd4cd7d76df8ba8a1f3d4 (patch)
tree751074aba0c6be2854cdf35af38fe389a6ed99ad
parentbce1a38322327256ad2b718269d43371236d0bb7 (diff)
downloadscreenplain-179bd424ee8b5a01584cd4cd7d76df8ba8a1f3d4.tar.gz
Fix incorrectly parsing when mixing italic and bold. Thx, Stu!
-rw-r--r--screenplain/richstring.py5
-rw-r--r--tests/richstring_test.py28
2 files changed, 29 insertions, 4 deletions
diff --git a/screenplain/richstring.py b/screenplain/richstring.py
index ee8332a..9aaa163 100644
--- a/screenplain/richstring.py
+++ b/screenplain/richstring.py
@@ -107,9 +107,8 @@ class Italic(Style):
parse_re = re.compile(
r'\*' # one star
- r'(?=\S)' # must not be followed by space
- r'(.+)' # inside text
- r'(?<=\S)\*' # finishing with one star
+ r'([^\s].*?)' # anything but a space, then text
+ r'\*' # finishing with one star
r'(?!\*)' # must not be followed by star
)
diff --git a/tests/richstring_test.py b/tests/richstring_test.py
index c79981d..2804ec2 100644
--- a/tests/richstring_test.py
+++ b/tests/richstring_test.py
@@ -126,7 +126,6 @@ class ParseEmphasisTests(unittest2.TestCase):
(bold + italic)('really strong')
)
- @unittest2.expectedFailure
def test_additional_star(self):
self.assertEquals(
parse_emphasis('*foo* bar* baz'),
@@ -152,3 +151,30 @@ class ParseEmphasisTests(unittest2.TestCase):
parse_emphasis('_*he_llo*'),
(italic + underline)('he') + italic('llo')
)
+
+ def test_complicated(self):
+ # As reported by Stu
+ self.assertEquals(
+ parse_emphasis('You can _underline_ words, make them **bold** or *italic* or even ***bold italic.***'),
+ (plain('You can ') + underline('underline') +
+ plain(' words, make them ') + bold('bold') + plain(' or ') +
+ italic('italic') + plain(' or even ') + (bold + italic)('bold italic.'))
+ )
+
+ def test_simplified_complicated(self):
+ self.assertEquals(
+ parse_emphasis('*italic* or even ***bold italic.***'),
+ italic('italic') + plain(' or even ') + (bold + italic)('bold italic.')
+ )
+
+ def test_two_italic_should_not_create_one_long_italic_string(self):
+ self.assertEquals(
+ parse_emphasis('*first* *second*'),
+ italic('first') + plain(' ') + italic('second')
+ )
+
+ def test_two_bold_should_not_create_one_long_bold_string(self):
+ self.assertEquals(
+ parse_emphasis('**first** **second**'),
+ bold('first') + plain(' ') + bold('second')
+ )