##// END OF EJS Templates
minirst: use unicode string as intermediate form for replacement...
FUJIWARA Katsunori -
r11464:521c8e0c stable
parent child Browse files
Show More
@@ -36,7 +36,13 b' It only supports a small subset of reStr'
36 """
36 """
37
37
38 import re, sys
38 import re, sys
39 import util
39 import util, encoding
40
41 def replace(text, substs):
42 utext = text.decode(encoding.encoding)
43 for f, t in substs:
44 utext = utext.replace(f, t)
45 return utext.encode(encoding.encoding)
40
46
41 def findblocks(text):
47 def findblocks(text):
42 """Find continuous blocks of lines in text.
48 """Find continuous blocks of lines in text.
@@ -251,21 +257,22 b' def findsections(blocks):'
251
257
252
258
253 def inlineliterals(blocks):
259 def inlineliterals(blocks):
260 substs = [('``', '"')]
254 for b in blocks:
261 for b in blocks:
255 if b['type'] in ('paragraph', 'section'):
262 if b['type'] in ('paragraph', 'section'):
256 b['lines'] = [l.replace('``', '"') for l in b['lines']]
263 b['lines'] = [replace(l, substs) for l in b['lines']]
257 return blocks
264 return blocks
258
265
259
266
260 def hgrole(blocks):
267 def hgrole(blocks):
268 substs = [(':hg:`', '"hg '), ('`', '"')]
261 for b in blocks:
269 for b in blocks:
262 if b['type'] in ('paragraph', 'section'):
270 if b['type'] in ('paragraph', 'section'):
263 # Turn :hg:`command` into "hg command". This also works
271 # Turn :hg:`command` into "hg command". This also works
264 # when there is a line break in the command and relies on
272 # when there is a line break in the command and relies on
265 # the fact that we have no stray back-quotes in the input
273 # the fact that we have no stray back-quotes in the input
266 # (run the blocks through inlineliterals first).
274 # (run the blocks through inlineliterals first).
267 b['lines'] = [l.replace(':hg:`', '"hg ').replace('`', '"')
275 b['lines'] = [replace(l, substs) for l in b['lines']]
268 for l in b['lines']]
269 return blocks
276 return blocks
270
277
271
278
General Comments 0
You need to be logged in to leave comments. Login now