comparison mercurial/minirst.py @ 15122:efa213b14ec0

minirst: remove some whitespace
author Matt Mackall <mpm@selenic.com>
date Sat, 17 Sep 2011 13:37:50 -0500
parents 0ad0ebe67815
children 9b41ccb2043e
comparison
equal deleted inserted replaced
15121:0ad0ebe67815 15122:efa213b14ec0
20 20
21 import re 21 import re
22 import util, encoding 22 import util, encoding
23 from i18n import _ 23 from i18n import _
24 24
25
26 def replace(text, substs): 25 def replace(text, substs):
27 for f, t in substs: 26 for f, t in substs:
28 text = text.replace(f, t) 27 text = text.replace(f, t)
29 return text 28 return text
30 29
41 lines = b.splitlines() 40 lines = b.splitlines()
42 indent = min((len(l) - len(l.lstrip())) for l in lines) 41 indent = min((len(l) - len(l.lstrip())) for l in lines)
43 lines = [l[indent:] for l in lines] 42 lines = [l[indent:] for l in lines]
44 blocks.append(dict(indent=indent, lines=lines)) 43 blocks.append(dict(indent=indent, lines=lines))
45 return blocks 44 return blocks
46
47 45
48 def findliteralblocks(blocks): 46 def findliteralblocks(blocks):
49 """Finds literal blocks and adds a 'type' field to the blocks. 47 """Finds literal blocks and adds a 'type' field to the blocks.
50 48
51 Literal blocks are given the type 'literal', all other blocks are 49 Literal blocks are given the type 'literal', all other blocks are
143 blocks[i:i + 1] = items 141 blocks[i:i + 1] = items
144 break 142 break
145 i += 1 143 i += 1
146 return blocks 144 return blocks
147 145
148
149 _fieldwidth = 12 146 _fieldwidth = 12
150 147
151 def updatefieldlists(blocks): 148 def updatefieldlists(blocks):
152 """Find key and maximum key width for field lists.""" 149 """Find key and maximum key width for field lists."""
153 i = 0 150 i = 0
169 for block in blocks[i:j]: 166 for block in blocks[i:j]:
170 block['keywidth'] = keywidth 167 block['keywidth'] = keywidth
171 i = j + 1 168 i = j + 1
172 169
173 return blocks 170 return blocks
174
175 171
176 def updateoptionlists(blocks): 172 def updateoptionlists(blocks):
177 i = 0 173 i = 0
178 while i < len(blocks): 174 while i < len(blocks):
179 if blocks[i]['type'] != 'option': 175 if blocks[i]['type'] != 'option':
244 else: 240 else:
245 blocks[j]['indent'] -= adjustment 241 blocks[j]['indent'] -= adjustment
246 j += 1 242 j += 1
247 i += 1 243 i += 1
248 return blocks, pruned 244 return blocks, pruned
249
250 245
251 _sectionre = re.compile(r"""^([-=`:.'"~^_*+#])\1+$""") 246 _sectionre = re.compile(r"""^([-=`:.'"~^_*+#])\1+$""")
252 247
253 def findtables(blocks): 248 def findtables(blocks):
254 '''Find simple tables 249 '''Find simple tables
310 block['underline'] = block['lines'][1][0] 305 block['underline'] = block['lines'][1][0]
311 block['type'] = 'section' 306 block['type'] = 'section'
312 del block['lines'][1] 307 del block['lines'][1]
313 return blocks 308 return blocks
314 309
315
316 def inlineliterals(blocks): 310 def inlineliterals(blocks):
317 substs = [('``', '"')] 311 substs = [('``', '"')]
318 for b in blocks: 312 for b in blocks:
319 if b['type'] in ('paragraph', 'section'): 313 if b['type'] in ('paragraph', 'section'):
320 b['lines'] = [replace(l, substs) for l in b['lines']] 314 b['lines'] = [replace(l, substs) for l in b['lines']]
321 return blocks 315 return blocks
322
323 316
324 def hgrole(blocks): 317 def hgrole(blocks):
325 substs = [(':hg:`', '"hg '), ('`', '"')] 318 substs = [(':hg:`', '"hg '), ('`', '"')]
326 for b in blocks: 319 for b in blocks:
327 if b['type'] in ('paragraph', 'section'): 320 if b['type'] in ('paragraph', 'section'):
329 # when there is a line break in the command and relies on 322 # when there is a line break in the command and relies on
330 # the fact that we have no stray back-quotes in the input 323 # the fact that we have no stray back-quotes in the input
331 # (run the blocks through inlineliterals first). 324 # (run the blocks through inlineliterals first).
332 b['lines'] = [replace(l, substs) for l in b['lines']] 325 b['lines'] = [replace(l, substs) for l in b['lines']]
333 return blocks 326 return blocks
334
335 327
336 def addmargins(blocks): 328 def addmargins(blocks):
337 """Adds empty blocks for vertical spacing. 329 """Adds empty blocks for vertical spacing.
338 330
339 This groups bullets, options, and definitions together with no vertical 331 This groups bullets, options, and definitions together with no vertical