##// 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 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 47 def findblocks(text):
42 48 """Find continuous blocks of lines in text.
@@ -251,21 +257,22 b' def findsections(blocks):'
251 257
252 258
253 259 def inlineliterals(blocks):
260 substs = [('``', '"')]
254 261 for b in blocks:
255 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 264 return blocks
258 265
259 266
260 267 def hgrole(blocks):
268 substs = [(':hg:`', '"hg '), ('`', '"')]
261 269 for b in blocks:
262 270 if b['type'] in ('paragraph', 'section'):
263 271 # Turn :hg:`command` into "hg command". This also works
264 272 # when there is a line break in the command and relies on
265 273 # the fact that we have no stray back-quotes in the input
266 274 # (run the blocks through inlineliterals first).
267 b['lines'] = [l.replace(':hg:`', '"hg ').replace('`', '"')
268 for l in b['lines']]
275 b['lines'] = [replace(l, substs) for l in b['lines']]
269 276 return blocks
270 277
271 278
General Comments 0
You need to be logged in to leave comments. Login now