Mercurial > hg
comparison 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 |
comparison
equal
deleted
inserted
replaced
11428:8b452fe4bf50 | 11493:cc4e2a7ca23f |
---|---|
34 | 34 |
35 - inline literals (no other inline markup is not recognized) | 35 - inline literals (no other inline markup is not recognized) |
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. |
43 | 49 |
44 Returns a list of dictionaries representing the blocks. Each block | 50 Returns a list of dictionaries representing the blocks. Each block |
249 del block['lines'][1] | 255 del block['lines'][1] |
250 return blocks | 256 return 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 |
272 def addmargins(blocks): | 279 def addmargins(blocks): |
273 """Adds empty blocks for vertical spacing. | 280 """Adds empty blocks for vertical spacing. |