diff mercurial/minirst.py @ 11493:cc4e2a7ca23f

Merge with stable
author Martin Geisler <mg@aragost.com>
date Fri, 02 Jul 2010 11:30:57 +0200
parents 521c8e0c93bf
children 75f044d4dbf5
line wrap: on
line diff
--- a/mercurial/minirst.py	Mon Jun 21 17:02:48 2010 -0300
+++ b/mercurial/minirst.py	Fri Jul 02 11:30:57 2010 +0200
@@ -36,7 +36,13 @@
 """
 
 import re, sys
-import util
+import util, encoding
+
+def replace(text, substs):
+    utext = text.decode(encoding.encoding)
+    for f, t in substs:
+        utext = utext.replace(f, t)
+    return utext.encode(encoding.encoding)
 
 def findblocks(text):
     """Find continuous blocks of lines in text.
@@ -251,21 +257,22 @@
 
 
 def inlineliterals(blocks):
+    substs = [('``', '"')]
     for b in blocks:
         if b['type'] in ('paragraph', 'section'):
-            b['lines'] = [l.replace('``', '"') for l in b['lines']]
+            b['lines'] = [replace(l, substs) for l in b['lines']]
     return blocks
 
 
 def hgrole(blocks):
+    substs = [(':hg:`', '"hg '), ('`', '"')]
     for b in blocks:
         if b['type'] in ('paragraph', 'section'):
             # Turn :hg:`command` into "hg command". This also works
             # when there is a line break in the command and relies on
             # the fact that we have no stray back-quotes in the input
             # (run the blocks through inlineliterals first).
-            b['lines'] = [l.replace(':hg:`', '"hg ').replace('`', '"')
-                          for l in b['lines']]
+            b['lines'] = [replace(l, substs) for l in b['lines']]
     return blocks