[py-svn] r33716 - in py/dist/py/rst: . testing

guido at codespeak.net guido at codespeak.net
Wed Oct 25 14:02:20 CEST 2006


Author: guido
Date: Wed Oct 25 14:02:17 2006
New Revision: 33716

Modified:
   py/dist/py/rst/rst.py
   py/dist/py/rst/testing/test_rst.py
Log:
Fixed escaping of the markup characters themselves (and only them) in the 
markup nodes.


Modified: py/dist/py/rst/rst.py
==============================================================================
--- py/dist/py/rst/rst.py	(original)
+++ py/dist/py/rst/rst.py	Wed Oct 25 14:02:17 2006
@@ -218,8 +218,15 @@
         self._text = _text
     
     def text(self):
-        text = self._text
+        text = self.escape(self._text)
         return self.start + text + self.end
+
+    def escape(self, text):
+        if self.start:
+            text = text.replace(self.start, '\\%s' % (self.start,))
+        if self.end and self.end != self.start:
+            text = text.replace(self.end, '\\%s' % (self.end,))
+        return text
     
 class Text(AbstractText):
     def wordlist(self):
@@ -238,9 +245,6 @@
     start = '``'
     end = '``'
 
-    def text(self):
-        return super(Quote, self).text()
-
 class Anchor(AbstractText):
     start = '_`'
     end = '`'

Modified: py/dist/py/rst/testing/test_rst.py
==============================================================================
--- py/dist/py/rst/testing/test_rst.py	(original)
+++ py/dist/py/rst/testing/test_rst.py	Wed Oct 25 14:02:17 2006
@@ -26,13 +26,16 @@
     txt = Paragraph('*escape* ``test``').text()
     assert txt == '\\*escape\\* \\`\\`test\\`\\`'
     checkrest(txt)
-    txt = Paragraph(Strong('*strong*')).text()
+    txt = Paragraph(Em('*strong*')).text()
     # docutils doesn't require escaping here (it's greedy)
-    assert txt == '***strong***'
+    assert txt == '*\\*strong\\**'
     checkrest(txt)
     txt = Rest(Paragraph('foo [1]_')).text()
     assert txt == "foo [1]\\_\n"
     checkrest(txt)
+    # hmmm...
+    txt = Rest(Paragraph(Em('foo *bar* baz'))).text()
+    assert txt == '*foo \\*bar\\* baz*\n'
 
 def test_escape_literal():
     txt = LiteralBlock('*escape* ``test``').text()
@@ -41,8 +44,7 @@
 
 def test_escape_markup():
     txt = Em('foo*bar').text()
-    # no escaping required here... (greedy behaviour)
-    assert txt == '*foo*bar*'
+    assert txt == '*foo\\*bar*'
     checkrest(txt)
     txt = Paragraph(Em('foo'), "*bar").text()
     assert txt == '*foo* \\*bar'



More information about the pytest-commit mailing list