Mercurial > hg
comparison mercurial/minirst.py @ 12652:3c31c0e42b11
minirst: pull admonition titles out formatblock function
author | Martin Geisler <mg@lazybytes.net> |
---|---|
date | Fri, 08 Oct 2010 23:23:49 +0200 |
parents | 17f28de168a4 |
children | 5082e2f3f8e0 |
comparison
equal
deleted
inserted
replaced
12651:17f28de168a4 | 12652:3c31c0e42b11 |
---|---|
315 blocks[i]['admonitiontitle'] = admonitiontitle | 315 blocks[i]['admonitiontitle'] = admonitiontitle |
316 del blocks[i]['lines'][0] | 316 del blocks[i]['lines'][0] |
317 i = i + 1 | 317 i = i + 1 |
318 return blocks | 318 return blocks |
319 | 319 |
320 _admonitiontitles = {'attention': _('Attention:'), | |
321 'caution': _('Caution:'), | |
322 'danger': _('!Danger!') , | |
323 'error': _('Error:'), | |
324 'hint': _('Hint:'), | |
325 'important': _('Important:'), | |
326 'note': _('Note:'), | |
327 'tip': _('Tip:'), | |
328 'warning': _('Warning!')} | |
329 | |
320 def formatblock(block, width): | 330 def formatblock(block, width): |
321 """Format a block according to width.""" | 331 """Format a block according to width.""" |
322 if width <= 0: | 332 if width <= 0: |
323 width = 78 | 333 width = 78 |
324 indent = ' ' * block['indent'] | 334 indent = ' ' * block['indent'] |
325 if block['type'] == 'admonition': | 335 if block['type'] == 'admonition': |
326 titles = {'attention': _('Attention:'), | 336 admonition = _admonitiontitles[block['admonitiontitle']] |
327 'caution': _('Caution:'), | |
328 'danger': _('!Danger!') , | |
329 'error': _('Error:'), | |
330 'hint': _('Hint:'), | |
331 'important': _('Important:'), | |
332 'note': _('Note:'), | |
333 'tip': _('Tip:'), | |
334 'warning': _('Warning!')} | |
335 | |
336 admonition = titles[block['admonitiontitle']] | |
337 hang = len(block['lines'][-1]) - len(block['lines'][-1].lstrip()) | 337 hang = len(block['lines'][-1]) - len(block['lines'][-1].lstrip()) |
338 | 338 |
339 defindent = indent + hang * ' ' | 339 defindent = indent + hang * ' ' |
340 text = ' '.join(map(str.strip, block['lines'])) | 340 text = ' '.join(map(str.strip, block['lines'])) |
341 return '%s\n%s' % (indent + admonition, util.wrap(text, width=width, | 341 return '%s\n%s' % (indent + admonition, util.wrap(text, width=width, |